Skip to content

Commit

Permalink
Fix fatal error on CartPresenter on PS 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Oct 3, 2024
1 parent e8fef40 commit 8c29135
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/Presenter/Cart/CartPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,25 @@ public function present()
{
$context = \Context::getContext();
$productList = $context->cart->getProducts();

$cart = (array) $context->cart;

if (class_exists('\PrestaShop\PrestaShop\Adapter\Cart\CartPresenter')) {
$cart = new \PrestaShop\PrestaShop\Adapter\Cart\CartPresenter();
$cart = (array) $cart->present($context->cart);
}

if (false === isset($cart['totals']['total_including_tax']['amount'])) {
// Handle native CartPresenter before 1.7.2
$cart['totals']['total_including_tax']['amount'] = $context->cart->getOrderTotal(true);
}

$shippingAddress = \Address::initialize((int) $cart['id_address_delivery']);
$invoiceAddress = \Address::initialize((int) $cart['id_address_invoice']);
$shippingAddress = \Address::initialize((int) $context->cart->id_address_delivery);
$invoiceAddress = \Address::initialize((int) $context->cart->id_address_invoice);
$currency = \Currency::getCurrencyInstance((int) $context->cart->id_currency);

return [
'cart' => array_merge(
$cart,
['id' => $context->cart->id],
['shipping_cost' => $context->cart->getTotalShippingCost(null, true)]
),
'cart' => [
'id' => $context->cart->id,
'shipping_cost' => $context->cart->getTotalShippingCost(null, true),
'totals' => [
'total_including_tax' => [
'amount' => $context->cart->getOrderTotal(true),
],
],
'subtotals' => [
'gift_wrapping' => [
'amount' => $context->cart->getGiftWrappingPrice(true),
],
],
],
'customer' => \Validate::isLoadedObject($context->customer) ? $context->customer : new \Customer((int) $context->cart->id_customer),
'language' => $context->language,
'products' => $productList,
Expand Down

0 comments on commit 8c29135

Please sign in to comment.