blob: a0e1bb91e3d60063ff50a5f86b172df4d91a43c1 [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Rick Ellis98783322009-02-17 02:29:44 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Rick Ellis98783322009-02-17 02:29:44 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Rick Ellis98783322009-02-17 02:29:44 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Rick Ellis98783322009-02-17 02:29:44 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Shopping Cart Class
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category Shopping Cart
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Rick Ellis98783322009-02-17 02:29:44 +000037 * @link http://codeigniter.com/user_guide/libraries/cart.html
38 */
39class CI_Cart {
40
41 // These are the regular expression rules that we use to validate the product ID and product name
42 var $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods
43 var $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods
Barry Mienydd671972010-10-04 16:33:58 +020044
Derek Jones37f4b9c2011-07-01 17:56:50 -050045 // Private variables. Do not change!
Rick Ellis98783322009-02-17 02:29:44 +000046 var $CI;
Rick Ellisdf39d512009-02-24 22:29:37 +000047 var $_cart_contents = array();
Rick Ellis98783322009-02-17 02:29:44 +000048
49
50 /**
51 * Shopping Class Constructor
52 *
53 * The constructor loads the Session class, used to store the shopping cart contents.
Barry Mienydd671972010-10-04 16:33:58 +020054 */
Greg Akera9263282010-11-10 15:26:43 -060055 public function __construct($params = array())
Barry Mienydd671972010-10-04 16:33:58 +020056 {
Rick Ellis98783322009-02-17 02:29:44 +000057 // Set the super object to a local variable for use later
58 $this->CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +020059
Derek Jones37f4b9c2011-07-01 17:56:50 -050060 // Are any config settings being passed manually? If so, set them
Rick Ellis98783322009-02-17 02:29:44 +000061 $config = array();
62 if (count($params) > 0)
63 {
64 foreach ($params as $key => $val)
65 {
66 $config[$key] = $val;
67 }
68 }
Barry Mienydd671972010-10-04 16:33:58 +020069
Rick Ellis98783322009-02-17 02:29:44 +000070 // Load the Sessions class
71 $this->CI->load->library('session', $config);
Barry Mienydd671972010-10-04 16:33:58 +020072
Rick Ellis98783322009-02-17 02:29:44 +000073 // Grab the shopping cart array from the session table, if it exists
74 if ($this->CI->session->userdata('cart_contents') !== FALSE)
75 {
76 $this->_cart_contents = $this->CI->session->userdata('cart_contents');
77 }
78 else
79 {
80 // No cart exists so we'll set some base values
Barry Mienydd671972010-10-04 16:33:58 +020081 $this->_cart_contents['cart_total'] = 0;
82 $this->_cart_contents['total_items'] = 0;
Rick Ellis98783322009-02-17 02:29:44 +000083 }
Barry Mienydd671972010-10-04 16:33:58 +020084
Rick Ellis98783322009-02-17 02:29:44 +000085 log_message('debug', "Cart Class Initialized");
86 }
87
88 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020089
Rick Ellis98783322009-02-17 02:29:44 +000090 /**
91 * Insert items into the cart and save it to the session table
92 *
93 * @access public
94 * @param array
95 * @return bool
96 */
97 function insert($items = array())
98 {
99 // Was any cart data passed? No? Bah...
100 if ( ! is_array($items) OR count($items) == 0)
101 {
102 log_message('error', 'The insert method must be passed an array containing data.');
103 return FALSE;
104 }
Barry Mienydd671972010-10-04 16:33:58 +0200105
106 // You can either insert a single product using a one-dimensional array,
Rick Ellis98783322009-02-17 02:29:44 +0000107 // or multiple products using a multi-dimensional one. The way we
108 // determine the array type is by looking for a required array key named "id"
109 // at the top level. If it's not found, we will assume it's a multi-dimensional array.
Barry Mienydd671972010-10-04 16:33:58 +0200110
111 $save_cart = FALSE;
Rick Ellis98783322009-02-17 02:29:44 +0000112 if (isset($items['id']))
Barry Mienydd671972010-10-04 16:33:58 +0200113 {
Phil Sturgeon90910512011-07-20 10:07:40 -0600114 if (($rowid = $this->_insert($items)))
Rick Ellis98783322009-02-17 02:29:44 +0000115 {
116 $save_cart = TRUE;
117 }
118 }
119 else
120 {
121 foreach ($items as $val)
122 {
123 if (is_array($val) AND isset($val['id']))
124 {
Phil Sturgeon90910512011-07-20 10:07:40 -0600125 if ($this->_insert($val))
Rick Ellis98783322009-02-17 02:29:44 +0000126 {
127 $save_cart = TRUE;
128 }
Barry Mienydd671972010-10-04 16:33:58 +0200129 }
Rick Ellis98783322009-02-17 02:29:44 +0000130 }
131 }
132
133 // Save the cart data if the insert was successful
134 if ($save_cart == TRUE)
135 {
136 $this->_save_cart();
Phil Sturgeon90910512011-07-20 10:07:40 -0600137 return isset($rowid) ? $rowid : TRUE;
Rick Ellis98783322009-02-17 02:29:44 +0000138 }
139
140 return FALSE;
141 }
142
143 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200144
Rick Ellis98783322009-02-17 02:29:44 +0000145 /**
146 * Insert
147 *
148 * @access private
149 * @param array
150 * @return bool
151 */
152 function _insert($items = array())
153 {
154 // Was any cart data passed? No? Bah...
155 if ( ! is_array($items) OR count($items) == 0)
156 {
157 log_message('error', 'The insert method must be passed an array containing data.');
158 return FALSE;
159 }
Barry Mienydd671972010-10-04 16:33:58 +0200160
Rick Ellis98783322009-02-17 02:29:44 +0000161 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200162
Derek Jones37f4b9c2011-07-01 17:56:50 -0500163 // Does the $items array contain an id, quantity, price, and name? These are required
Rick Ellis98783322009-02-17 02:29:44 +0000164 if ( ! isset($items['id']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($items['name']))
165 {
166 log_message('error', 'The cart array must contain a product ID, quantity, price, and name.');
167 return FALSE;
168 }
169
170 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200171
Derek Jones37f4b9c2011-07-01 17:56:50 -0500172 // Prep the quantity. It can only be a number. Duh...
Rick Ellis98783322009-02-17 02:29:44 +0000173 $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty']));
174 // Trim any leading zeros
175 $items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty']));
176
177 // If the quantity is zero or blank there's nothing for us to do
178 if ( ! is_numeric($items['qty']) OR $items['qty'] == 0)
179 {
180 return FALSE;
181 }
Barry Mienydd671972010-10-04 16:33:58 +0200182
Rick Ellis98783322009-02-17 02:29:44 +0000183 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200184
Rick Ellis98783322009-02-17 02:29:44 +0000185 // Validate the product ID. It can only be alpha-numeric, dashes, underscores or periods
186 // Not totally sure we should impose this rule, but it seems prudent to standardize IDs.
187 // Note: These can be user-specified by setting the $this->product_id_rules variable.
188 if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id']))
189 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500190 log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores');
Rick Ellis98783322009-02-17 02:29:44 +0000191 return FALSE;
192 }
193
194 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200195
Rick Ellis98783322009-02-17 02:29:44 +0000196 // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods.
197 // Note: These can be user-specified by setting the $this->product_name_rules variable.
198 if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name']))
199 {
200 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');
201 return FALSE;
202 }
203
204 // --------------------------------------------------------------------
205
Derek Jones37f4b9c2011-07-01 17:56:50 -0500206 // Prep the price. Remove anything that isn't a number or decimal point.
Rick Ellis98783322009-02-17 02:29:44 +0000207 $items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price']));
208 // Trim any leading zeros
209 $items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price']));
Barry Mienydd671972010-10-04 16:33:58 +0200210
Rick Ellis98783322009-02-17 02:29:44 +0000211 // Is the price a valid number?
212 if ( ! is_numeric($items['price']))
213 {
214 log_message('error', 'An invalid price was submitted for product ID: '.$items['id']);
215 return FALSE;
216 }
217
218 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200219
Rick Ellis98783322009-02-17 02:29:44 +0000220 // We now need to create a unique identifier for the item being inserted into the cart.
Barry Mienydd671972010-10-04 16:33:58 +0200221 // Every time something is added to the cart it is stored in the master cart array.
222 // Each row in the cart array, however, must have a unique index that identifies not only
223 // a particular product, but makes it possible to store identical products with different options.
224 // For example, what if someone buys two identical t-shirts (same product ID), but in
Derek Jones37f4b9c2011-07-01 17:56:50 -0500225 // different sizes? The product ID (and other attributes, like the name) will be identical for
Rick Ellis98783322009-02-17 02:29:44 +0000226 // both sizes because it's the same shirt. The only difference will be the size.
227 // Internally, we need to treat identical submissions, but with different options, as a unique product.
228 // Our solution is to convert the options array to a string and MD5 it along with the product ID.
229 // This becomes the unique "row ID"
230 if (isset($items['options']) AND count($items['options']) > 0)
231 {
232 $rowid = md5($items['id'].implode('', $items['options']));
233 }
234 else
235 {
236 // No options were submitted so we simply MD5 the product ID.
237 // Technically, we don't need to MD5 the ID in this case, but it makes
238 // sense to standardize the format of array indexes for both conditions
239 $rowid = md5($items['id']);
Barry Mienydd671972010-10-04 16:33:58 +0200240 }
Rick Ellis98783322009-02-17 02:29:44 +0000241
242 // --------------------------------------------------------------------
243
244 // Now that we have our unique "row ID", we'll add our cart items to the master array
Barry Mienydd671972010-10-04 16:33:58 +0200245
Rick Ellis98783322009-02-17 02:29:44 +0000246 // let's unset this first, just to make sure our index contains only the data from this submission
Barry Mienydd671972010-10-04 16:33:58 +0200247 unset($this->_cart_contents[$rowid]);
248
Rick Ellis98783322009-02-17 02:29:44 +0000249 // Create a new index with our new row ID
250 $this->_cart_contents[$rowid]['rowid'] = $rowid;
Barry Mienydd671972010-10-04 16:33:58 +0200251
252 // And add the new items to the cart array
Rick Ellis98783322009-02-17 02:29:44 +0000253 foreach ($items as $key => $val)
254 {
255 $this->_cart_contents[$rowid][$key] = $val;
256 }
257
258 // Woot!
Phil Sturgeon90910512011-07-20 10:07:40 -0600259 return $rowid;
Rick Ellis98783322009-02-17 02:29:44 +0000260 }
261
262 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200263
Rick Ellis98783322009-02-17 02:29:44 +0000264 /**
265 * Update the cart
266 *
Barry Mienydd671972010-10-04 16:33:58 +0200267 * This function permits the quantity of a given item to be changed.
Rick Ellis98783322009-02-17 02:29:44 +0000268 * Typically it is called from the "view cart" page if a user makes
269 * changes to the quantity before checkout. That array must contain the
270 * product ID and quantity for each item.
271 *
272 * @access public
273 * @param array
274 * @param string
275 * @return bool
276 */
277 function update($items = array())
278 {
279 // Was any cart data passed?
280 if ( ! is_array($items) OR count($items) == 0)
281 {
282 return FALSE;
283 }
Barry Mienydd671972010-10-04 16:33:58 +0200284
285 // You can either update a single product using a one-dimensional array,
Derek Jones37f4b9c2011-07-01 17:56:50 -0500286 // or multiple products using a multi-dimensional one. The way we
Rick Ellis98783322009-02-17 02:29:44 +0000287 // determine the array type is by looking for a required array key named "id".
288 // If it's not found we assume it's a multi-dimensional array
289 $save_cart = FALSE;
290 if (isset($items['rowid']) AND isset($items['qty']))
291 {
292 if ($this->_update($items) == TRUE)
293 {
294 $save_cart = TRUE;
295 }
296 }
297 else
298 {
299 foreach ($items as $val)
300 {
301 if (is_array($val) AND isset($val['rowid']) AND isset($val['qty']))
302 {
303 if ($this->_update($val) == TRUE)
304 {
305 $save_cart = TRUE;
306 }
Barry Mienydd671972010-10-04 16:33:58 +0200307 }
Rick Ellis98783322009-02-17 02:29:44 +0000308 }
309 }
310
311 // Save the cart data if the insert was successful
312 if ($save_cart == TRUE)
313 {
314 $this->_save_cart();
315 return TRUE;
316 }
317
318 return FALSE;
319 }
320
321 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200322
Rick Ellis98783322009-02-17 02:29:44 +0000323 /**
324 * Update the cart
325 *
Barry Mienydd671972010-10-04 16:33:58 +0200326 * This function permits the quantity of a given item to be changed.
Rick Ellis98783322009-02-17 02:29:44 +0000327 * Typically it is called from the "view cart" page if a user makes
328 * changes to the quantity before checkout. That array must contain the
329 * product ID and quantity for each item.
330 *
331 * @access private
332 * @param array
333 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200334 */
Rick Ellis98783322009-02-17 02:29:44 +0000335 function _update($items = array())
336 {
337 // Without these array indexes there is nothing we can do
338 if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']]))
339 {
340 return FALSE;
341 }
Barry Mienydd671972010-10-04 16:33:58 +0200342
Rick Ellis98783322009-02-17 02:29:44 +0000343 // Prep the quantity
344 $items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']);
345
346 // Is the quantity a number?
347 if ( ! is_numeric($items['qty']))
348 {
349 return FALSE;
350 }
Barry Mienydd671972010-10-04 16:33:58 +0200351
Rick Ellis98783322009-02-17 02:29:44 +0000352 // Is the new quantity different than what is already saved in the cart?
353 // If it's the same there's nothing to do
354 if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty'])
355 {
356 return FALSE;
357 }
358
Derek Jones37f4b9c2011-07-01 17:56:50 -0500359 // Is the quantity zero? If so we will remove the item from the cart.
Rick Ellis98783322009-02-17 02:29:44 +0000360 // If the quantity is greater than zero we are updating
361 if ($items['qty'] == 0)
362 {
Barry Mienydd671972010-10-04 16:33:58 +0200363 unset($this->_cart_contents[$items['rowid']]);
Rick Ellis98783322009-02-17 02:29:44 +0000364 }
365 else
366 {
367 $this->_cart_contents[$items['rowid']]['qty'] = $items['qty'];
368 }
Barry Mienydd671972010-10-04 16:33:58 +0200369
Rick Ellis98783322009-02-17 02:29:44 +0000370 return TRUE;
371 }
372
373 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200374
Rick Ellis98783322009-02-17 02:29:44 +0000375 /**
376 * Save the cart array to the session DB
377 *
378 * @access private
379 * @return bool
380 */
381 function _save_cart()
382 {
Rick Ellisaf4fb222009-02-24 22:44:22 +0000383 // Unset these so our total can be calculated correctly below
384 unset($this->_cart_contents['total_items']);
385 unset($this->_cart_contents['cart_total']);
386
387 // Lets add up the individual prices and set the cart sub-total
Rick Ellis98783322009-02-17 02:29:44 +0000388 $total = 0;
MarcosCoelho98b21262011-07-18 16:12:47 -0300389 $items = 0;
Rick Ellis98783322009-02-17 02:29:44 +0000390 foreach ($this->_cart_contents as $key => $val)
391 {
392 // We make sure the array contains the proper indexes
Rick Ellisaf4fb222009-02-24 22:44:22 +0000393 if ( ! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty']))
Rick Ellis98783322009-02-17 02:29:44 +0000394 {
395 continue;
396 }
397
398 $total += ($val['price'] * $val['qty']);
MarcosCoelho98b21262011-07-18 16:12:47 -0300399 $items += $val['qty'];
Barry Mienydd671972010-10-04 16:33:58 +0200400
Rick Ellis98783322009-02-17 02:29:44 +0000401 // Set the subtotal
Rick Ellisdf39d512009-02-24 22:29:37 +0000402 $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
Rick Ellis98783322009-02-17 02:29:44 +0000403 }
404
Rick Ellis98783322009-02-17 02:29:44 +0000405 // Set the cart total and total items.
MarcosCoelho98b21262011-07-18 16:12:47 -0300406 $this->_cart_contents['total_items'] = $items;
Rick Ellis98783322009-02-17 02:29:44 +0000407 $this->_cart_contents['cart_total'] = $total;
Barry Mienydd671972010-10-04 16:33:58 +0200408
Derek Jones37f4b9c2011-07-01 17:56:50 -0500409 // Is our cart empty? If so we delete it from the session
Rick Ellis98783322009-02-17 02:29:44 +0000410 if (count($this->_cart_contents) <= 2)
411 {
412 $this->CI->session->unset_userdata('cart_contents');
Barry Mienydd671972010-10-04 16:33:58 +0200413
Rick Ellis98783322009-02-17 02:29:44 +0000414 // Nothing more to do... coffee time!
415 return FALSE;
416 }
417
418 // If we made it this far it means that our cart has data.
419 // Let's pass it to the Session class so it can be stored
420 $this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents));
421
422 // Woot!
Barry Mienydd671972010-10-04 16:33:58 +0200423 return TRUE;
Rick Ellis98783322009-02-17 02:29:44 +0000424 }
425
426 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200427
Rick Ellis98783322009-02-17 02:29:44 +0000428 /**
429 * Cart Total
430 *
431 * @access public
432 * @return integer
433 */
434 function total()
435 {
Rick Ellisdf39d512009-02-24 22:29:37 +0000436 return $this->_cart_contents['cart_total'];
Rick Ellis98783322009-02-17 02:29:44 +0000437 }
438
439 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200440
Rick Ellis98783322009-02-17 02:29:44 +0000441 /**
442 * Total Items
443 *
444 * Returns the total item count
445 *
446 * @access public
447 * @return integer
448 */
449 function total_items()
450 {
451 return $this->_cart_contents['total_items'];
452 }
453
454 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200455
Rick Ellis98783322009-02-17 02:29:44 +0000456 /**
457 * Cart Contents
458 *
459 * Returns the entire cart array
460 *
461 * @access public
462 * @return array
463 */
464 function contents()
465 {
466 $cart = $this->_cart_contents;
Barry Mienydd671972010-10-04 16:33:58 +0200467
Rick Ellis98783322009-02-17 02:29:44 +0000468 // Remove these so they don't create a problem when showing the cart table
469 unset($cart['total_items']);
470 unset($cart['cart_total']);
Barry Mienydd671972010-10-04 16:33:58 +0200471
Rick Ellis98783322009-02-17 02:29:44 +0000472 return $cart;
473 }
474
475 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200476
Rick Ellis98783322009-02-17 02:29:44 +0000477 /**
478 * Has options
479 *
480 * Returns TRUE if the rowid passed to this function correlates to an item
481 * that has options associated with it.
482 *
483 * @access public
484 * @return array
485 */
486 function has_options($rowid = '')
487 {
488 if ( ! isset($this->_cart_contents[$rowid]['options']) OR count($this->_cart_contents[$rowid]['options']) === 0)
489 {
490 return FALSE;
491 }
Barry Mienydd671972010-10-04 16:33:58 +0200492
Rick Ellis98783322009-02-17 02:29:44 +0000493 return TRUE;
494 }
495
496 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200497
Rick Ellis98783322009-02-17 02:29:44 +0000498 /**
499 * Product options
500 *
501 * Returns the an array of options, for a particular product row ID
502 *
503 * @access public
504 * @return array
505 */
506 function product_options($rowid = '')
507 {
508 if ( ! isset($this->_cart_contents[$rowid]['options']))
509 {
510 return array();
511 }
512
513 return $this->_cart_contents[$rowid]['options'];
514 }
Rick Ellisdf39d512009-02-24 22:29:37 +0000515
516 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200517
Rick Ellisdf39d512009-02-24 22:29:37 +0000518 /**
519 * Format Number
520 *
521 * Returns the supplied number with commas and a decimal point.
522 *
523 * @access public
524 * @return integer
525 */
526 function format_number($n = '')
527 {
528 if ($n == '')
529 {
530 return '';
531 }
Barry Mienydd671972010-10-04 16:33:58 +0200532
Rick Ellisdf39d512009-02-24 22:29:37 +0000533 // Remove anything that isn't a number or decimal point.
534 $n = trim(preg_replace('/([^0-9\.])/i', '', $n));
Barry Mienydd671972010-10-04 16:33:58 +0200535
Rick Ellisdf39d512009-02-24 22:29:37 +0000536 return number_format($n, 2, '.', ',');
537 }
Barry Mienydd671972010-10-04 16:33:58 +0200538
Rick Ellis98783322009-02-17 02:29:44 +0000539 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200540
Rick Ellis98783322009-02-17 02:29:44 +0000541 /**
542 * Destroy the cart
543 *
544 * Empties the cart and kills the session
545 *
546 * @access public
547 * @return null
548 */
549 function destroy()
550 {
551 unset($this->_cart_contents);
Barry Mienydd671972010-10-04 16:33:58 +0200552
553 $this->_cart_contents['cart_total'] = 0;
554 $this->_cart_contents['total_items'] = 0;
Rick Ellis98783322009-02-17 02:29:44 +0000555
Rick Ellis9c86ce52009-02-17 19:54:14 +0000556 $this->CI->session->unset_userdata('cart_contents');
Rick Ellis98783322009-02-17 02:29:44 +0000557 }
558
559
560}
561// END Cart Class
562
563/* End of file Cart.php */
564/* Location: ./system/libraries/Cart.php */