I am building a simple shop cart and I am getting the following array from product page(when the user submits add to cart button)…
Array ( [product_id] => 1 [weight] => 2 [size] => 4 [type] => cafe [cost] => 6323.86 )
and after that I am saving it to session to showing later on cart…
$_SESSION['cart']= $data; //$_POST values into $data
it works great for if user adds only 1 product into cart, but if he adds another product the $_SESSION[‘cart’] array replaces with new value, but i want it save all selected product’s details, how can i achieve that?
Put another data level into your cart:
which would do the simple task of recording that this item’s been put in the cart. You’d need to add extra logic for handling quantity updates and whatnot.
However, of major note: if that ‘cost’ field is being roundtripped through the client, DO NOT TRUST THE VALUE. it will be extraordinarily simple for someone to add massive quantities of expensive items and set the price to 0. Boom goes your ecommerce system.