dss89001
2012-11-29 03:31
浏览 24
已采纳

Codeigniter Cart - 在数据库中保存数据 - 如何处理?

I need help with handling orders and cart in my web application.

I decided to use Cart library built in Codeigniter 2.

I've seen some tutorials about that Cart library and i know how to use it, but i dont know:

  • when shall I create/save that order in database? when user is adding items to cart, or shall i keep all order data in session and "move" it do database when user accepts order?
  • shall I store session id or something other in database?

I tried to see how cart/order functionality is implemented in PrestaShop, but it looks too complicated for me, im amateur PHP programmer.

图片转代码服务由CSDN问答提供 功能建议

我需要帮助处理我的网络应用程序中的订单和购物车。

我决定使用内置在Codeigniter 2中的Cart库。

我看过一些关于Cart库的教程,我知道如何使用它,但我不知道: \ n

  • 何时在数据库中创建/保存该订单? 当用户将项目添加到购物车时,或者我是否将所有订单数据保存在会话中并“移动”它在用户接受订单时执行数据库?
  • 我是否应将会话ID或其他内容存储在数据库中?< / li>

    我试图了解如何在PrestaShop中实现购物车/订单功能,但对于我来说,这对我来说太复杂了,即业余的PHP程序员。 < / DIV>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dounangshen6553 2012-11-29 03:51
    已采纳

    The ideal and good way to use cart is keep it in session, codeigniter's cart class is doing the same thing, and when user gives order use this data put this order in database and do other stuff like payment gateway, shipping. If you want to use user to keep his order in next session, like if user add some product in cart and he quits before giving order and he is a registered user, then you can save his cart every time in database, so that if he gone away without putting order you can show him his orders next time when he logged in.

    You can store users cart data in database using $this->cart->contents(); method of cart class. use like this

    $cartContentString = serialize($this->cart->contents());
    

    you will get a string of cart content, you can save this string in database and later use it like

    $cartArray = unserialize($cartContentString);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题