vendor/store.shopware.com/viocustomerprice/src/Subscriber/ProductCriteriaEventSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace VioCustomerPrice\Subscriber;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  7. use Shopware\Core\System\SalesChannel\Event\SalesChannelProcessCriteriaEvent;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class ProductCriteriaEventSubscriber implements EventSubscriberInterface
  11. {
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             'sales_channel.product.process.criteria' => 'onProductCriteria'
  16.         ];
  17.     }
  18.     public function onProductCriteria(SalesChannelProcessCriteriaEvent $event): void
  19.     {
  20.         $this->addCustomerPricesAssociation(
  21.             $event->getCriteria(),
  22.             $event->getSalesChannelContext()
  23.         );
  24.     }
  25.     protected function addCustomerPricesAssociation(Criteria $criteriaSalesChannelContext $context): void
  26.     {
  27.         if($context->getCustomer()) {
  28.             $criteria->getAssociation('customerPrices')
  29.                 ->addFilter(new EqualsFilter('customerId'$context->getCustomer()->getId()))
  30.                 ->addSorting(new FieldSorting('quantityStart'));
  31.         }
  32.     }
  33. }