I’m using CODEIGNITER Cart Class. The following is a VAR_DUMP of the cart contents. I have a radio selection field which allows you to select a SHIP option. The problem is that my PHP is not getting the SHIP values but only returning the last item in cart’s value and multiplying by the total number of cart items. How do I get the SHIP array from each item and sum the values?
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> '; }
^this code will only get the values from ship in the last item in the cart. The result will say that ground shipping is $43.35 (14.45 (ground shipping value * 3 total items)
Obviously this is wrong i need to add the shipping values from each $item
VAR_DUMP of Arrays (all items in cart)
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
You can try
Output