Changeset 354 for trunk


Ignore:
Timestamp:
Jun 11, 2009 4:37:41 PM (15 years ago)
Author:
quinn
Message:

Refactored the sum() function in Cart.inc.php.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Cart.inc.php

    r353 r354  
    247247    * Return the sum of the numeric values stored under the specified key for cart items.
    248248    * 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.
    249251    *
    250252    * @access   public
     
    257259    function sum($key='extended_price')
    258260    {
     261        $sum = 0;
    259262        switch ($key) {
    260263        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' :
    265267            foreach ($_SESSION['_cart'][$this->_ns]['items'] as $item_id => $specs) {
    266268                $sum += isset($specs[$key]) && is_numeric($specs[$key]) ? $specs[$key] : 0;
    267269            }
    268             return $sum;
     270
    269271        default :
    270                 $sum = 0;
     272            // Retreive arbitrary values stored in the cart (shipping, air miles, etc).
    271273            foreach ($_SESSION['_cart'][$this->_ns]['items'] as $item_id => $specs) {
    272274                $sum += isset($specs[$key]) && is_numeric($specs[$key]) ? $specs[$key] * $specs['quantity'] : 0;
    273275            }
    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;
    276281    }
    277282
  • trunk/services/logs.php

    r334 r354  
    2525$valid_file_extensions = array('', 'txt', 'log');
    2626
    27 // Files that cannot be deleted (preg search expressions).
     27// Files that shouldn't be deleted (preg search expressions).
    2828$no_delete_files = '/^php_error_log$|^access_log$|^error_log$|^ssl_request_log$/';
    2929
    30 // Files that cannot be cleared (preg search expressions).
     30// Files that shouldn't be cleared (preg search expressions).
    3131$no_clear_files = '/__|^access_log$|^error_log$|^ssl_request_log$/';
    3232
    33 // Files that cannot be archived (preg search expressions).
     33// Files that shouldn't be archived (preg search expressions).
    3434$no_archive_files = '/__|^access_log$|^error_log$|^ssl_request_log$/';
    3535
    36 // Files that cannot be archived (preg search expressions).
     36// Files that shouldn't be downloaded (preg search expressions).
    3737$no_download_files = '/^$/';
    3838
Note: See TracChangeset for help on using the changeset viewer.