<?php declare(strict_types=1);
namespace Acris\ProductVoucherCode\Storefront\Subscriber;
use Acris\ProductVoucherCode\Components\Service\ProductVoucherCodeService;
use Shopware\Core\Checkout\Cart\Event\BeforeLineItemRemovedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class StorefrontCartSubscriber implements EventSubscriberInterface
{
private ProductVoucherCodeService $productVoucherCodeService;
public function __construct(ProductVoucherCodeService $productVoucherCodeService)
{
$this->productVoucherCodeService = $productVoucherCodeService;
}
public static function getSubscribedEvents(): array
{
return [
BeforeLineItemRemovedEvent::class => [
['onLineItemRemoved', 200],
]
];
}
public function onLineItemRemoved(BeforeLineItemRemovedEvent $event): void
{
$this->productVoucherCodeService->reduceQuantity($event->getCart(), $event->getLineItem(), $event->getSalesChannelContext());
$this->productVoucherCodeService->changePromotionIds($event->getCart());
}
}