summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cart.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-05-17 13:32:19 +0200
committerAndrey Andreev <narf@bofh.bg>2012-05-17 13:32:19 +0200
commit5645479c622eb36cf9869797896dc0921568c4a9 (patch)
tree7a1d0c2d4cb38f440fcc7ff1204d527ed96477cc /system/libraries/Cart.php
parent92ebfb65ac044f5c2e6d88fba137253854cf1b94 (diff)
Clean up the libraries
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, '.', ',');
}
// --------------------------------------------------------------------