src/Sylius/Bundle/CoreBundle/EventListener/UserCartRecalculationListener.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\CoreBundle\EventListener;
  12. use Sylius\Component\Core\Model\OrderInterface;
  13. use Sylius\Component\Order\Context\CartContextInterface;
  14. use Sylius\Component\Order\Context\CartNotFoundException;
  15. use Sylius\Component\Order\Processor\OrderProcessorInterface;
  16. use Symfony\Component\EventDispatcher\Event;
  17. use Webmozart\Assert\Assert;
  18. final class UserCartRecalculationListener
  19. {
  20.     /** @var CartContextInterface */
  21.     private $cartContext;
  22.     /** @var OrderProcessorInterface */
  23.     private $orderProcessor;
  24.     public function __construct(CartContextInterface $cartContextOrderProcessorInterface $orderProcessor)
  25.     {
  26.         $this->cartContext $cartContext;
  27.         $this->orderProcessor $orderProcessor;
  28.     }
  29.     /**
  30.      * @throws \InvalidArgumentException
  31.      */
  32.     public function recalculateCartWhileLogin(Event $event): void
  33.     {
  34.         try {
  35.             $cart $this->cartContext->getCart();
  36.         } catch (CartNotFoundException $exception) {
  37.             return;
  38.         }
  39.         Assert::isInstanceOf($cartOrderInterface::class);
  40.         $this->orderProcessor->process($cart);
  41.     }
  42. }