为网站实施购物车的最佳方法是什么? [英] What's the best way to implement a shopping cart for a website?

查看:49
本文介绍了为网站实施购物车的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线购物网站.该网站不是真实的,它只是我的作品集和个人学习的代表.我对购物车主题有些困惑,因为我不知道什么是最好的进行方式.我注意到,即使您没有登录,即使您没有帐户,即使您关闭浏览器并稍后再返回,大多数网站也会保存您的购物车.我已经考虑了几件事,但是我对每件事都有一些疑问,而且我还没有找到做这件事的最佳方法.这些是我的选择:

I''m developing an online shopping site. The site isn''t real, it''s just a proyect for my portfolio and for personal learning. I''m a little stuck on the shopping cart subject becuase I do not know what''s the best way to proceed. I''ve noticed that most websites save your cart even if you''re not logged in, even if you don''t have an account, even if you close your browser and come back later. I''ve thought of a few things, but I have a few doubts on each and I haven''t been able to find what is the best way of doing it. These are my options:


  1. 会话变量.我可以启动一个php会话变量,但这仅适用于当前会话(我认为?).
  2. 数据库表.我可以在数据库中设置一个临时表,以将购物车信息保留给用户,无论他们是否创建了帐户.但是,要做到这一点,我将不得不找到一种独特的方式来识别每个客户(对于没有账户的客户),而且我对如何做到这一点也毫不犹豫.我知道IP地址不会起作用,因为人们一直都在登录不同的路由器,而所有共享路由器的人都将共享一个IP地址.如果有办法,我非常想知道.
  3. Cookies.目前,这似乎是最好的主意,只要用户打开网站在同一浏览器上在同一设备上.缺点是,有些人喜欢配置其浏览器以阻止cookie.另外,如果用户删除了包括cookie在内的浏览器历史记录,它就消失了.

  1. Session variables. I could start a php session variable but that would only work for the current session (I think?).
  2. Database table. I could set a temporary table on my database to keep that cart info for users whether or not they''ve created an account. To do this though, I''d have to find a unique way of identifying each client (for those with no accounts) and I haven''t the faintest as of to how to do that. I know IPs won''t work beacuse people log on into different routers all the time, and all those sharing a router would share an IP address. If there is a way though, I would very much like to know.
  3. Cookies. At the moment, this seems like the best idea, as long as the user opens up the site on the same browser on the same device. The disadvantage is, that some people like to configure their browsers to block cookies. Plus, if the user erases the browser history including the cookies, it''s gone.


如果这些(或这些的任何组合)中的任何一个是正确的答案,请指出,或者我错过了一些东西.我在正确的轨道上吗?

P.S.我知道有一些免费的第三方解决方案,但我真的想自己做,只是为了解决它.


If any of these (or any combination of these) is the right answer, please point it out, or if I''m missing something. Am I on the right track?

P.S. I know there are a few free third-party-solutions but I would really like to do this myself, just for the heck of it.

推荐答案

正确的方向.购物车是一种应用程序,其中包含所有需要学习和探索的基本知识.

如您所说,使用JavaScript Cookies是一个适当的选择.而且,JavaScript中还有另一种存储机制-localStorage.使用此功能,您不必担心用户清除的浏览器cookie.有关更多详细信息,请访问该站点- jstorage

祝您编码愉快!

问候,
尼拉·索尼(Nial Soni)
You are going in the right direction. Shopping Cart is a kind of application which includes all the basic stuffs to learn and explore.

As you said, making use of JavaScript Cookies is an appropriate option. But also, there is another storage mechanism - localStorage, in JavaScript. Using this, you need not to worry about the browser cookies cleared by the users. For more details please refer to the site - jstorage

Have a happy coding !!!

Regards,
Niral Soni


这篇关于为网站实施购物车的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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