On any shopping cart, you get to update the qtys of the products you selected before paying for your goods.
When you click Update button it updates all the quantities for you.

What I can't get my head around, is how they grab the values from the text fields, how these update the quantities in the db, then when the page is posted to itself the new quantities show on the cart page.

Would someone be kind enough to explain the basic principles of this.

HOW I GOT AROUND THIS PROBLEM ON MY OWN TEST CART
Each qty box had its own update button. When you clicked the button It updated the product qty with the new qty you entered using the product id in the db. This works but is not flexible enough.

Thank you very much

    Well, without actually creating this myself. I would just suggest that in order to use 1 update button with multiple text fields. I would name each text field name="qtyID" where ID would be the ID of the item. After submission, loop all the posted items. Use a regex to grab each qtyID, take the ID and update the quantities with their respected value.. make any sense?

      Yes that does make sense. I was struggling with a foreach loop, I managed to fill one array with the qtys, but I cam unstuck trying to fill another array with id and them combining the two.

      I will look up regex.

      Thank you very much for your help.

        well we'd be happy to look at your code and make suggestions if you want to post some of it up

          Write a Reply...