2013-08-11 7 views

ответ

3

согласно Codeigniter Cart class documentation:

$this->cart->total();

Отображает общую сумму в корзине.

Вот как он вычисляется внутри, в случае, если вам интересно:

/** 
* Cart Total 
* 
* @access public 
* @return integer 
*/ 
function total() 
{ 
    return $this->_cart_contents['cart_total']; 
} 

Вот где что установлено:

/* snippet from function _save_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 
    if (! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty'])) 
    { 
     continue; 
    } 

    $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'] = $items; 
$this->_cart_contents['cart_total'] = $total; 

Я не уверен, почему total значения, возвращаемого документирована как целое число, должно быть float/double.

+1

CodeIgniter - позор в мире PHP :( –

 Смежные вопросы

  • Нет связанных вопросов^_^