| @@ 12-37 (lines=26) @@ | ||
| 9 | use Sylius\ShopApiPlugin\Command\DropCart; |
|
| 10 | use Webmozart\Assert\Assert; |
|
| 11 | ||
| 12 | final class DropCartHandler |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var OrderRepositoryInterface |
|
| 16 | */ |
|
| 17 | private $cartRepository; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @param OrderRepositoryInterface $cartRepository |
|
| 21 | */ |
|
| 22 | public function __construct(OrderRepositoryInterface $cartRepository) |
|
| 23 | { |
|
| 24 | $this->cartRepository = $cartRepository; |
|
| 25 | } |
|
| 26 | ||
| 27 | public function handle(DropCart $dropCart) |
|
| 28 | { |
|
| 29 | /** @var OrderInterface $cart */ |
|
| 30 | $cart = $this->cartRepository->findOneBy(['tokenValue' => $dropCart->orderToken()]); |
|
| 31 | ||
| 32 | Assert::notNull($cart, sprintf('Order with %s token has not been found.', $dropCart->orderToken())); |
|
| 33 | Assert::same(OrderInterface::STATE_CART, $cart->getState()); |
|
| 34 | ||
| 35 | $this->cartRepository->remove($cart); |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| @@ 13-51 (lines=39) @@ | ||
| 10 | use Sylius\ShopApiPlugin\Command\RemoveCoupon; |
|
| 11 | use Webmozart\Assert\Assert; |
|
| 12 | ||
| 13 | final class RemoveCouponHandler |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var OrderRepositoryInterface |
|
| 17 | */ |
|
| 18 | private $orderRepository; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var OrderProcessorInterface |
|
| 22 | */ |
|
| 23 | private $orderProcessor; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param OrderRepositoryInterface $orderRepository |
|
| 27 | * @param OrderProcessorInterface $orderProcessor |
|
| 28 | */ |
|
| 29 | public function __construct( |
|
| 30 | OrderRepositoryInterface $orderRepository, |
|
| 31 | OrderProcessorInterface $orderProcessor |
|
| 32 | ) { |
|
| 33 | $this->orderRepository = $orderRepository; |
|
| 34 | $this->orderProcessor = $orderProcessor; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @param RemoveCoupon $removeCoupon |
|
| 39 | */ |
|
| 40 | public function handle(RemoveCoupon $removeCoupon) |
|
| 41 | { |
|
| 42 | /** @var OrderInterface $cart */ |
|
| 43 | $cart = $this->orderRepository->findOneBy(['tokenValue' => $removeCoupon->orderToken()]); |
|
| 44 | ||
| 45 | Assert::notNull($cart, sprintf('Cart with token %s has not been found.', $removeCoupon->orderToken())); |
|
| 46 | ||
| 47 | $cart->setPromotionCoupon(null); |
|
| 48 | ||
| 49 | $this->orderProcessor->process($cart); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||