Skip to content

Commit

Permalink
Merge branch 'feature/apm-unbranded' into tests/ps6-apm-unbranded
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Jul 5, 2023
2 parents d4559f1 + eab9118 commit 979e340
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Checkout/CheckoutChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 11 additions & 1 deletion src/Order/CommandHandler/CreateOrderCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 979e340

Please sign in to comment.