购物车会话数组
我正在构建一个简单的购物车,并且从产品页面获取以下数组(当用户提交“添加到购物车”按钮时)...
Array ( [product_id] => 1 [weight] => 2 [size] => 4 [type] => cafe [cost] => 6323.86 )
之后,我将其保存到 session
以便稍后显示购物车...
$_SESSION['cart']= $data; //$_POST values into $data
如果用户仅将 1 个产品添加到购物车中,但如果他添加另一个产品,$_SESSION['cart'] 数组将替换为新值,那么它非常有用,但我希望它保存所有选定产品的详细信息,我该如何达到那个目的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将另一个数据级别放入购物车:
这将完成记录该商品已放入购物车的简单任务。您需要添加额外的逻辑来处理数量更新等。
然而,值得注意的是:如果“成本”字段是通过客户端往返的,请不要相信该值。对于某人来说,添加大量昂贵的商品并将价格设置为 0 将会非常简单。 Boom 会进入您的电子商务系统。
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.