summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cart.php
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2012-05-17 15:54:35 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2012-05-17 15:54:35 +0200
commit76c5185c6ed8c44cb0f249afd72677627d54ff3c (patch)
treedb10cc2cc30f731ac8625117f08ad8855efdf816 /system/libraries/Cart.php
parent714252bf88306839484579059e3a447dd93d55c1 (diff)
parente30b3f7afafa2c016cf78cc8bb8a457c2dbcda8c (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop
Diffstat (limited to 'system/libraries/Cart.php')
-rw-r--r--system/libraries/Cart.php31
1 files changed, 12 insertions, 19 deletions
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, '.', ',');
}
// --------------------------------------------------------------------