src/Core/Content/ImportExport/Event/Subscriber/ProductCriteriaSubscriber.php line 30

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\ImportExport\Event\Subscriber;
  3. use Shopware\Core\Content\ImportExport\Event\EnrichExportCriteriaEvent;
  4. use Shopware\Core\Content\ImportExport\ImportExportProfileEntity;
  5. use Shopware\Core\Content\ImportExport\Struct\Config;
  6. use Shopware\Core\Content\Product\ProductDefinition;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  9. use Shopware\Core\Framework\Log\Package;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12.  * @internal
  13.  */
  14. #[Package('system-settings')]
  15. class ProductCriteriaSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  19.      */
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             EnrichExportCriteriaEvent::class => 'enrich',
  24.         ];
  25.     }
  26.     public function enrich(EnrichExportCriteriaEvent $event): void
  27.     {
  28.         /** @var ImportExportProfileEntity $profile */
  29.         $profile $event->getLogEntity()->getProfile();
  30.         if ($profile->getSourceEntity() !== ProductDefinition::ENTITY_NAME) {
  31.             return;
  32.         }
  33.         $criteria $event->getCriteria();
  34.         $criteria->resetSorting();
  35.         $criteria->addSorting(new FieldSorting('autoIncrement'));
  36.         $config Config::fromLog($event->getLogEntity());
  37.         if ($config->get('includeVariants') !== true) {
  38.             $criteria->addFilter(new EqualsFilter('parentId'null));
  39.         }
  40.     }
  41. }