Codeigniter购物车 - 在数据库中保存数据 - 如何接近? [英] Codeigniter Cart - saving data in database - how to approach?

查看:102
本文介绍了Codeigniter购物车 - 在数据库中保存数据 - 如何接近?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I decided to use Cart library built in Codeigniter 2.

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

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


  • 我应该在数据库中创建/保存该订单吗?当用户将商品添加到购物车,或者我应保留所有订单数据在会话中,并在用户接受订单时移动数据库?

  • 应存储会话ID或其他数据库?

我试图看看如何在PrestaShop中实现购物车/订单功能,但对我来说看起来太复杂, 。

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

推荐答案

使用购物车的理想方式是保持会话,codeigniter的cart类是做同样的事情,当用户给订单使用这个数据把这个订单在数据库和做其他东西,如支付网关,运费。
如果你想使用用户在下一个会话保持他的订单,如果用户在购物车中添加一些产品,他在下订单前退出,他是一个注册用户,那么你可以每次在数据库中保存他的购物车,所以如果他没有下订单就可以下次在他登录时向他显示他的订单。

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.

您可以使用<$ c $将用户购物车数据存储在数据库中c> $ this-> cart-> contents(); cart类的方法。
使用像这样

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);

这篇关于Codeigniter购物车 - 在数据库中保存数据 - 如何接近?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆