custom/plugins/SwagCmsExtensions/src/Core/Content/Product/SalesChannel/Listing/ProductListingCriteriaSubscriber.php line 32

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\CmsExtensions\Core\Content\Product\SalesChannel\Listing;
  8. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  9. use Shopware\Core\Content\Product\ProductEvents;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  11. use Swag\CmsExtensions\Storefront\Controller\QuickviewController;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class ProductListingCriteriaSubscriber implements EventSubscriberInterface
  14. {
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             ProductEvents::PRODUCT_LISTING_CRITERIA => 'filterByParentId',
  19.         ];
  20.     }
  21.     /**
  22.      * filterByParentId adds a filter for the parentId supplied in the request to the
  23.      * product listing criteria object. This is used to determine the original product id
  24.      * shown in the listing (listingProductId) when switching variants via the quickview.
  25.      *
  26.      * @see \Swag\CmsExtensions\Storefront\Pagelet\Quickview\QuickviewVariantPageletLoader::getListingProductId()
  27.      */
  28.     public function filterByParentId(ProductListingCriteriaEvent $event): void
  29.     {
  30.         if ($event->getRequest()->attributes->get('_route') !== QuickviewController::QUICKVIEW_VARIANT_ROUTE) {
  31.             return;
  32.         }
  33.         $event->getCriteria()
  34.             ->addFilter(new EqualsFilter('product.parentId'$event->getRequest()->request->get('parentId')))
  35.             ->setLimit(1);
  36.     }
  37. }