Changeset 354 for trunk/lib/Cart.inc.php
- Timestamp:
- Jun 11, 2009 4:37:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Cart.inc.php
r353 r354 247 247 * Return the sum of the numeric values stored under the specified key for cart items. 248 248 * 0 will be returned if key is invalid or not filled with numeric values. 249 * Most commonly, $cart->sum() will be called when checking out to retrieve the total 250 * cost of the items in the cart. 249 251 * 250 252 * @access public … … 257 259 function sum($key='extended_price') 258 260 { 261 $sum = 0; 259 262 switch ($key) { 260 263 case 'items' : 261 return sizeof($_SESSION['_cart'][$this->_ns]['items']); 262 263 case 'extended_price' : 264 $sum = 0; 264 $sum = sizeof($_SESSION['_cart'][$this->_ns]['items']); 265 266 case 'extended_price' : 265 267 foreach ($_SESSION['_cart'][$this->_ns]['items'] as $item_id => $specs) { 266 268 $sum += isset($specs[$key]) && is_numeric($specs[$key]) ? $specs[$key] : 0; 267 269 } 268 return $sum; 270 269 271 default : 270 $sum = 0;272 // Retreive arbitrary values stored in the cart (shipping, air miles, etc). 271 273 foreach ($_SESSION['_cart'][$this->_ns]['items'] as $item_id => $specs) { 272 274 $sum += isset($specs[$key]) && is_numeric($specs[$key]) ? $specs[$key] * $specs['quantity'] : 0; 273 275 } 274 return $sum; 275 } 276 if (!isset($specs[$key])) { 277 $app->logMsg(sprintf('Could not sum up nonexistent value: %s', $key), LOG_ERR, __FILE__, __LINE__); 278 } 279 } 280 return $sum; 276 281 } 277 282
Note: See TracChangeset
for help on using the changeset viewer.