gobbles Posted May 22, 2006 Share Posted May 22, 2006 Hey All,I was wondering if someone could help me with a couple of statements im trying to write.I have a shopping cart, and im trying to implement a individual shipping cost per product and a secondary shipping price for additional products and quantitys.I just cant seem to get my head around the statement ... basically this is how it should go:if theres more than one product in the cart then get primary shipping cost of 1st product how much qty? any additional product? for each additional products and qty's use secondary shipping price ( which is defined for each product)else if there is only one product and one qty then use primary shipping cost.Hows that sound ... I cant get my head around it at all.to give a real world example:Listed below are 2 products with their detailsProduct: Canon Digi CameraPrimary Shipping Cost: $20Additional Shipping Cost: $1Product: DVD PlayerPrimary Shipping Cost: $40Additional Shipping Cost: $2If i buy 2 digi cameras, the total shipping price will be $21$20 + $1If i buy 1 digi camera and 1 DVD player, the total shipping price will be $22$20 + $2If i buy 1 digi camera and 4 DVD players, the shipping will be $28$20 + $2 + $2 + $2 + $2I hope thats a better explaination of it.If any could help me get my head around this it would be greatly appreciated, i have been pulling my hair out about this for months now.Cheers Quote Link to comment https://forums.phpfreaks.com/topic/10175-if-else-statement-maybe/ Share on other sites More sharing options...
eves Posted May 22, 2006 Share Posted May 22, 2006 you might want to try these:assuming you have this fields on your cart tabletbl_cart(cart_id, prod_id, qty, unit_price, pri_shipping, sec_shipping, initial, client_id)- would greatly ease computation if you store primary and secondary shipping on the table- pri_shipping - primary shipping cost of product- sec_shipping - additional shipping cost of product[code]$result = mysql_query("select * from tbl_cart where client_id='$CLIENT_ID'");$shipping = 0;while($row=mysql_fetch_assoc($result)){ if ($row['qty']>1) { if ($row['initial']==1) //get primary shipping cost first then add secondary costs { $shipping += $row['pri_shipping']; $shipping += ($row['qty']-1)*$row['sec_shipping']; } else { $shipping += ($row['qty'])*$row['sec_shipping']; } } else { // since only 1 qty, should be the main product, thus primary shipping cost apply $shipping += $row['pri_shipping']; } }[/code]the initial field is etheir 1 or 0, 1 if its the main product being pruchased, else 0you might want to check for some syntax or typos, just basically made it up on this site's editor [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/10175-if-else-statement-maybe/#findComment-37939 Share on other sites More sharing options...
gobbles Posted May 22, 2006 Author Share Posted May 22, 2006 Thanks for your quick reply.I tried to implement the code that you gave, but came through with some errors, the following code works perfect if theres only 1 product in the cart, if i update the qty, everything.But it doesnt work with multiple products in the cart, when there are multiple products, it adds the primary ($products_ship_price) instead of adding the additional ($products_ship_price_two)[code]$this->vendor_shipping[$vendors_id]['ship_cost'] += ($products_ship_price);if ($this->vendor_shipping[$vendors_id]['ship_cost'] >= 2.5000) $this->vendor_shipping[$vendors_id]['ship_cost'] = ($this->vendor_shipping[$vendors_id]['ship_cost']); if ($quantity > 1) { $this->vendor_shipping[$vendors_id]['ship_cost'] += ($products_ship_price_two * ($quantity-1)); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10175-if-else-statement-maybe/#findComment-37948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.