platform/src/Core/Content/ImportExport/Event/Subscriber/ProductCriteriaSubscriber.php line 21

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.     public static function getSubscribedEvents()
  12.     {
  13.         return [
  14.             EnrichExportCriteriaEvent::class => 'enrich',
  15.         ];
  16.     }
  17.     public function enrich(EnrichExportCriteriaEvent $event): void
  18.     {
  19.         if ($event->getLogEntity()->getProfile()->getSourceEntity() !== ProductDefinition::ENTITY_NAME) {
  20.             return;
  21.         }
  22.         $criteria $event->getCriteria();
  23.         $criteria->resetSorting();
  24.         $criteria->addSorting(new FieldSorting('autoIncrement'));
  25.         $config Config::fromLog($event->getLogEntity());
  26.         if ($config->get('includeVariants') !== true) {
  27.             $criteria->addFilter(new EqualsFilter('parentId'null));
  28.         }
  29.     }
  30. }