From 53dc3d7e3fa8e66eac19bad7782c6988c6d48618 Mon Sep 17 00:00:00 2001 From: Taylor Daughtry Date: Mon, 10 Apr 2017 09:42:50 -0500 Subject: [PATCH 1/2] Fix an issue where adding multiples of an item wouldn't be reflected in itemCount --- services/CartBundleService.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/CartBundleService.php b/services/CartBundleService.php index b0cbc6d..45563e8 100644 --- a/services/CartBundleService.php +++ b/services/CartBundleService.php @@ -47,7 +47,15 @@ public function cartItemsCount() // Only worry about doing more processing if there are enough items in the cart to bundle if ( $cartItemsCount > 1 ) { $lineItems = $this->bundleItems( $cart->lineItems ); - $cartItemsCount = count( $lineItems ); + + $qty = 0; + + foreach ( $lineItems as $item ) { + $qty += $item->qty; + } + + $cartItemsCount = $qty; + } return $cartItemsCount; From 108b8069556425fa416e54596c32273bfe32bea5 Mon Sep 17 00:00:00 2001 From: Taylor Daughtry Date: Mon, 10 Apr 2017 10:02:00 -0500 Subject: [PATCH 2/2] Fix an issue where having zero bundled items produced an incorrect count --- services/CartBundleService.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/services/CartBundleService.php b/services/CartBundleService.php index 45563e8..a433a13 100644 --- a/services/CartBundleService.php +++ b/services/CartBundleService.php @@ -42,23 +42,20 @@ public function cartItemsCount() { // Get the current cart $cart = craft()->commerce_cart->getCart(); - $cartItemsCount = count( $cart->lineItems ); + $lineItems = $cart->lineItems; // Only worry about doing more processing if there are enough items in the cart to bundle - if ( $cartItemsCount > 1 ) { + if ( count( $lineItems ) > 1 ) { $lineItems = $this->bundleItems( $cart->lineItems ); + } - $qty = 0; - - foreach ( $lineItems as $item ) { - $qty += $item->qty; - } - - $cartItemsCount = $qty; + $qty = 0; + foreach ( $lineItems as $item ) { + $qty += $item->qty; } - return $cartItemsCount; + return $qty; } /**