small medium large xlarge

14 Mar 2009, 17:32
Shimshun (3 posts)

I don’t understand what is happening here so please put me right if possible.

The smarter cart solution is given on page 113 to overcome the doubling up of the same product in a listing by incorporating the quantity attribute. In doing so we come across an issue with sessions and then this is solved; but i also come across another issue that is not addressed in the book:

Using browser refresh in the add_to_cart page, which lists the items already in the cart, asks me if i want to resend the information. If i do resend, then the count is incremented. In a real application we would not want this action: i am not sure how it is possible to stop it. So, how is this done? Here are two things i have tried.

1/ I tried stopping the increment in the add_to_cart method in the store controller, on the basis of the PATH_INFO request header but it seems that the PATH_INFO header is overwritten after the response from the client, so by grabbing it after the request from the store page, the value for the store page is already lost and now, while stopping the problem on refresh of thee ad_to_cart page, the store page does not update the cart.

2/ On the other hand by grabbing it (or any other identifying header) into a parameter in the store index view and passing this to add_to_cart means that when refreshing the add_to_cart view in the browser, this information is sent and the original problem has remained.

I hope i have explained this ok. Whats going on?

15 Mar 2009, 14:17
Dave Thomas (390 posts)

In a real-world application, that’s exactly what happens, though: a refresh resubmits the form data, which is why the browser is warning you.

Possible solutions including adding a timestamp to the request, and asking the use if they’re sure they want to order again if a second request comes in within so many seconds, an simply redirecting away from the page on every post request.


Dave Thomas

17 Mar 2009, 06:31
Shimshun (3 posts)

Hi Dave Yes i see what you mean - i have just tried this on Amazon. I am surpised that there is no well known intervention mechanism, though i will try your two solutions Thanks Shimshun

You must be logged in to comment