custom/plugins/BALThreeDimensionModelView/src/Subscriber/ProductListingSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. namespace BAL\Plugin\ThreeDimensionModelView\Subscriber;
  3. use BAL\Plugin\ThreeDimensionModelView\Entity\Product\ProductExtension;
  4. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  5. use Shopware\Core\Content\Product\ProductEvents;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ProductListingSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents() : array
  11.     {
  12.         return [
  13.             ProductEvents::PRODUCT_LISTING_CRITERIA => 'onProductListingCriteriaEvent',
  14.         ];
  15.     }
  16.     public function onProductListingCriteriaEvent(ProductListingCriteriaEvent $event) : void
  17.     {
  18.         $productModelCriteria $event->getCriteria()->getAssociation(ProductExtension::FIELD_NAME);
  19.         $productModelCriteria->addAssociation('threeDimensionModel');
  20.         $productModelCriteria->addFilter(
  21.             new EqualsFilter('active'true),
  22.             new EqualsFilter('threeDimensionModel.active'true),
  23.         );
  24.     }
  25. }