正在获取CI购物车类中的总金额



我使用的是cart类CI,里面有小计。有没有办法统计所有小计并在视图中显示它们?

$total=$allsubtotal;

感谢

根据Codeigniter Cart类文档:

$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的返回值被记录为整数,应该是浮点/双精度。

最新更新