我正在使用购物车类CI
,而我内部则有小计。有没有办法统计所有小计并在视图中显示它们?
喜欢$total=$allsubtotal;
由于
答案 0 :(得分: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。