From 384e6606d13b3465258c0a45224cbcd93fe93d40 Mon Sep 17 00:00:00 2001 From: Antonio Peric Date: Wed, 26 Feb 2020 23:35:09 +0100 Subject: [PATCH 1/2] Update CartItemViewFactory.php --- src/Factory/Cart/CartItemViewFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factory/Cart/CartItemViewFactory.php b/src/Factory/Cart/CartItemViewFactory.php index 2d80a3b53..8d262585a 100644 --- a/src/Factory/Cart/CartItemViewFactory.php +++ b/src/Factory/Cart/CartItemViewFactory.php @@ -39,7 +39,7 @@ public function create(OrderItemInterface $item, ChannelInterface $channel, stri $itemView->id = $item->getId(); $itemView->quantity = $item->getQuantity(); - $itemView->total = $item->getTotal(); + $itemView->total = $item->getSubtotal(); $itemView->product = $this->productViewFactory->create($item->getProduct(), $channel, $locale); $itemView->product->variants = [$this->productVariantViewFactory->create($item->getVariant(), $channel, $locale)]; From 747561e35e1a17c03bb98970c33fb10f9ba6550c Mon Sep 17 00:00:00 2001 From: Antonio Peric Date: Wed, 26 Feb 2020 23:39:31 +0100 Subject: [PATCH 2/2] fixed items total in cart response --- src/Factory/Cart/TotalViewFactory.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Factory/Cart/TotalViewFactory.php b/src/Factory/Cart/TotalViewFactory.php index dc2866406..f3fecc41f 100644 --- a/src/Factory/Cart/TotalViewFactory.php +++ b/src/Factory/Cart/TotalViewFactory.php @@ -25,10 +25,21 @@ public function create(OrderInterface $cart): TotalsView $totalsView->promotion = $cart->getOrderPromotionTotal(); $totalsView->total = $cart->getTotal(); - $totalsView->items = $cart->getItemsTotal(); + $totalsView->items = $this->getSubtotal($cart); $totalsView->shipping = $cart->getShippingTotal(); $totalsView->taxes = $cart->getTaxTotal(); return $totalsView; } + + private function getSubtotal(OrderInterface $order): int + { + return array_reduce( + $order->getItems()->toArray(), + static function (int $subtotal, OrderItemInterface $item) { + return $subtotal + $item->getSubtotal(); + }, + 0 + ); + } }