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.

  • 写回答

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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?