Sunday 15 February 2015

php - Failure to adjust item amount -


Hi if the item with the same PID, length and square is already in the shopping cart I am using the code below and if so, then it should adjust the amount of the item. The point is that if you add an item with a drink, length and range, it is added to the shopping basket as a new product.

  Note: one item has the same PIN but it comes in different sizes and categories. If (isset ($ _ POST ['pid'])) {$ pid = $ _POST ['pid']; $ Length = $ _POST ["size"]; $ Qty = $ _POST ['Quantity']; $ Range = $ _POST ['category']; $ Was wrong = false; $ I = 0; {$ _SESSION ["cart_array"] = array (0 = & gt; array (ifet ($ _ session ["cart_array"]) || calculation ($ _ session ["cart_array"]) & lt ;! 1) ("ITEM_ID" = & gt; $ PID, "length" => gt; $ length, "category" = & gt; $ range, "quantity" = & gt; $ quantity)); } And {foreach ($ _SESSION ["cart_array"] as $ $ each_item) {$ i ++; Whereas (list ($ key, $ value, $ ilength, $ pcategory) = each ($ every_item)) {if ($ key == "ITEM_ID" & amp; $ ilength == $ in length & amp; Amp; $ pcategory == $ category and & amp; $ value == $ pid) {array_splice ($ _ session ["cart_are"], $ i-1, 1, array (array ("item_id" => Pid, "length" => gt; $ length, "category" = & gt; $ range, "volume" = & gt; $ each_item ['quantity'] + 1))); $ Was right; = True; }}} If ($ Wasfound == incorrect) {array_push ($ _ session ["cart_array"], array ("ITEM_ID" = & gt; $ PID, "length" = & gt; $ length, "category" = & Gt; $ range, "volume" => $ qty)); }} Header ("location: cart.php"); Go out(); }? & Gt;    

I will try it;) Update and test code foreach ($ _SESSION ["cart_array"] $ array_key => $ each_item) {if ($ each_item ['item_id'] == $ pid and $ every_item ['length'] == $ Length & amp; $ each_item ['category'] == $ range) {$ _SESSION ["cart_array"] [$ array_key] ['quantity'] + = $ qty; $ Was right; = True; }}

No comments:

Post a Comment