diff options
author | Rick Ellis <rick.ellis@ellislab.com> | 2009-02-24 23:44:22 +0100 |
---|---|---|
committer | Rick Ellis <rick.ellis@ellislab.com> | 2009-02-24 23:44:22 +0100 |
commit | af4fb22745413cac182064a495da83318a41fde9 (patch) | |
tree | bdc6af21532674a02d432a971a54dd85ae6e473e /system | |
parent | f4ed69e80c553486a8f3d69e46911fcb25c73b9e (diff) |
Fixed a bug in the "save cart" function that was causing the total to be calcluated incorrectly
Diffstat (limited to 'system')
-rw-r--r-- | system/libraries/Cart.php | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 800c21f75..2eb8b75be 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -368,12 +368,16 @@ class CI_Cart { */ function _save_cart() { - // First we add up the individual prices and get the cart total + // Unset these so our total can be calculated correctly below + unset($this->_cart_contents['total_items']); + unset($this->_cart_contents['cart_total']); + + // Lets add up the individual prices and set the cart sub-total $total = 0; foreach ($this->_cart_contents as $key => $val) { // We make sure the array contains the proper indexes - if ( ! isset($val['price']) or ! isset($val['qty'])) + if ( ! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty'])) { continue; } @@ -381,14 +385,9 @@ class CI_Cart { $total += ($val['price'] * $val['qty']); // Set the subtotal - // Note: "subtotal" is a reserved array index. We need to make a note of that in the docs $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); } - // Unset these so our total can be calculated correctly below - unset($this->_cart_contents['total_items']); - unset($this->_cart_contents['cart_total']); - // Set the cart total and total items. $this->_cart_contents['total_items'] = count($this->_cart_contents); $this->_cart_contents['cart_total'] = $total; |