<?php declare(strict_types=1);
namespace Samson\Subscriber;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2020
*
***/
use Samson\Service\PersistentCartService;
use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class CheckoutSubscriber
* @package Samson\Subscriber
* @author Artur Seitz <artur.seitz@dkd.de>
*/
class CheckoutSubscriber implements EventSubscriberInterface
{
/** @var PersistentCartService */
protected $persistentCartService;
/**
* CartSubscriber constructor.
*
* @param PersistentCartService $persistentCartService
*/
public function __construct(
PersistentCartService $persistentCartService
) {
$this->persistentCartService = $persistentCartService;
}
/** {@inheritDoc} */
public static function getSubscribedEvents(): array
{
return [
CheckoutOrderPlacedEvent::class => 'onCheckoutOrderPlacedEvent',
];
}
/**
* CheckoutOrderPlacedEvent event listener.
*
* @param CheckoutOrderPlacedEvent $event
*/
public function onCheckoutOrderPlacedEvent(CheckoutOrderPlacedEvent $event): void
{
$customer = $event->getOrder()->getOrderCustomer()->getCustomer();
$context = $event->getContext();
$this->persistentCartService->removePersistentCart($customer, $context);
}
}