summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cart.php
diff options
context:
space:
mode:
authorGreg Aker <greg@gregaker.net>2011-08-20 18:58:58 +0200
committerGreg Aker <greg@gregaker.net>2011-08-20 18:58:58 +0200
commitabbad9ea53e81c6e3211029711ac5b2ab4f1978d (patch)
tree9a4d5a8587da1dd3a365251afa37be2f835a53c2 /system/libraries/Cart.php
parent71644d683d0a15a6f7e04fabd0f51a4200d620b4 (diff)
parentd56be70257696d0bbf2dcc880888d8dc17cba21c (diff)
Merge branch 'develop' into feature/unit-tests
Conflicts: .hgignore
Diffstat (limited to 'system/libraries/Cart.php')
-rw-r--r--system/libraries/Cart.php34
1 files changed, 18 insertions, 16 deletions
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index fbccfb3d9..ab5a70c98 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -30,7 +30,7 @@ class CI_Cart {
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
- // Private variables. Do not change!
+ // Private variables. Do not change!
var $CI;
var $_cart_contents = array();
@@ -45,7 +45,7 @@ class CI_Cart {
// Set the super object to a local variable for use later
$this->CI =& get_instance();
- // Are any config settings being passed manually? If so, set them
+ // Are any config settings being passed manually? If so, set them
$config = array();
if (count($params) > 0)
{
@@ -99,7 +99,7 @@ class CI_Cart {
$save_cart = FALSE;
if (isset($items['id']))
{
- if ($this->_insert($items) == TRUE)
+ if (($rowid = $this->_insert($items)))
{
$save_cart = TRUE;
}
@@ -110,7 +110,7 @@ class CI_Cart {
{
if (is_array($val) AND isset($val['id']))
{
- if ($this->_insert($val) == TRUE)
+ if ($this->_insert($val))
{
$save_cart = TRUE;
}
@@ -122,7 +122,7 @@ class CI_Cart {
if ($save_cart == TRUE)
{
$this->_save_cart();
- return TRUE;
+ return isset($rowid) ? $rowid : TRUE;
}
return FALSE;
@@ -148,7 +148,7 @@ class CI_Cart {
// --------------------------------------------------------------------
- // Does the $items array contain an id, quantity, price, and name? These are required
+ // Does the $items array contain an id, quantity, price, and name? These are required
if ( ! isset($items['id']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($items['name']))
{
log_message('error', 'The cart array must contain a product ID, quantity, price, and name.');
@@ -157,7 +157,7 @@ class CI_Cart {
// --------------------------------------------------------------------
- // Prep the quantity. It can only be a number. Duh...
+ // Prep the quantity. It can only be a number. Duh...
$items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty']));
// Trim any leading zeros
$items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty']));
@@ -175,7 +175,7 @@ class CI_Cart {
// Note: These can be user-specified by setting the $this->product_id_rules variable.
if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id']))
{
- log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores');
+ log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores');
return FALSE;
}
@@ -191,7 +191,7 @@ class CI_Cart {
// --------------------------------------------------------------------
- // Prep the price. Remove anything that isn't a number or decimal point.
+ // Prep the price. Remove anything that isn't a number or decimal point.
$items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price']));
// Trim any leading zeros
$items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price']));
@@ -210,7 +210,7 @@ class CI_Cart {
// Each row in the cart array, however, must have a unique index that identifies not only
// a particular product, but makes it possible to store identical products with different options.
// For example, what if someone buys two identical t-shirts (same product ID), but in
- // different sizes? The product ID (and other attributes, like the name) will be identical for
+ // different sizes? The product ID (and other attributes, like the name) will be identical for
// both sizes because it's the same shirt. The only difference will be the size.
// Internally, we need to treat identical submissions, but with different options, as a unique product.
// Our solution is to convert the options array to a string and MD5 it along with the product ID.
@@ -244,7 +244,7 @@ class CI_Cart {
}
// Woot!
- return TRUE;
+ return $rowid;
}
// --------------------------------------------------------------------
@@ -271,7 +271,7 @@ class CI_Cart {
}
// You can either update a single product using a one-dimensional array,
- // or multiple products using a multi-dimensional one. The way we
+ // or multiple products using a multi-dimensional one. The way we
// determine the array type is by looking for a required array key named "id".
// If it's not found we assume it's a multi-dimensional array
$save_cart = FALSE;
@@ -344,7 +344,7 @@ class CI_Cart {
return FALSE;
}
- // Is the quantity zero? If so we will remove the item from the cart.
+ // Is the quantity zero? If so we will remove the item from the cart.
// If the quantity is greater than zero we are updating
if ($items['qty'] == 0)
{
@@ -374,6 +374,7 @@ class CI_Cart {
// Lets add up the individual prices and set the cart sub-total
$total = 0;
+ $items = 0;
foreach ($this->_cart_contents as $key => $val)
{
// We make sure the array contains the proper indexes
@@ -383,16 +384,17 @@ class CI_Cart {
}
$total += ($val['price'] * $val['qty']);
+ $items += $val['qty'];
// Set the subtotal
$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
}
// Set the cart total and total items.
- $this->_cart_contents['total_items'] = count($this->_cart_contents);
+ $this->_cart_contents['total_items'] = $items;
$this->_cart_contents['cart_total'] = $total;
- // Is our cart empty? If so we delete it from the session
+ // 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');