From 37f4b9caa02783e06dd7c5318200113409a0deb1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Jul 2011 17:56:50 -0500 Subject: backed out 648b42a75739, which was a NON-trivial whitespace commit. It broke the Typography class's string replacements, for instance --- system/libraries/Cart.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index fbccfb3d9..7f65b48b9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,4 +1,4 @@ -CI =& get_instance(); - // Are any config settings being passed manually? If so, set them + // Are any config settings being passed manually? If so, set them $config = array(); if (count($params) > 0) { @@ -148,7 +148,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Does the $items array contain an id, quantity, price, and name? These are required + // Does the $items array contain an id, quantity, price, and name? These are required if ( ! isset($items['id']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($items['name'])) { log_message('error', 'The cart array must contain a product ID, quantity, price, and name.'); @@ -157,7 +157,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the quantity. It can only be a number. Duh... + // Prep the quantity. It can only be a number. Duh... $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty'])); // Trim any leading zeros $items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty'])); @@ -175,7 +175,7 @@ class CI_Cart { // Note: These can be user-specified by setting the $this->product_id_rules variable. if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id'])) { - log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); + log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); return FALSE; } @@ -191,7 +191,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the price. Remove anything that isn't a number or decimal point. + // Prep the price. Remove anything that isn't a number or decimal point. $items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price'])); // Trim any leading zeros $items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price'])); @@ -210,7 +210,7 @@ class CI_Cart { // Each row in the cart array, however, must have a unique index that identifies not only // a particular product, but makes it possible to store identical products with different options. // For example, what if someone buys two identical t-shirts (same product ID), but in - // different sizes? The product ID (and other attributes, like the name) will be identical for + // different sizes? The product ID (and other attributes, like the name) will be identical for // both sizes because it's the same shirt. The only difference will be the size. // Internally, we need to treat identical submissions, but with different options, as a unique product. // Our solution is to convert the options array to a string and MD5 it along with the product ID. @@ -271,7 +271,7 @@ class CI_Cart { } // You can either update a single product using a one-dimensional array, - // or multiple products using a multi-dimensional one. The way we + // or multiple products using a multi-dimensional one. The way we // determine the array type is by looking for a required array key named "id". // If it's not found we assume it's a multi-dimensional array $save_cart = FALSE; @@ -344,7 +344,7 @@ class CI_Cart { return FALSE; } - // Is the quantity zero? If so we will remove the item from the cart. + // Is the quantity zero? If so we will remove the item from the cart. // If the quantity is greater than zero we are updating if ($items['qty'] == 0) { @@ -392,7 +392,7 @@ class CI_Cart { $this->_cart_contents['total_items'] = count($this->_cart_contents); $this->_cart_contents['cart_total'] = $total; - // Is our cart empty? If so we delete it from the session + // Is our cart empty? If so we delete it from the session if (count($this->_cart_contents) <= 2) { $this->CI->session->unset_userdata('cart_contents'); -- cgit v1.2.3-24-g4f1b From 98b2126f1050f9f29677c7c6236c8039bbfee9ea Mon Sep 17 00:00:00 2001 From: MarcosCoelho Date: Mon, 18 Jul 2011 16:12:47 -0300 Subject: sync total items count and total amount price; by sum of quantity of each item in cart --- system/libraries/Cart.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 7f65b48b9..b2eaa9ad7 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -374,6 +374,7 @@ class CI_Cart { // Lets add up the individual prices and set the cart sub-total $total = 0; + $items = 0; foreach ($this->_cart_contents as $key => $val) { // We make sure the array contains the proper indexes @@ -383,13 +384,14 @@ class CI_Cart { } $total += ($val['price'] * $val['qty']); + $items += $val['qty']; // Set the subtotal $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); } // Set the cart total and total items. - $this->_cart_contents['total_items'] = count($this->_cart_contents); + $this->_cart_contents['total_items'] = $items; $this->_cart_contents['cart_total'] = $total; // Is our cart empty? If so we delete it from the session -- cgit v1.2.3-24-g4f1b From 909105135439ac2ade75a99922f77c038e882fee Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 20 Jul 2011 10:07:40 -0600 Subject: Changed Cart library to return the if inserted successfully. This will be fine for anyone using () == true. http://codeigniter.uservoice.com/forums/40508-codeigniter-reactor/suggestions/2055829-last-rowid-of-cart --- system/libraries/Cart.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index b2eaa9ad7..ab5a70c98 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -99,7 +99,7 @@ class CI_Cart { $save_cart = FALSE; if (isset($items['id'])) { - if ($this->_insert($items) == TRUE) + if (($rowid = $this->_insert($items))) { $save_cart = TRUE; } @@ -110,7 +110,7 @@ class CI_Cart { { if (is_array($val) AND isset($val['id'])) { - if ($this->_insert($val) == TRUE) + if ($this->_insert($val)) { $save_cart = TRUE; } @@ -122,7 +122,7 @@ class CI_Cart { if ($save_cart == TRUE) { $this->_save_cart(); - return TRUE; + return isset($rowid) ? $rowid : TRUE; } return FALSE; @@ -244,7 +244,7 @@ class CI_Cart { } // Woot! - return TRUE; + return $rowid; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b