问题描述
当前正在开发一个购物车,我认为保留购物车的选项是:
Currently developing a shopping cart, the options for persisting the cart, as i see them are:
- 将整个购物车对象存储在会话表。
- 将整个购物车对象存储在cookie会话中。
- 有一个购物车表,并将购物车ID存储在cookie会话中。
我错过了吗?
谢谢
推荐答案
#3可能是您最好的选择,因为这给了您最大的自由度/灵活性。假设某天您希望用户能够在会话之间保存他们的购物车。或者,您想保留用户的购物车历史记录。或者您决定对购物车数据进行一些分析。
#3 is probably your best bet, because that gives you the most freedom/flexibility. Say someday you want users to be able to save their shopping carts between sessions. Or you want to keep shopping cart histories for your users. Or you decide to run some analytics on shopping cart data.
#2是一个糟糕的解决方案,因为浏览器的cookie大小受到限制。您正在为大型购物车损坏的讨厌的bug做好准备,尤其是在较旧的浏览器中。
#2 is a bad solution because of the cookie size limits on browsers. You're setting yourself up for nasty bugs where large shopping carts get corrupted, particularly in older browsers.
这篇关于在Ruby on Rails中保留购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!