I'm working on a shipping calculator and i have a problem,let me tell you what i have and then i'll tell you my problem,
My array and foreach:
$array = unserialize($_SESSION['__vm']['vmcart']);
foreach($array->products as $product){
$price = $product->product_price;
$amount = $product->quantity;
$length = $product->product_length;
$width = $product->product_width;
$height = $product->product_height;
$weight = $product->product_weight;
$supplier = $product->product_unit;
}
and everything works with the above code (That's not my problem)
My problem is:
the calculator has to take all the weight from supplier 1 and add them together and then do the same for supplier 2 (see below)
Example:
Product1 - weight is 5kg and it's from supplier 1
Product2 - weight is 2kg and it's from supplier 1
Product3 - weight is 9kg and it's from supplier 2
supplier 1's weight = to 7kg
supplier 2's weight = to 9kg
The same thing if it's the other way around,
Now what i have tried is a if statement (see below) but all it's doing is adding every products weight together,
if ($supplier =='S1'){
$s1_total_weight += $product->product_weight;
} if ($supplier =='S2'){
$s2_total_weight += $product->product_weight;
}
echo 'Supplier 1 '.$s1_total_weight.'<br>';
echo 'Supplier 2 '.$s2_total_weight.'<br>';
i use the below code to get the supplier number (S1 = supplier 1 - S2 = supplier 2),
$supplier = $product->product_unit;
I'm new to php but i think it has to do with the below code or am i wrong? can it be the if statement?
$product->product_weight
Please let me know if you need any more information,
if you have a better title for this topic please change it :)
Thanks for any help.