将商品添加到购物车问题 [英] add item to shopping cart problem

查看:72
本文介绍了将商品添加到购物车问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我在网站上列出的所有产品中都有购物车链接。当我按这个链接时我会生成一个这样的网址

http://www.mysite.com/index.htm?loca...rt&productid=3


按下此链接后,将包含网站cart.php并将

想要的产品添加到购物车,并显示购物车。


我现在的问题是购物车显示新商品后,

当我在浏览器中按F5键刷新网站时,同样

产品将再次添加到购物车中,因为之前生成的

url在浏览器中没有变化。


有任何人一个想法如何解决这个问题?


thanx ...

解决方案

Josef Bl?sl写道:

嗨大家好!

我在我列出的所有产品中都有购物车链接网站。当我按下此链接时,我会生成一个这样的网址

http://www.mysite.com/index.htm?loca...rt&productid=3
在我按下此链接后,将包含网站cart.php,并将
想要的产品添加到购物车,并显示购物车。

我的问题现在是在购物车显示后新产品在其中,当我在浏览器中按F5键刷新网站时,同样的产品会再次添加到购物车中,因为之前生成的网址没有变化在浏览器中。

有谁知道如何解决这个问题?

比...




是 - 将随机cookie(不是网络cookie)附加到每个请求,并忽略

请求,其中cookie已经在篮子中。


哈欠。


C.


Colin McKinnon schrieb:

Josef Bl?sl写道:

嗨大家好!

我有一个我在网站上列出的所有产品中的购物车链接。当我按下这个链接时,我会生成一个这样的网址



http://www.mysite.com/index.htm?loca...rt&productid= 3

在我按下此链接后,将包含网站cart.php,并将
想要的产品添加到购物车,并显示购物车。现在我的问题是在购物车显示新产品后,
当我在浏览器中按F5键刷新网站时,同样的产品将添加到购物车再一次,因为之前生成的网址在浏览器中没有变化。

有谁知道如何解决这个问题?

thanx ...



是 - 将随机cookie(不是网络cookie)附加到每个请求,并忽略cookie已经在篮子中的请求。
哈欠。

C。




非常感谢...好主意


Colin,

如果你''如此无聊,那么为什么不给出一个可以帮助他的答案

改进他的代码,而不仅仅是躲避一个bug。


Josef,
最终,你的根本问题是你有一个动作

变量。您需要将您的操作代码与

显示代码分开。


将PHP中的每个页面都视为对象中的方法。而不是在一个页面上使用
,并根据switch语句选择行为,而是花时间将动作分离到专用页面。

在这种情况下,创建一个cart-additem.php页面和一个cart-display.php

页面。让cart-additem.php进行变量/访问验证,然后将

项添加到购物车。然后,重新定位到显示页面。


你会发现这段代码更容易维护,并且会有很少/没有状态相关的错误。


~D


hi folks!

i have a cart link in all of my listed products on the site. when i
press this link i will generate a url like this

http://www.mysite.com/index.htm?loca...rt&productid=3

after i press this link the site cart.php will be included and add the
wanted product to the cart, and show the cart.

my problem now is after the cart is showed with the new product in it,
when i press the F5 key in the browser to refresh the site, the same
product will added to the cart once more, because the previous generated
url is unchanged in the browser.

have anyone a idea how to fix this problem?

thanx...

解决方案

Josef Bl?sl wrote:

hi folks!

i have a cart link in all of my listed products on the site. when i
press this link i will generate a url like this

http://www.mysite.com/index.htm?loca...rt&productid=3
after i press this link the site cart.php will be included and add the
wanted product to the cart, and show the cart.

my problem now is after the cart is showed with the new product in it,
when i press the F5 key in the browser to refresh the site, the same
product will added to the cart once more, because the previous generated
url is unchanged in the browser.

have anyone a idea how to fix this problem?

thanx...



Yes - attach a random cookie (not a web cookie) to each request and ignore
requests where the cookie is already in the basket.

yawn.

C.


Colin McKinnon schrieb:

Josef Bl?sl wrote:

hi folks!

i have a cart link in all of my listed products on the site. when i
press this link i will generate a url like this



http://www.mysite.com/index.htm?loca...rt&productid=3

after i press this link the site cart.php will be included and add the
wanted product to the cart, and show the cart.

my problem now is after the cart is showed with the new product in it,
when i press the F5 key in the browser to refresh the site, the same
product will added to the cart once more, because the previous generated
url is unchanged in the browser.

have anyone a idea how to fix this problem?

thanx...


Yes - attach a random cookie (not a web cookie) to each request and ignore
requests where the cookie is already in the basket.

yawn.

C.



thanks a lot... good idea


Colin,
If you''re so bored, then why not give an answer that might help him
improve his code, instead of just dodge a bug.

Josef,
Ultimately, your underlying problem is that you have an "action"
variable. You need to be separating out your action code from your
display code.

Think of each page in PHP as a method in an object. Instead of having
one page, and choosing the behavior based on a switch statement, take
the time to separate out actions to dedicated pages.

In this case, create a cart-additem.php page and a cart-display.php
page. Have cart-additem.php do variable/access validation, and then add
the item to the cart. Then, relocate to the display page.

You will find that this code will be easier to maintain, and will have
few/no state-related bugs.

~D


这篇关于将商品添加到购物车问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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