在Ruby on Rails中坚持购物车

时间:2022-04-01 23:35:11

Currently developing a shopping cart, the options for persisting the cart, as i see them are:

目前正在开发购物车,保持购物车的选项,如我所见:

  1. Store the entire cart object in a sessions table.
  2. 将整个购物车对象存储在会话表中。

  3. Store the entire cart object in a cookie session.
  4. 将整个购物车对象存储在cookie会话中。

  5. Have a cart table, and store the cart id in a cookie session.
  6. 有一个购物车表,并将购物车ID存储在cookie会话中。

Have i missed any? which is the best to roll with please?

我错过了吗?请哪个最好滚?

Thanks

2 个解决方案

#1


10  

#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.

#3可能是你最好的选择,因为这给你最大的*/灵活性。总而言之,您希望用户能够在会话之间保存购物车。或者您希望为用户保留购物车历史记录。或者您决定对购物车数据进行一些分析。

#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.

由于浏览器的cookie大小限制,#2是一个糟糕的解决方案。你正在为大型购物车损坏而烦恼,特别是在旧版浏览器中。

#2


5  

Check out the Railscasts episodes #141-#146... Helped me a lot with shopping cart/checkout related stuff (though the episodes don't directly address your question, you will get to see a straightforward method of implementing a shopping cart).

查看Railscasts剧集#141-#146 ...通过购物车/结账相关的东西帮助了我很多(虽然剧集没有直接解决你的问题,你会看到一个实现购物车的简单方法) 。

#1


10  

#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.

#3可能是你最好的选择,因为这给你最大的*/灵活性。总而言之,您希望用户能够在会话之间保存购物车。或者您希望为用户保留购物车历史记录。或者您决定对购物车数据进行一些分析。

#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.

由于浏览器的cookie大小限制,#2是一个糟糕的解决方案。你正在为大型购物车损坏而烦恼,特别是在旧版浏览器中。

#2


5  

Check out the Railscasts episodes #141-#146... Helped me a lot with shopping cart/checkout related stuff (though the episodes don't directly address your question, you will get to see a straightforward method of implementing a shopping cart).

查看Railscasts剧集#141-#146 ...通过购物车/结账相关的东西帮助了我很多(虽然剧集没有直接解决你的问题,你会看到一个实现购物车的简单方法) 。