summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/helpers/inflector_helper.php18
-rw-r--r--system/libraries/Cart.php59
2 files changed, 62 insertions, 15 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 513a9c54f..3393bda8f 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -5,9 +5,9 @@
* 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:
@@ -84,7 +84,7 @@ if ( ! function_exists('singular'))
'/(n)ews$/' => '\1\2ews',
'/([^u])s$/' => '\1',
);
-
+
foreach ($singular_rules as $rule => $replacement)
{
if (preg_match($rule, $result))
@@ -115,7 +115,7 @@ if ( ! function_exists('plural'))
function plural($str, $force = FALSE)
{
$result = strval($str);
-
+
$plural_rules = array(
'/^(ox)$/' => '\1\2en', // ox
'/([m|l])ouse$/' => '\1ice', // mouse, louse
@@ -196,20 +196,20 @@ if ( ! function_exists('underscore'))
/**
* Humanize
*
- * Takes multiple words separated by underscores and changes them to spaces
+ * Takes multiple words separated by the separator and changes them to spaces
*
* @access public
- * @param string
+ * @param string $str
+ * @param string $separator
* @return str
*/
if ( ! function_exists('humanize'))
{
- function humanize($str)
+ function humanize($str, $separator = '_')
{
- return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
+ return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str))));
}
}
-
/* End of file inflector_helper.php */
/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index a0e1bb91e..717ccd9fb 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,7 +196,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 ( ! 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;
@@ -242,7 +243,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 +266,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;
}
@@ -435,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;
+ }
+
// --------------------------------------------------------------------
/**
@@ -461,9 +498,19 @@ 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']);