<?php declare(strict_types=1);
/**
* gb media
* All Rights Reserved.
*
* Unauthorized copying of this file, via any medium is strictly prohibited.
* The content of this file is proprietary and confidential.
*
* @category Shopware
* @package Shopware_Plugins
* @subpackage GbmedShoppingList
* @copyright Copyright (c) 2020, gb media
* @license proprietary
* @author Giuseppe Bottino
* @link http://www.gb-media.biz
*/
namespace Gbmed\ShoppingList\Subscriber;
use Gbmed\ShoppingList\Service\ShoppingList;
use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Checkout implements EventSubscriberInterface
{
/**
* @var ShoppingList
*/
private $shoppingListService;
/**
* Subscriber constructor.
* @param ShoppingList $shoppingListService
*/
public function __construct(ShoppingList $shoppingListService)
{
$this->shoppingListService = $shoppingListService;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
CheckoutCartPageLoadedEvent::class => 'onCheckoutCartPageLoadedEvent'
];
}
/**
* add gbmedShoppingLists extension
*
* @param ProductPageLoadedEvent $event
* @throws \Exception
*/
public function onCheckoutCartPageLoadedEvent(CheckoutCartPageLoadedEvent $event): void
{
if ($event->getSalesChannelContext()->getCustomer() && !$event->getSalesChannelContext()->getCustomer()->getGuest()) {
$shoppingLists = $this->shoppingListService->getCustomerShoppingListsMinimal($event->getSalesChannelContext());
$event->getPage()->addExtension('gbmedShoppingLists', $shoppingLists->getEntities());
}
}
}