vendor/lnb/shopware6-checkout-customization/src/Subscriber/CartSavingsSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace Lnb\Shopware6\CheckoutCustomization\Subscriber;
  3. use Lnb\Shopware6\CheckoutCustomization\Content\Savings\SavingsCalculator;
  4. use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
  5. use Shopware\Core\Framework\Routing\Event\SalesChannelContextResolvedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CartSavingsSubscriber implements EventSubscriberInterface
  8. {
  9.     private SavingsCalculator $savingsCalculator;
  10.     private CartService $cartService;
  11.     public function __construct(SavingsCalculator $savingsCalculatorCartService $cartService)
  12.     {
  13.         $this->savingsCalculator $savingsCalculator;
  14.         $this->cartService $cartService;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             SalesChannelContextResolvedEvent::class => 'onSalesChannelContextResolvedEvent',
  20.         ];
  21.     }
  22.     public function onSalesChannelContextResolvedEvent(SalesChannelContextResolvedEvent $event): void
  23.     {
  24.         $cart $this->cartService->getCart($event->getSalesChannelContext()->getToken(), $event->getSalesChannelContext());
  25.         $this->savingsCalculator->calculate($cart);
  26.     }
  27. }