From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Cart.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index ab5a70c98..a0e1bb91e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -21,7 +33,7 @@ * @package CodeIgniter * @subpackage Libraries * @category Shopping Cart - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/cart.html */ class CI_Cart { -- cgit v1.2.3-24-g4f1b From 2e5bda3bde171e71306c80479f04d886127d88a2 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Tue, 13 Dec 2011 11:40:15 +0000 Subject: Updated Cart.php to handle quantity changes differently (now auto-increments), also updated the changelog to reflect this change for the people that are currently using this library --- system/libraries/Cart.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index a0e1bb91e..13485a3ee 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -41,6 +41,7 @@ class CI_Cart { // These are the regular expression rules that we use to validate the product ID and product name var $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods var $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods + var $product_name_safe = true; // only allow safe product names // Private variables. Do not change! var $CI; @@ -195,10 +196,13 @@ class CI_Cart { // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. // Note: These can be user-specified by setting the $this->product_name_rules variable. - if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) + if($this->product_name_safe) { - log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); - return FALSE; + if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) + { + log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); + return FALSE; + } } // -------------------------------------------------------------------- @@ -242,7 +246,18 @@ class CI_Cart { // -------------------------------------------------------------------- // Now that we have our unique "row ID", we'll add our cart items to the master array - + // grab quantity if it's already there and add it on + if(isset($this->_cart_contents[$rowid]['qty'])) + { + // set our old quantity + $old_quantity = (int)$this->_cart_contents[$rowid]['qty']; + } + else + { + // we have no old quantity but - we don't want to throw an error + $old_quantity = 0; + } + // let's unset this first, just to make sure our index contains only the data from this submission unset($this->_cart_contents[$rowid]); @@ -254,7 +269,10 @@ class CI_Cart { { $this->_cart_contents[$rowid][$key] = $val; } - + + // add old quantity back in + $this->_cart_contents[$rowid]['qty'] = ($this->_cart_contents[$rowid]['qty'] + $old_quantity); + // Woot! return $rowid; } -- cgit v1.2.3-24-g4f1b From 3dd66631330841e4d0e29a95fc279a5d5cc921f2 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Tue, 13 Dec 2011 15:50:52 +0000 Subject: Merged the two if's together as suggested by @philsturgeon - updated the Changelog to include something that may be important --- system/libraries/Cart.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 13485a3ee..f9f3bca47 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -196,13 +196,10 @@ class CI_Cart { // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. // Note: These can be user-specified by setting the $this->product_name_rules variable. - if($this->product_name_safe) + if ( $this->product_name_safe && ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) { - if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) - { - log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); - return FALSE; - } + log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); + return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fefff9fcdfc26676b8c57653c3d8176b729901b2 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Tue, 13 Dec 2011 15:52:50 +0000 Subject: Spacing added, @philsturgeon is too picky! --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index f9f3bca47..997b9b8de 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -244,7 +244,7 @@ class CI_Cart { // Now that we have our unique "row ID", we'll add our cart items to the master array // grab quantity if it's already there and add it on - if(isset($this->_cart_contents[$rowid]['qty'])) + if( isset($this->_cart_contents[$rowid]['qty'])) { // set our old quantity $old_quantity = (int)$this->_cart_contents[$rowid]['qty']; -- cgit v1.2.3-24-g4f1b From de2e96a298cc48b8e86a03d530bc328bd43b0c80 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Tue, 13 Dec 2011 16:44:59 +0000 Subject: Added the ability to get the contents in a different order --- system/libraries/Cart.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 997b9b8de..2e580863b 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -476,9 +476,17 @@ class CI_Cart { * @access public * @return array */ - function contents() + function contents($newest_first = false) { - $cart = $this->_cart_contents; + // do we want the newest first? + if($newest_first) + { + // reverse the array + $cart = array_reverse($this->_cart_contents); + } else { + // just added first to last + $cart = $this->_cast_contents; + } // Remove these so they don't create a problem when showing the cart table unset($cart['total_items']); -- cgit v1.2.3-24-g4f1b From 17aebce8e06fae0edf1d54cf6823f1b8f48924c0 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Tue, 13 Dec 2011 16:57:13 +0000 Subject: Changed the syntax slightly, @philsturgeon may be claustrophobic as he doesn't like no spaces --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 2e580863b..e78ecd5f6 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -244,7 +244,7 @@ class CI_Cart { // Now that we have our unique "row ID", we'll add our cart items to the master array // grab quantity if it's already there and add it on - if( isset($this->_cart_contents[$rowid]['qty'])) + if (isset($this->_cart_contents[$rowid]['qty'])) { // set our old quantity $old_quantity = (int)$this->_cart_contents[$rowid]['qty']; -- cgit v1.2.3-24-g4f1b From f75ec11d7ed0592f930dd3a090db7c1c6d251eed Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Wed, 14 Dec 2011 09:36:39 +0000 Subject: Added in a remove item from cart function to save the "hacky" method of updating a product with 0 quantity, updated the changelog to reflect and to be neater and more readable surrounding the changes of the Cart library --- system/libraries/Cart.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index e78ecd5f6..7f6cdf5dd 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -450,7 +450,29 @@ class CI_Cart { { return $this->_cart_contents['cart_total']; } - + + // -------------------------------------------------------------------- + + /** + * Remove Item + * + * Removes an item from the cart + * + * @access public + * @return boolean + */ + public function remove($rowid) + { + // just do an unset + unset($this->_cart_contents[$rowid]); + + // we need to save the cart now we've made our changes + $this->_save_cart(); + + // completed + return true; + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 3a67ed15d984a341612af9e1dd9ba52f30d02e89 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Wed, 14 Dec 2011 15:35:06 +0000 Subject: Slight syntax change to the Cart class --- 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 7f6cdf5dd..717ccd9fb 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -505,7 +505,9 @@ class CI_Cart { { // reverse the array $cart = array_reverse($this->_cart_contents); - } else { + } + else + { // just added first to last $cart = $this->_cast_contents; } -- cgit v1.2.3-24-g4f1b From bb2488305194e50881df0971bf4f33f30d974d36 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 21 Dec 2011 16:42:51 +0200 Subject: Improved the Cart library --- system/libraries/Cart.php | 196 +++++++++++++++------------------------------- 1 file changed, 61 insertions(+), 135 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 717ccd9fb..b2cc2081e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,13 +1,13 @@ -CI =& get_instance(); // Are any config settings being passed manually? If so, set them - $config = array(); - if (count($params) > 0) - { - foreach ($params as $key => $val) - { - $config[$key] = $val; - } - } + $config = is_array($params) ? $params : array(); // Load the Sessions class $this->CI->load->library('session', $config); - // Grab the shopping cart array from the session table, if it exists - if ($this->CI->session->userdata('cart_contents') !== FALSE) - { - $this->_cart_contents = $this->CI->session->userdata('cart_contents'); - } - else + // Grab the shopping cart array from the session table + $this->_cart_contents = $this->CI->session->userdata('cart_contents'); + if ($this->_cart_contents === FALSE) { // No cart exists so we'll set some base values - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; + $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); } log_message('debug', "Cart Class Initialized"); @@ -95,10 +84,10 @@ class CI_Cart { * @param array * @return bool */ - function insert($items = array()) + public function insert($items = array()) { // Was any cart data passed? No? Bah... - if ( ! is_array($items) OR count($items) == 0) + if ( ! is_array($items) OR count($items) === 0) { log_message('error', 'The insert method must be passed an array containing data.'); return FALSE; @@ -132,7 +121,7 @@ class CI_Cart { } // Save the cart data if the insert was successful - if ($save_cart == TRUE) + if ($save_cart === TRUE) { $this->_save_cart(); return isset($rowid) ? $rowid : TRUE; @@ -150,10 +139,10 @@ class CI_Cart { * @param array * @return bool */ - function _insert($items = array()) + private function _insert($items = array()) { // Was any cart data passed? No? Bah... - if ( ! is_array($items) OR count($items) == 0) + if ( ! is_array($items) OR count($items) === 0) { log_message('error', 'The insert method must be passed an array containing data.'); return FALSE; @@ -170,10 +159,8 @@ class CI_Cart { // -------------------------------------------------------------------- - // 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'])); + // Prep the quantity. It can only be a number. Duh... also trim any leading zeros + $items['qty'] = ltrim(trim(preg_replace('/([^0-9])/i', '', $items['qty'])), '0'); // If the quantity is zero or blank there's nothing for us to do if ( ! is_numeric($items['qty']) OR $items['qty'] == 0) @@ -186,7 +173,7 @@ class CI_Cart { // Validate the product ID. It can only be alpha-numeric, dashes, underscores or periods // Not totally sure we should impose this rule, but it seems prudent to standardize IDs. // Note: These can be user-specified by setting the $this->product_id_rules variable. - if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id'])) + 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'); return FALSE; @@ -196,7 +183,7 @@ class CI_Cart { // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. // Note: These can be user-specified by setting the $this->product_name_rules variable. - if ( $this->product_name_safe && ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) + if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/i', $items['name'])) { log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); return FALSE; @@ -204,10 +191,8 @@ class CI_Cart { // -------------------------------------------------------------------- - // 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'])); + // Prep the price. Remove leading zeros and anything that isn't a number or decimal point. + $items['price'] = lrtrim(trim(preg_replace('/([^0-9\.])/i', '', $items['price'])), '0'); // Is the price a valid number? if ( ! is_numeric($items['price'])) @@ -244,33 +229,13 @@ class CI_Cart { // Now that we have our unique "row ID", we'll add our cart items to the master array // grab quantity if it's already there and add it on - if (isset($this->_cart_contents[$rowid]['qty'])) - { - // set our old quantity - $old_quantity = (int)$this->_cart_contents[$rowid]['qty']; - } - else - { - // we have no old quantity but - we don't want to throw an error - $old_quantity = 0; - } - - // let's unset this first, just to make sure our index contains only the data from this submission - unset($this->_cart_contents[$rowid]); + $old_quantity = isset($this->_cart_contents[$rowid]['qty']) ? (int) $this->_cart_contents[$rowid]['qty'] : 0; - // Create a new index with our new row ID - $this->_cart_contents[$rowid]['rowid'] = $rowid; + // Re-create the entry, just to make sure our index contains only the data from this submission + $items['rowid'] = $rowid; + $items['qty'] += $old_quantity; + $this->_cart_contents[$rowid] = $items; - // And add the new items to the cart array - foreach ($items as $key => $val) - { - $this->_cart_contents[$rowid][$key] = $val; - } - - // add old quantity back in - $this->_cart_contents[$rowid]['qty'] = ($this->_cart_contents[$rowid]['qty'] + $old_quantity); - - // Woot! return $rowid; } @@ -289,10 +254,10 @@ class CI_Cart { * @param string * @return bool */ - function update($items = array()) + public function update($items = array()) { // Was any cart data passed? - if ( ! is_array($items) OR count($items) == 0) + if ( ! is_array($items) OR count($items) === 0) { return FALSE; } @@ -302,9 +267,9 @@ class CI_Cart { // 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; - if (isset($items['rowid']) AND isset($items['qty'])) + if (isset($items['rowid'], $items['qty'])) { - if ($this->_update($items) == TRUE) + if ($this->_update($items) === TRUE) { $save_cart = TRUE; } @@ -313,9 +278,9 @@ class CI_Cart { { foreach ($items as $val) { - if (is_array($val) AND isset($val['rowid']) AND isset($val['qty'])) + if (is_array($val) && isset($val['rowid'], $val['qty'])) { - if ($this->_update($val) == TRUE) + if ($this->_update($val) === TRUE) { $save_cart = TRUE; } @@ -324,7 +289,7 @@ class CI_Cart { } // Save the cart data if the insert was successful - if ($save_cart == TRUE) + if ($save_cart === TRUE) { $this->_save_cart(); return TRUE; @@ -347,7 +312,7 @@ class CI_Cart { * @param array * @return bool */ - function _update($items = array()) + private function _update($items = array()) { // Without these array indexes there is nothing we can do if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']])) @@ -393,15 +358,10 @@ class CI_Cart { * @access private * @return bool */ - function _save_cart() + private function _save_cart() { - // 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; - $items = 0; + $this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0; foreach ($this->_cart_contents as $key => $val) { // We make sure the array contains the proper indexes @@ -410,17 +370,11 @@ class CI_Cart { continue; } - $total += ($val['price'] * $val['qty']); - $items += $val['qty']; - - // Set the subtotal + $this->_cart_contents['cart_total'] += ($val['price'] * $val['qty']); + $this->_cart_contents['total_items'] += $val['qty']; $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'] = $items; - $this->_cart_contents['cart_total'] = $total; - // Is our cart empty? If so we delete it from the session if (count($this->_cart_contents) <= 2) { @@ -434,7 +388,6 @@ class CI_Cart { // Let's pass it to the Session class so it can be stored $this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents)); - // Woot! return TRUE; } @@ -446,13 +399,13 @@ class CI_Cart { * @access public * @return integer */ - function total() + public function total() { return $this->_cart_contents['cart_total']; } - + // -------------------------------------------------------------------- - + /** * Remove Item * @@ -463,16 +416,12 @@ class CI_Cart { */ public function remove($rowid) { - // just do an unset + // unset & save unset($this->_cart_contents[$rowid]); - - // we need to save the cart now we've made our changes $this->_save_cart(); - - // completed - return true; + return TRUE; } - + // -------------------------------------------------------------------- /** @@ -483,7 +432,7 @@ class CI_Cart { * @access public * @return integer */ - function total_items() + public function total_items() { return $this->_cart_contents['total_items']; } @@ -498,19 +447,10 @@ class CI_Cart { * @access public * @return array */ - function contents($newest_first = false) + public function contents($newest_first = FALSE) { // do we want the newest first? - if($newest_first) - { - // reverse the array - $cart = array_reverse($this->_cart_contents); - } - else - { - // just added first to last - $cart = $this->_cast_contents; - } + $cart = ($newest_first) ? array_reverse($this->_cart_contents) : $this->_cart_contents; // Remove these so they don't create a problem when showing the cart table unset($cart['total_items']); @@ -528,16 +468,11 @@ class CI_Cart { * that has options associated with it. * * @access public - * @return array + * @return bool */ - function has_options($rowid = '') + public function has_options($rowid = '') { - if ( ! isset($this->_cart_contents[$rowid]['options']) OR count($this->_cart_contents[$rowid]['options']) === 0) - { - return FALSE; - } - - return TRUE; + return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0) ? TRUE : FALSE; } // -------------------------------------------------------------------- @@ -550,14 +485,9 @@ class CI_Cart { * @access public * @return array */ - function product_options($rowid = '') + public function product_options($rowid = '') { - if ( ! isset($this->_cart_contents[$rowid]['options'])) - { - return array(); - } - - return $this->_cart_contents[$rowid]['options']; + return isset($this->_cart_contents[$rowid]['options']) ? $this->_cart_contents[$rowid]['options'] : array(); } // -------------------------------------------------------------------- @@ -568,9 +498,9 @@ class CI_Cart { * Returns the supplied number with commas and a decimal point. * * @access public - * @return integer + * @return string */ - function format_number($n = '') + public function format_number($n = '') { if ($n == '') { @@ -591,15 +521,11 @@ class CI_Cart { * Empties the cart and kills the session * * @access public - * @return null + * @return void */ - function destroy() + public function destroy() { - unset($this->_cart_contents); - - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; - + $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); $this->CI->session->unset_userdata('cart_contents'); } @@ -608,4 +534,4 @@ class CI_Cart { // END Cart Class /* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ \ No newline at end of file +/* Location: ./system/libraries/Cart.php */ -- cgit v1.2.3-24-g4f1b From 17779d6163aa3a2b0544a45f7159717c95a23c2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Dec 2011 13:21:08 +0200 Subject: Cast to float instead of using preg_replace() for sanitizing numbers --- system/libraries/Cart.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index b2cc2081e..01a0cb8ce 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -160,7 +160,7 @@ class CI_Cart { // -------------------------------------------------------------------- // Prep the quantity. It can only be a number. Duh... also trim any leading zeros - $items['qty'] = ltrim(trim(preg_replace('/([^0-9])/i', '', $items['qty'])), '0'); + $items['qty'] = (float) $items['qty']; // If the quantity is zero or blank there's nothing for us to do if ( ! is_numeric($items['qty']) OR $items['qty'] == 0) @@ -192,7 +192,7 @@ class CI_Cart { // -------------------------------------------------------------------- // Prep the price. Remove leading zeros and anything that isn't a number or decimal point. - $items['price'] = lrtrim(trim(preg_replace('/([^0-9\.])/i', '', $items['price'])), '0'); + $items['price'] = (float) $items['price']; // Is the price a valid number? if ( ! is_numeric($items['price'])) @@ -321,7 +321,7 @@ class CI_Cart { } // Prep the quantity - $items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']); + $items['qty'] = (float) $items['qty']; // Is the quantity a number? if ( ! is_numeric($items['qty'])) @@ -388,6 +388,7 @@ class CI_Cart { // Let's pass it to the Session class so it can be stored $this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents)); + // Woot! return TRUE; } @@ -508,7 +509,7 @@ class CI_Cart { } // Remove anything that isn't a number or decimal point. - $n = trim(preg_replace('/([^0-9\.])/i', '', $n)); + $n = (float) $n; return number_format($n, 2, '.', ','); } -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 01a0cb8ce..ba8d69be2 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 287dd450911251c3dc4d744c2e03fcd5d8a5b173 Mon Sep 17 00:00:00 2001 From: Marcos Garcia Date: Fri, 17 Feb 2012 02:26:22 +0100 Subject: Fixed issue #960 --- system/libraries/Cart.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index ba8d69be2..10b5362a5 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -329,13 +329,6 @@ class CI_Cart { return FALSE; } - // Is the new quantity different than what is already saved in the cart? - // If it's the same there's nothing to do - if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty']) - { - return FALSE; - } - // 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) -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 10b5362a5..60a1e52fe 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 6f042ccc261645530e897bb8c390eae0640bacb0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 14:58:33 +0300 Subject: Switch private methods and properties to protected and cleanup the Cart library --- system/libraries/Cart.php | 46 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 60a1e52fe..305960f5f 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Shopping Cart Class * @@ -41,12 +39,11 @@ class CI_Cart { // These are the regular expression rules that we use to validate the product ID and product name public $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods public $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods - public $product_name_safe = true; // only allow safe product names - - // Private variables. Do not change! - private $CI; - private $_cart_contents = array(); + public $product_name_safe = TRUE; // only allow safe product names + // Protected variables. Do not change! + protected $CI; + protected $_cart_contents = array(); /** * Shopping Class Constructor @@ -72,7 +69,7 @@ class CI_Cart { $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); } - log_message('debug', "Cart Class Initialized"); + log_message('debug', 'Cart Class Initialized'); } // -------------------------------------------------------------------- @@ -80,7 +77,6 @@ class CI_Cart { /** * Insert items into the cart and save it to the session table * - * @access public * @param array * @return bool */ @@ -110,7 +106,7 @@ class CI_Cart { { foreach ($items as $val) { - if (is_array($val) AND isset($val['id'])) + if (is_array($val) && isset($val['id'])) { if ($this->_insert($val)) { @@ -135,7 +131,6 @@ class CI_Cart { /** * Insert * - * @access private * @param array * @return bool */ @@ -213,7 +208,7 @@ class CI_Cart { // 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. // This becomes the unique "row ID" - if (isset($items['options']) AND count($items['options']) > 0) + if (isset($items['options']) && count($items['options']) > 0) { $rowid = md5($items['id'].implode('', $items['options'])); } @@ -249,7 +244,6 @@ class CI_Cart { * changes to the quantity before checkout. That array must contain the * product ID and quantity for each item. * - * @access public * @param array * @param string * @return bool @@ -308,11 +302,10 @@ class CI_Cart { * changes to the quantity before checkout. That array must contain the * product ID and quantity for each item. * - * @access private * @param array * @return bool */ - private function _update($items = array()) + protected function _update($items = array()) { // Without these array indexes there is nothing we can do if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']])) @@ -348,10 +341,9 @@ class CI_Cart { /** * Save the cart array to the session DB * - * @access private * @return bool */ - private function _save_cart() + protected function _save_cart() { // Lets add up the individual prices and set the cart sub-total $this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0; @@ -390,8 +382,7 @@ class CI_Cart { /** * Cart Total * - * @access public - * @return integer + * @return int */ public function total() { @@ -405,8 +396,7 @@ class CI_Cart { * * Removes an item from the cart * - * @access public - * @return boolean + * @return bool */ public function remove($rowid) { @@ -423,8 +413,7 @@ class CI_Cart { * * Returns the total item count * - * @access public - * @return integer + * @return int */ public function total_items() { @@ -438,7 +427,6 @@ class CI_Cart { * * Returns the entire cart array * - * @access public * @return array */ public function contents($newest_first = FALSE) @@ -461,7 +449,6 @@ class CI_Cart { * Returns TRUE if the rowid passed to this function correlates to an item * that has options associated with it. * - * @access public * @return bool */ public function has_options($rowid = '') @@ -476,7 +463,7 @@ class CI_Cart { * * Returns the an array of options, for a particular product row ID * - * @access public + * @param int * @return array */ public function product_options($rowid = '') @@ -491,7 +478,7 @@ class CI_Cart { * * Returns the supplied number with commas and a decimal point. * - * @access public + * @param float * @return string */ public function format_number($n = '') @@ -514,7 +501,6 @@ class CI_Cart { * * Empties the cart and kills the session * - * @access public * @return void */ public function destroy() @@ -523,9 +509,7 @@ class CI_Cart { $this->CI->session->unset_userdata('cart_contents'); } - } -// END Cart Class /* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ +/* Location: ./system/libraries/Cart.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 74476e1c4371bb7dc8c9727898026687d875284f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 15:03:40 +0300 Subject: Switch private methods and properties to protected and cleanup the Parser library --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 305960f5f..ca7be555e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -134,7 +134,7 @@ class CI_Cart { * @param array * @return bool */ - private function _insert($items = array()) + protected function _insert($items = array()) { // Was any cart data passed? No? Bah... if ( ! is_array($items) OR count($items) === 0) -- cgit v1.2.3-24-g4f1b From 86611db279c17cf9b3d6ad8732a1c840cb833148 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 10:06:25 -0400 Subject: Fixed Cart, Migration, Parser and Zip libraries --- system/libraries/Cart.php | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index ca7be555e..eee123584 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -36,19 +36,53 @@ */ class CI_Cart { - // These are the regular expression rules that we use to validate the product ID and product name - public $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods - public $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods - public $product_name_safe = TRUE; // only allow safe product names + /** + * These are the regular expression rules that we use to validate the product ID and product name + * alpha-numeric, dashes, underscores, or periods + * + * @var string + */ + public $product_id_rules = '\.a-z0-9_-'; + + /** + * These are the regular expression rules that we use to validate the product ID and product name + * alpha-numeric, dashes, underscores, colons or periods + * + * @var string + */ + public $product_name_rules = '\.\:\-_ a-z0-9'; + + /** + * only allow safe product names + * + * @var bool + */ + public $product_name_safe = TRUE; + // -------------------------------------------------------------------------- // Protected variables. Do not change! + // -------------------------------------------------------------------------- + + /** + * Reference to CodeIgniter instance + * + * @var object + */ protected $CI; + + /** + * Contents of the cart + * + * @var array + */ protected $_cart_contents = array(); /** * Shopping Class Constructor * * The constructor loads the Session class, used to store the shopping cart contents. + * + * @param array */ public function __construct($params = array()) { @@ -245,7 +279,6 @@ class CI_Cart { * product ID and quantity for each item. * * @param array - * @param string * @return bool */ public function update($items = array()) @@ -396,6 +429,7 @@ class CI_Cart { * * Removes an item from the cart * + * @param int * @return bool */ public function remove($rowid) @@ -427,6 +461,7 @@ class CI_Cart { * * Returns the entire cart array * + * @param bool * @return array */ public function contents($newest_first = FALSE) @@ -449,6 +484,7 @@ class CI_Cart { * Returns TRUE if the rowid passed to this function correlates to an item * that has options associated with it. * + * @param mixed * @return bool */ public function has_options($rowid = '') -- cgit v1.2.3-24-g4f1b From f074dff71f136860102a6042dccd3ff6db02d9f4 Mon Sep 17 00:00:00 2001 From: ThallisPHP Date: Thu, 3 May 2012 16:01:46 -0300 Subject: Update system/libraries/Cart.php - To enable integrity when using associative arrays --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index eee123584..9f258beb3 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -244,7 +244,7 @@ class CI_Cart { // This becomes the unique "row ID" if (isset($items['options']) && count($items['options']) > 0) { - $rowid = md5($items['id'].implode('', $items['options'])); + $rowid = md5($items['id'].serialize($items['options'])); } else { -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Cart.php | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index eee123584..b73ed5128 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -39,11 +39,11 @@ class CI_Cart { /** * These are the regular expression rules that we use to validate the product ID and product name * alpha-numeric, dashes, underscores, or periods - * + * * @var string */ public $product_id_rules = '\.a-z0-9_-'; - + /** * These are the regular expression rules that we use to validate the product ID and product name * alpha-numeric, dashes, underscores, colons or periods @@ -51,7 +51,7 @@ class CI_Cart { * @var string */ public $product_name_rules = '\.\:\-_ a-z0-9'; - + /** * only allow safe product names * @@ -62,14 +62,14 @@ class CI_Cart { // -------------------------------------------------------------------------- // Protected variables. Do not change! // -------------------------------------------------------------------------- - + /** * Reference to CodeIgniter instance * * @var object */ protected $CI; - + /** * Contents of the cart * @@ -83,6 +83,7 @@ class CI_Cart { * The constructor loads the Session class, used to store the shopping cart contents. * * @param array + * @return void */ public function __construct($params = array()) { @@ -180,7 +181,7 @@ class CI_Cart { // -------------------------------------------------------------------- // 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'])) + if ( ! isset($items['id'], $items['qty'], $items['price'], $items['name'])) { log_message('error', 'The cart array must contain a product ID, quantity, price, and name.'); return FALSE; @@ -341,7 +342,7 @@ class CI_Cart { protected function _update($items = array()) { // Without these array indexes there is nothing we can do - if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']])) + if ( ! isset($items['qty'], $items['rowid'], $this->_cart_contents[$items['rowid']])) { return FALSE; } @@ -383,7 +384,7 @@ class CI_Cart { foreach ($this->_cart_contents as $key => $val) { // We make sure the array contains the proper indexes - if ( ! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty'])) + if ( ! is_array($val) OR ! isset($val['price'], $val['qty'])) { continue; } @@ -393,7 +394,7 @@ class CI_Cart { $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); } - // 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'); @@ -489,7 +490,7 @@ class CI_Cart { */ public function has_options($rowid = '') { - return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0) ? TRUE : FALSE; + return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0); } // -------------------------------------------------------------------- @@ -519,15 +520,7 @@ class CI_Cart { */ public function format_number($n = '') { - if ($n == '') - { - return ''; - } - - // Remove anything that isn't a number or decimal point. - $n = (float) $n; - - return number_format($n, 2, '.', ','); + return ($n == '') ? '' : number_format( (float) $n, 2, '.', ','); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Cart.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 827050310..87b1877c3 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -193,7 +193,7 @@ class CI_Cart { $items['qty'] = (float) $items['qty']; // If the quantity is zero or blank there's nothing for us to do - if ( ! is_numeric($items['qty']) OR $items['qty'] == 0) + if ( ! is_numeric($items['qty']) OR $items['qty'] === 0) { return FALSE; } @@ -358,7 +358,7 @@ class CI_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) + if ($items['qty'] === 0) { unset($this->_cart_contents[$items['rowid']]); } @@ -520,7 +520,7 @@ class CI_Cart { */ public function format_number($n = '') { - return ($n == '') ? '' : number_format( (float) $n, 2, '.', ','); + return ($n === '') ? '' : number_format( (float) $n, 2, '.', ','); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5036c9caabb12f90b9533d7fb417610e02a652ff Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 15:34:56 +0300 Subject: Revert/optimize some changes from 773ccc318f2769c9b7579630569b5d8ba47b114b and d261b1e89c3d4d5191036d5a5660ef6764e593a0 --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 87b1877c3..c442f88da 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -193,7 +193,7 @@ class CI_Cart { $items['qty'] = (float) $items['qty']; // If the quantity is zero or blank there's nothing for us to do - if ( ! is_numeric($items['qty']) OR $items['qty'] === 0) + if ( ! is_numeric($items['qty']) OR $items['qty'] == 0) { return FALSE; } @@ -358,7 +358,7 @@ class CI_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) + if ($items['qty'] == 0) { unset($this->_cart_contents[$items['rowid']]); } -- cgit v1.2.3-24-g4f1b From cdeee661db2438cc65304f704ab4bcebeccb9b7d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 25 Oct 2012 17:29:52 +0300 Subject: Add CI_Cart::get_item() (rel #400) --- system/libraries/Cart.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index c442f88da..d4b17fa36 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -479,18 +479,35 @@ class CI_Cart { // -------------------------------------------------------------------- + /** + * Get cart item + * + * Returns the details of a specific item in the cart + * + * @param string $row_id + * @return array + */ + public function get_item($row_id) + { + return (in_array($row_id, array('total_items', 'cart_total'), TRUE) OR ! isset($this->_cart_contents[$row_id])) + ? FALSE + : $this->_cart_contents[$row_id]; + } + + // -------------------------------------------------------------------- + /** * Has options * * Returns TRUE if the rowid passed to this function correlates to an item * that has options associated with it. * - * @param mixed + * @param string $row_id = '' * @return bool */ - public function has_options($rowid = '') + public function has_options($row_id = '') { - return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0); + return (isset($this->_cart_contents[$row_id]['options']) && count($this->_cart_contents[$row_id]['options']) !== 0); } // -------------------------------------------------------------------- @@ -500,12 +517,12 @@ class CI_Cart { * * Returns the an array of options, for a particular product row ID * - * @param int + * @param string $row_id = '' * @return array */ - public function product_options($rowid = '') + public function product_options($row_id = '') { - return isset($this->_cart_contents[$rowid]['options']) ? $this->_cart_contents[$rowid]['options'] : array(); + return isset($this->_cart_contents[$row_id]['options']) ? $this->_cart_contents[$row_id]['options'] : array(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1a9b7e0d1f96b3cee5692f582d860dca4978dee5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 16:23:47 +0200 Subject: Remove is_numeric() checks from Cart library (superseded by casts to float) --- system/libraries/Cart.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index d4b17fa36..6cc7ee230 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -193,7 +193,7 @@ class CI_Cart { $items['qty'] = (float) $items['qty']; // If the quantity is zero or blank there's nothing for us to do - if ( ! is_numeric($items['qty']) OR $items['qty'] == 0) + if ($items['qty'] == 0) { return FALSE; } @@ -224,15 +224,6 @@ class CI_Cart { // Prep the price. Remove leading zeros and anything that isn't a number or decimal point. $items['price'] = (float) $items['price']; - // Is the price a valid number? - if ( ! is_numeric($items['price'])) - { - log_message('error', 'An invalid price was submitted for product ID: '.$items['id']); - return FALSE; - } - - // -------------------------------------------------------------------- - // We now need to create a unique identifier for the item being inserted into the cart. // Every time something is added to the cart it is stored in the master cart array. // Each row in the cart array, however, must have a unique index that identifies not only @@ -350,12 +341,6 @@ class CI_Cart { // Prep the quantity $items['qty'] = (float) $items['qty']; - // Is the quantity a number? - if ( ! is_numeric($items['qty'])) - { - return FALSE; - } - // 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) -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Cart.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 6cc7ee230..035a6a42b 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,4 +1,4 @@ - Date: Fri, 23 Nov 2012 13:54:28 +0200 Subject: 3.0.0-dev: Fixing the issue #2023. CI_Cart initialization: Session data presense should be tested against NULL, not FALSE. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 035a6a42b..79c2b8cdc 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -99,7 +99,7 @@ class CI_Cart { // Grab the shopping cart array from the session table $this->_cart_contents = $this->CI->session->userdata('cart_contents'); - if ($this->_cart_contents === FALSE) + if ($this->_cart_contents === NULL) { // No cart exists so we'll set some base values $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 79c2b8cdc..8734d7774 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From edc9afa09b01f67089f121ed7054fe3a5a3b8ec2 Mon Sep 17 00:00:00 2001 From: Edwin Aw Date: Fri, 25 Jan 2013 16:12:20 +0800 Subject: Fix issue #2191. Signed-off-by: Edwin Aw --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 8734d7774..d64f6f042 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -95,7 +95,7 @@ class CI_Cart { $config = is_array($params) ? $params : array(); // Load the Sessions class - $this->CI->load->library('session', $config); + $this->CI->load->driver('session', $config); // Grab the shopping cart array from the session table $this->_cart_contents = $this->CI->session->userdata('cart_contents'); -- cgit v1.2.3-24-g4f1b From 3567246091195e035ea4c8d3b2915eb6b45ad5e2 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Fri, 15 Feb 2013 01:36:04 +0100 Subject: Various cosmetic fixes --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index d64f6f042..b7b0697fb 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -365,7 +365,7 @@ class CI_Cart { */ protected function _save_cart() { - // Lets add up the individual prices and set the cart sub-total + // Let's add up the individual prices and set the cart sub-total $this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0; foreach ($this->_cart_contents as $key => $val) { -- cgit v1.2.3-24-g4f1b From 2d33e22c0af65963d7617374427814846f419a2e Mon Sep 17 00:00:00 2001 From: Louis Racicot Date: Tue, 5 Mar 2013 15:29:51 -0500 Subject: Add unicode support in cart product name for unicode 00C000 to 00E01F. --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index b7b0697fb..86c11d6f6 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -51,7 +51,7 @@ class CI_Cart { * * @var string */ - public $product_name_rules = '\.\:\-_ a-z0-9'; + public $product_name_rules = '\.\:\-_ a-zA-ZÀ-ÿ0-9'; /** * only allow safe product names @@ -544,4 +544,4 @@ class CI_Cart { } /* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ \ No newline at end of file +/* Location: ./system/libraries/Cart.php */ -- cgit v1.2.3-24-g4f1b From 141e2cb8a20e84a4e521c47edd885102185b2419 Mon Sep 17 00:00:00 2001 From: Louis Racicot Date: Wed, 6 Mar 2013 09:29:45 -0500 Subject: Update Cart.php Regex were already case sensitive. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 86c11d6f6..84be7fa85 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -51,7 +51,7 @@ class CI_Cart { * * @var string */ - public $product_name_rules = '\.\:\-_ a-zA-ZÀ-ÿ0-9'; + public $product_name_rules = '\.\:\-_ a-z�-�0-9'; /** * only allow safe product names -- cgit v1.2.3-24-g4f1b From 837b203bcbd52fc8fc909a3dc8c5031fb4dc3379 Mon Sep 17 00:00:00 2001 From: Louis Racicot Date: Wed, 6 Mar 2013 09:31:31 -0500 Subject: Github broke the file encoding. I repaired it. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 84be7fa85..d5664f22c 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -51,7 +51,7 @@ class CI_Cart { * * @var string */ - public $product_name_rules = '\.\:\-_ a-z�-�0-9'; + public $product_name_rules = '\.\:\-_ a-zÀ-ÿ0-9'; /** * only allow safe product names -- cgit v1.2.3-24-g4f1b From 592e7d46895029f462369708085631d67494ec56 Mon Sep 17 00:00:00 2001 From: Louis Racicot Date: Wed, 6 Mar 2013 10:04:55 -0500 Subject: Full unicode support for the product name. --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index d5664f22c..c224a6dc9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -51,7 +51,7 @@ class CI_Cart { * * @var string */ - public $product_name_rules = '\.\:\-_ a-zÀ-ÿ0-9'; + public $product_name_rules = '\.\:\- \w'; /** * only allow safe product names @@ -214,7 +214,7 @@ class CI_Cart { // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. // Note: These can be user-specified by setting the $this->product_name_rules variable. - if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/i', $items['name'])) + if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/iu', $items['name'])) { log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); return FALSE; -- cgit v1.2.3-24-g4f1b From 025b6465c4baa7ba501b24df64672fd15f779a1a Mon Sep 17 00:00:00 2001 From: Louis Racicot Date: Thu, 7 Mar 2013 09:32:16 -0500 Subject: check if uft8 is enabled --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index c224a6dc9..6e203a8c7 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -214,7 +214,7 @@ class CI_Cart { // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. // Note: These can be user-specified by setting the $this->product_name_rules variable. - if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/iu', $items['name'])) + if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/i'.(UTF8_ENABLED ? 'u' : ''), $items['name'])) { log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); return FALSE; -- cgit v1.2.3-24-g4f1b From 65b8f835e572cc6ff73fe07024ffaa537fee912e Mon Sep 17 00:00:00 2001 From: Louis Racicot Date: Mon, 11 Mar 2013 09:03:25 -0400 Subject: reorder rules in product name regex by importance --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 6e203a8c7..edc300bd7 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -51,7 +51,7 @@ class CI_Cart { * * @var string */ - public $product_name_rules = '\.\:\- \w'; + public $product_name_rules = '\w \-\.\:'; /** * only allow safe product names @@ -544,4 +544,4 @@ class CI_Cart { } /* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ +/* Location: ./system/libraries/Cart.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index edc300bd7..5a31a1d45 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From f69f1822558645aa00944b436558fb6948f42aa9 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 11 Feb 2014 22:55:47 +0200 Subject: Allow updating all properties for an item. --- system/libraries/Cart.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 5a31a1d45..b00ccd862 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -350,7 +350,11 @@ class CI_Cart { } else { - $this->_cart_contents[$items['rowid']]['qty'] = $items['qty']; + // find updatable keys + $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); + foreach ( $keys as $key ) { + $this->_cart_contents[$items['rowid']][$key] = $items[$key]; + } } return TRUE; -- cgit v1.2.3-24-g4f1b From 7d16de620a46f84ffeb52a54ae82439a06f89c74 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 01:45:27 +0200 Subject: Fixed code style & added few extra checks. Updated cart documentation. --- system/libraries/Cart.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index b00ccd862..f5e85b715 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -323,10 +323,10 @@ class CI_Cart { /** * Update the cart * - * This function permits the quantity of a given item to be changed. + * This function permits changing item properties. * Typically it is called from the "view cart" page if a user makes * changes to the quantity before checkout. That array must contain the - * product ID and quantity for each item. + * rowid and qty for each item. * * @param array * @return bool @@ -352,7 +352,18 @@ class CI_Cart { { // find updatable keys $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); - foreach ( $keys as $key ) { + // if a price was passed, make sure it contains valid data + if (isset($keys['price'])) + { + $keys['price'] = (float) $keys['price']; + } + + // product name & id shouldn't be changed + unset($keys['name']); + unset($keys['id']); + + foreach ($keys as $key) + { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; } } -- cgit v1.2.3-24-g4f1b From 11db7a7da940a6ab0168a70b71194f078cdf953d Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 02:40:45 +0200 Subject: Delete by values, not keys --- system/libraries/Cart.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index f5e85b715..8a2516f1c 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -353,14 +353,13 @@ class CI_Cart { // find updatable keys $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); // if a price was passed, make sure it contains valid data - if (isset($keys['price'])) + if (isset($items['price'])) { - $keys['price'] = (float) $keys['price']; + $items['price'] = (float) $items['price']; } // product name & id shouldn't be changed - unset($keys['name']); - unset($keys['id']); + $keys = array_diff($keys, array('id', 'name')); foreach ($keys as $key) { -- cgit v1.2.3-24-g4f1b From 576439fda03d4e81cb5b0cfed371f7776a73fe3a Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 06:16:31 +0200 Subject: Added changelog entry. An example to the docs. Tidy code a little bit. --- system/libraries/Cart.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 8a2516f1c..ec67d9b4a 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -358,10 +358,8 @@ class CI_Cart { $items['price'] = (float) $items['price']; } - // product name & id shouldn't be changed - $keys = array_diff($keys, array('id', 'name')); - - foreach ($keys as $key) + // product id & name shouldn't be changed + foreach (array_diff($keys, array('id', 'name')) as $key) { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; } -- cgit v1.2.3-24-g4f1b From da2bdf2b95a55f03aadfb6a1d21a90a0fff627db Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 12:59:18 +0200 Subject: Re-arranged documentation, fixed comment. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index ec67d9b4a..389b1b77e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -326,7 +326,7 @@ class CI_Cart { * This function permits changing item properties. * Typically it is called from the "view cart" page if a user makes * changes to the quantity before checkout. That array must contain the - * rowid and qty for each item. + * rowid and quantity for each item. * * @param array * @return bool -- cgit v1.2.3-24-g4f1b From 0bd390c660290b7dc478955da6a8a7fbb3ca9fd6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 14:26:50 +0200 Subject: [ci skip] Polish changes from #2874 --- system/libraries/Cart.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 389b1b77e..5b05974e4 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -60,8 +60,6 @@ class CI_Cart { */ public $product_name_safe = TRUE; - // -------------------------------------------------------------------------- - // Protected variables. Do not change! // -------------------------------------------------------------------------- /** @@ -357,9 +355,9 @@ class CI_Cart { { $items['price'] = (float) $items['price']; } - - // product id & name shouldn't be changed - foreach (array_diff($keys, array('id', 'name')) as $key) + + // product id & name shouldn't be changed + foreach (array_diff($keys, array('id', 'name')) as $key) { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; } -- cgit v1.2.3-24-g4f1b From 4321cb0912ad24d78b851a9f39c688cab0341c96 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Fri, 14 Mar 2014 15:21:13 +0200 Subject: Removed the requirment of quantity to trigger cart update. --- system/libraries/Cart.php | 49 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 5b05974e4..6cc1509b6 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -282,10 +282,10 @@ 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 - // determine the array type is by looking for a required array key named "id". + // determine the array type is by looking for a required array key named "rowid". // If it's not found we assume it's a multi-dimensional array $save_cart = FALSE; - if (isset($items['rowid'], $items['qty'])) + if (isset($items['rowid'])) { if ($this->_update($items) === TRUE) { @@ -296,7 +296,7 @@ class CI_Cart { { foreach ($items as $val) { - if (is_array($val) && isset($val['rowid'], $val['qty'])) + if (is_array($val) && isset($val['rowid'])) { if ($this->_update($val) === TRUE) { @@ -332,37 +332,38 @@ class CI_Cart { protected function _update($items = array()) { // Without these array indexes there is nothing we can do - if ( ! isset($items['qty'], $items['rowid'], $this->_cart_contents[$items['rowid']])) + if ( ! isset($items['rowid'], $this->_cart_contents[$items['rowid']])) { return FALSE; } // Prep the quantity - $items['qty'] = (float) $items['qty']; - - // 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) - { - unset($this->_cart_contents[$items['rowid']]); - } - else + if ( isset($items['qty']) ) { - // find updatable keys - $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); - // if a price was passed, make sure it contains valid data - if (isset($items['price'])) + $items['qty'] = (float) $items['qty']; + // 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) { - $items['price'] = (float) $items['price']; - } - - // product id & name shouldn't be changed - foreach (array_diff($keys, array('id', 'name')) as $key) - { - $this->_cart_contents[$items['rowid']][$key] = $items[$key]; + unset($this->_cart_contents[$items['rowid']]); + return TRUE } + } + + // find updatable keys + $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); + // if a price was passed, make sure it contains valid data + if (isset($items['price'])) + { + $items['price'] = (float) $items['price']; } + // product id & name shouldn't be changed + foreach (array_diff($keys, array('id', 'name')) as $key) + { + $this->_cart_contents[$items['rowid']][$key] = $items[$key]; + } + return TRUE; } -- cgit v1.2.3-24-g4f1b From 9af0746825a1af1c463462c10bdff70f58ded72a Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Fri, 14 Mar 2014 15:33:18 +0200 Subject: Added missing semicolon --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 6cc1509b6..9c9a285cd 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -346,7 +346,7 @@ class CI_Cart { if ($items['qty'] == 0) { unset($this->_cart_contents[$items['rowid']]); - return TRUE + return TRUE; } } -- cgit v1.2.3-24-g4f1b From 2702a3b647785c06bf21ba0b6b36cacef2f8ee1f Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Fri, 14 Mar 2014 16:53:44 +0200 Subject: Fixed coding style & line length. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 9c9a285cd..cd46a6ef6 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -338,7 +338,7 @@ class CI_Cart { } // Prep the quantity - if ( isset($items['qty']) ) + if (isset($items['qty'])) { $items['qty'] = (float) $items['qty']; // Is the quantity zero? If so we will remove the item from the cart. -- cgit v1.2.3-24-g4f1b From db3e49d2a932eca5910b0fc89c87d28c1d6b7bb1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 17 Mar 2014 11:04:55 +0200 Subject: [ci skip] Clear some whitespace --- system/libraries/Cart.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index cd46a6ef6..4441db4dd 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -348,8 +348,8 @@ class CI_Cart { unset($this->_cart_contents[$items['rowid']]); return TRUE; } - } - + } + // find updatable keys $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); // if a price was passed, make sure it contains valid data @@ -362,7 +362,7 @@ class CI_Cart { foreach (array_diff($keys, array('id', 'name')) as $key) { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; - } + } return TRUE; } -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/libraries/Cart.php | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 4441db4dd..14f08a8c3 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is - * also available through the world wide web at this URL: - * http://opensource.org/licenses/OSL-3.0 - * If you did not receive a copy of the license and are unable to obtain it - * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 1.0 + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 1.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From 694d400efb077666955672c2e8c22e4d1b3a3a06 Mon Sep 17 00:00:00 2001 From: James L Parry Date: Wed, 3 Dec 2014 20:53:40 -0800 Subject: Flag the smiley helper and shopping cart as deprecated. They should be removed the next minor release. Lowered the "javascript" deprecation message to "important" instead of "warning", for consistency with the rest of CI. Signed-off-by:James L Parry --- system/libraries/Cart.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 14f08a8c3..686d563b0 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -45,6 +45,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @category Shopping Cart * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/cart.html + * @deprecated 3.0.0 This class does not fit CI */ class CI_Cart { -- cgit v1.2.3-24-g4f1b From 21c3c22320a10d32054b251b24e5b1e569ddeabf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Dec 2014 12:10:00 +0200 Subject: [ci skip] Update on the changes from PR #3388 - Fixed a broken link - Added missing notes about deprecations in the upgrade instructions - Improved consistency with other deprecation notices in the docs --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 686d563b0..72ef5e8b5 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -45,7 +45,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @category Shopping Cart * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/cart.html - * @deprecated 3.0.0 This class does not fit CI + * @deprecated 3.0.0 This class is too specific for CI. */ class CI_Cart { -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/libraries/Cart.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 72ef5e8b5..a0fe1053d 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 @@ -55,7 +55,7 @@ class CI_Cart { * * @var string */ - public $product_id_rules = '\.a-z0-9_-'; + public $product_id_rules = '\.a-z0-9_-'; /** * These are the regular expression rules that we use to validate the product ID and product name @@ -63,14 +63,14 @@ class CI_Cart { * * @var string */ - public $product_name_rules = '\w \-\.\:'; + public $product_name_rules = '\w \-\.\:'; /** * only allow safe product names * * @var bool */ - public $product_name_safe = TRUE; + public $product_name_safe = TRUE; // -------------------------------------------------------------------------- @@ -86,7 +86,7 @@ class CI_Cart { * * @var array */ - protected $_cart_contents = array(); + protected $_cart_contents = array(); /** * Shopping Class Constructor -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index a0fe1053d..2fffd9a76 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -115,7 +115,7 @@ class CI_Cart { $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); } - log_message('debug', 'Cart Class Initialized'); + log_message('info', 'Cart Class Initialized'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/libraries/Cart.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 2fffd9a76..bf27c6392 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -565,6 +565,3 @@ class CI_Cart { } } - -/* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index bf27c6392..0be2a585b 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 0be2a585b..af527da9e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 1.0.0 * @filesource */ @@ -44,7 +44,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Shopping Cart * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/libraries/cart.html + * @link https://codeigniter.com/user_guide/libraries/cart.html * @deprecated 3.0.0 This class is too specific for CI. */ class CI_Cart { -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index af527da9e..44d87e0bf 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From 0642faa79669826603502239b8fc092d0f1a437a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Jan 2017 12:31:41 +0200 Subject: [ci skip] Update year number in remaining files that were recently deleted from develop --- system/libraries/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cart.php') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 44d87e0bf..734c43420 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b