custom/plugins/GbmedShoppingList/src/Subscriber/Product.php line 56

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * gb media
  4.  * All Rights Reserved.
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited.
  7.  * The content of this file is proprietary and confidential.
  8.  *
  9.  * @category       Shopware
  10.  * @package        Shopware_Plugins
  11.  * @subpackage     GbmedShoppingList
  12.  * @copyright      Copyright (c) 2020, gb media
  13.  * @license        proprietary
  14.  * @author         Giuseppe Bottino
  15.  * @link           http://www.gb-media.biz
  16.  */
  17. namespace Gbmed\ShoppingList\Subscriber;
  18. use Gbmed\ShoppingList\Service\ShoppingList;
  19. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. class Product implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var ShoppingList
  25.      */
  26.     private $shoppingListService;
  27.     /**
  28.      * Subscriber constructor.
  29.      * @param ShoppingList $shoppingListService
  30.      */
  31.     public function __construct(ShoppingList $shoppingListService)
  32.     {
  33.         $this->shoppingListService $shoppingListService;
  34.     }
  35.     /**
  36.      * @return array
  37.      */
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             ProductPageLoadedEvent::class => 'onProductPageLoadedEvent'
  42.         ];
  43.     }
  44.     /**
  45.      * add gbmedShoppingLists extension
  46.      *
  47.      * @param ProductPageLoadedEvent $event
  48.      * @throws \Exception
  49.      */
  50.     public function onProductPageLoadedEvent(ProductPageLoadedEvent $event): void
  51.     {
  52.         if ($event->getSalesChannelContext()->getCustomer() && !$event->getSalesChannelContext()->getCustomer()->getGuest()) {
  53.             $shoppingLists $this->shoppingListService->getCustomerShoppingListsMinimal($event->getSalesChannelContext());
  54.             $event->getPage()->addExtension('gbmedShoppingLists'$shoppingLists->getEntities());
  55.         }
  56.     }
  57. }