diff --git a/src/Checkout/CheckoutChecker.php b/src/Checkout/CheckoutChecker.php index ed406ee46..9ffef68a2 100644 --- a/src/Checkout/CheckoutChecker.php +++ b/src/Checkout/CheckoutChecker.php @@ -101,7 +101,9 @@ public function continueWithAuthorization($cartId, $orderPayPal) throw new PsCheckoutException(sprintf('Cart with id %s not found.', var_export($cartId, true)), PsCheckoutException::PRESTASHOP_CART_NOT_FOUND); } - if (!$cart->nbProducts()) { + $products = $cart->getProducts(true); + + if (empty($products)) { throw new PsCheckoutException(sprintf('Cart with id %s has no product. Cannot capture the order.', var_export($cart->id, true)), PsCheckoutException::CART_PRODUCT_MISSING); } diff --git a/src/Order/CommandHandler/CreateOrderCommandHandler.php b/src/Order/CommandHandler/CreateOrderCommandHandler.php index 782315d3a..ec7408102 100644 --- a/src/Order/CommandHandler/CreateOrderCommandHandler.php +++ b/src/Order/CommandHandler/CreateOrderCommandHandler.php @@ -109,7 +109,11 @@ public function handle(CreateOrderCommand $command) /** @var PsCheckoutCart $psCheckoutCart */ $psCheckoutCart = $this->psCheckoutCartRepository->findOneByPayPalOrderId($command->getOrderPayPalId()->getValue()); - $cart = new Cart($psCheckoutCart->getIdCart()); + if (Validate::isLoadedObject($this->contextStateManager->getContext()->cart) && (int) $this->contextStateManager->getContext()->cart->id === $psCheckoutCart->getIdCart()) { + $cart = $this->contextStateManager->getContext()->cart; + } else { + $cart = new Cart($psCheckoutCart->getIdCart()); + } if (!Validate::isLoadedObject($cart)) { throw new PsCheckoutException('Cart not found', PsCheckoutException::PRESTASHOP_CART_NOT_FOUND); @@ -122,6 +126,12 @@ public function handle(CreateOrderCommand $command) return; } + $products = $cart->getProducts(true); + + if (empty($products)) { + throw new PsCheckoutException(sprintf('Cart with id %s has no product. Cannot create the order.', var_export($cart->id, true)), PsCheckoutException::CART_PRODUCT_MISSING); + } + $fundingSource = $psCheckoutCart->getPaypalFundingSource(); $transactionId = $orderStateId = $paidAmount = ''; $capture = $command->getCapturePayPal();