custom/plugins/sw-asus/src/Subscriber/ProductSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace Onedot\Asus\Subscriber;
  3. use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
  4. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ProductSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var CartService
  10.      */
  11.     private $cartService;
  12.    public function __construct(CartService $cartService)
  13.    {
  14.        $this->cartService $cartService;
  15.    }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             ProductPageLoadedEvent::class => 'onProductPageLoaded'
  20.         ];
  21.     }
  22.     public function onProductPageLoaded(ProductPageLoadedEvent $event)
  23.     {
  24.         $saleChannelContext $event->getSalesChannelContext();
  25.         $page $event->getPage();
  26.         $cart $this->cartService->getCart($saleChannelContext->getToken(), $saleChannelContext);
  27.         $page->assign([
  28.             'cart' => $cart,
  29.         ]);
  30.     }
  31. }