我正在使用 CODEIGNITER 购物车类。以下是VAR_DUMP
购物车内容。我有一个单选字段,可让您选择一个SHIP
选项。问题是我的 PHP 没有获取SHIP
值,而只返回购物车值中的最后一项并乘以购物车项目的总数。如何SHIP
从每个项目中获取数组并对值求和?
PHP
$ship_array = $this->cart->ship($item['rowid']);
foreach ($ship_array as $index => $ship_option){
#SHIPPING CALC
$ship_total = 0;
foreach ($cart as $item)
{
$ship_total += $ship_option;
}
echo '<label><input type="radio" name="print" class="option" data-number="'. $ship_total .'" value="'. $index .'"/> UPS '. $index .' </label> '; }
^此代码只会从ship
购物车中的最后一项中获取值。结果将显示ground
运费为 43.35 美元(14.45(陆运价值 * 3 件总物品)
显然这是错误的,我需要添加每个的运费值$item
VAR_DUMP 数组(购物车中的所有商品)
array (size=3)
'554ed09a5f80917741359cc9da50a75c' =>
array (size=8)
'rowid' => string '554ed09a5f80917741359cc9da50a75c' (length=32)
'id' => string '101' (length=3)
'qty' => string '1' (length=1)
'price' => string '112.5' (length=5)
'name' => string 'Business Card' (length=13)
'ship' =>
array (size=3)
'Ground' => float 9.73
'2nd Day Air' => float 18.54
'Overnight' => float 26.27
'options' =>
array (size=2)
'Print Package' => string 'Pro' (length=3)
'Design Package' => string 'Premium' (length=7)
'subtotal' => float 112.5
'675d8a197a25e6720af7ac05707fee40' =>
array (size=8)
'rowid' => string '675d8a197a25e6720af7ac05707fee40' (length=32)
'id' => string '102' (length=3)
'qty' => string '1' (length=1)
'price' => string '446' (length=3)
'name' => string 'Booklet' (length=7)
'ship' =>
array (size=3)
'Ground' => float 14.45
'2nd Day Air' => float 22.57
'Overnight' => float 34.12
'options' =>
array (size=2)
'Print Package' => string 'Plus' (length=4)
'Design Package' => string 'Ultimate' (length=8)
'subtotal' => int 446
'aea5d2f84151e65a0a1e50371aad26aa' =>
array (size=8)
'rowid' => string 'aea5d2f84151e65a0a1e50371aad26aa' (length=32)
'id' => string '102' (length=3)
'qty' => string '1' (length=1)
'price' => string '325' (length=3)
'name' => string 'Booklet' (length=7)
'ship' =>
array (size=3)
'Ground' => float 14.45
'2nd Day Air' => float 22.57
'Overnight' => float 34.12
'options' =>
array (size=2)
'Print Package' => string 'Pro' (length=3)
'Design Package' => string 'Premium' (length=7)
'subtotal' => int 325