vendor/shopware/core/Content/ImportExport/Event/Subscriber/ProductCriteriaSubscriber.php line 24

Open in your IDE?
  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\Struct\Config;
  5. use Shopware\Core\Content\Product\ProductDefinition;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ProductCriteriaSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  13.      */
  14.     public static function getSubscribedEvents()
  15.     {
  16.         return [
  17.             EnrichExportCriteriaEvent::class => 'enrich',
  18.         ];
  19.     }
  20.     public function enrich(EnrichExportCriteriaEvent $event): void
  21.     {
  22.         if ($event->getLogEntity()->getProfile()->getSourceEntity() !== ProductDefinition::ENTITY_NAME) {
  23.             return;
  24.         }
  25.         $criteria $event->getCriteria();
  26.         $criteria->resetSorting();
  27.         $criteria->addSorting(new FieldSorting('autoIncrement'));
  28.         $config Config::fromLog($event->getLogEntity());
  29.         if ($config->get('includeVariants') !== true) {
  30.             $criteria->addFilter(new EqualsFilter('parentId'null));
  31.         }
  32.     }
  33. }