custom/plugins/zenitPlatformGravity/src/Subscriber/QuickViewSubscriber.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformGravity\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Shopware\Core\Content\Product\SalesChannel\Detail\AbstractProductDetailRoute;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  8. use Shopware\Storefront\Page\Product\QuickView\MinimalQuickViewPageLoadedEvent;
  9. class QuickViewSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var AbstractProductDetailRoute
  13.      */
  14.     protected $productDetailRoute;
  15.     public function __construct(AbstractProductDetailRoute $productDetailRoute)
  16.     {
  17.         $this->productDetailRoute $productDetailRoute;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             MinimalQuickViewPageLoadedEvent::class => 'onMinimalQuickViewPageLoaded',
  23.         ];
  24.     }
  25.     public function onMinimalQuickViewPageLoaded(MinimalQuickViewPageLoadedEvent $event): void
  26.     {
  27.         $page $event->getPage();
  28.         $product $page->getProduct();
  29.         $productId $product->getId();
  30.         $criteria = (new Criteria())
  31.             ->addAssociation('manufacturer.media')
  32.             ->addAssociation('options.group')
  33.             ->addAssociation('properties.group')
  34.             ->addAssociation('mainCategories.category');
  35.         $criteria
  36.             ->getAssociation('media')
  37.             ->addSorting(new FieldSorting('position'));
  38.         $criteriaResult $this->productDetailRoute->load($productId, new Request$event->getSalesChannelContext(), $criteria);
  39.         $page->configuratorSettings $criteriaResult->getConfigurator();
  40.     }
  41. }