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