custom/plugins/GbmedShoppingList/src/Subscriber/Checkout.php line 57

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\Checkout\Cart\CheckoutCartPageLoadedEvent;
  20. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. class Checkout implements EventSubscriberInterface
  23. {
  24.     /**
  25.      * @var ShoppingList
  26.      */
  27.     private $shoppingListService;
  28.     /**
  29.      * Subscriber constructor.
  30.      * @param ShoppingList $shoppingListService
  31.      */
  32.     public function __construct(ShoppingList $shoppingListService)
  33.     {
  34.         $this->shoppingListService $shoppingListService;
  35.     }
  36.     /**
  37.      * @return array
  38.      */
  39.     public static function getSubscribedEvents(): array
  40.     {
  41.         return [
  42.             CheckoutCartPageLoadedEvent::class => 'onCheckoutCartPageLoadedEvent'
  43.         ];
  44.     }
  45.     /**
  46.      * add gbmedShoppingLists extension
  47.      *
  48.      * @param ProductPageLoadedEvent $event
  49.      * @throws \Exception
  50.      */
  51.     public function onCheckoutCartPageLoadedEvent(CheckoutCartPageLoadedEvent $event): void
  52.     {
  53.         if ($event->getSalesChannelContext()->getCustomer() && !$event->getSalesChannelContext()->getCustomer()->getGuest()) {
  54.             $shoppingLists $this->shoppingListService->getCustomerShoppingListsMinimal($event->getSalesChannelContext());
  55.             $event->getPage()->addExtension('gbmedShoppingLists'$shoppingLists->getEntities());
  56.         }
  57.     }
  58. }