HomeHome Product Discus... Product Discus...RazorCartRazorCartUpdateRazorCartItem cookie issueUpdateRazorCartItem cookie issue
Previous
 
Next
New Post
3/20/2019 10:14 AM
 
Bug / Problem: The _RazorCart-GUID cookie is not being created in certain circumstances, at least on our sire, and it's causing an error when calling UpdateShoppingCartItem. We are working with RazorCart 1.5.2.

We have a site that cannot use the internal pricing system in RazorCart. I use the PreAddToCart code to determine the proper price for an item and put that into the cart data. When there is a change I call UpdateShoppingCartItem to update everything with the new values.

UpdateShoppingCartItem requires the RazorCart-GUID cookie value to operate properrly. As near as I can tell the cookie is only created when the "Add To Cart" button is clicked on a detail page. If you have cleared your cookies, and go straight to the checkout page (where items are sitting in the cart) and change the quantity on one or more and click recalculate, it executes the PreAddToCart but UpdateShoppingCartItem fails because there is no RazorCart-GUID cookie.

How can I get around this? Is there an alternate call I can use to update the price and quantity, is there a way to call a function in code to create the cookie if it does not exist, is there something different I can pass the function (other than the null it gets in these circumstances) or any way I can look into the Model and find the value if the cookie isn't there? Or some other way around this I haven't thought of?

Thank you,
G
 
New Post
3/20/2019 2:14 PM
 
It looks like the proper value is in CartItem.CartCookie even under the conditions above that caused the error. Do you see any problems with using the CartCookie for the item being updated instead of the real cookie?
 
New Post
3/27/2019 1:50 PM
 
Hi George,

The cookie "_RazorCart-GUID" should be created once an item added to the shopping cart from any module list, details, slider etc.. Is that working for you?
If the cookie is not being created please make sure that you're not using DNN 8.0.0 as of issue DNN-8347
But you also mentioned that you clear the cookies before you navigate to the checkout page! Can you explain why you would need to clear the cookies after you add to cart?
If the cookie "_RazorCart-GUID" was removed before opening the checkout page, you should not see any items unless your setting for "Persistent Cart Behavior" is set to "Persist By DNN User"! If so then why your custom function "UpdateShoppingCartItem" needs the cart cookie value?
However if I misunderstood and the cookie is being created and was not removed from the browser then you can still read it from: System.Web.HttpContext.Current.Request.Cookies["_RazorCart-GUID"]
If you still think this is a bug and I am not addressing it please reply with more info and steps how to produce or make a quick video showing the issue if possible.

Regards,
Wael
 
New Post
3/27/2019 9:39 PM
 
If you do an add to cart before going to checkout page the cookie gets created just fine. I don't think there's a problem, maybe a note should be made though. I've coded the update to use the CartCookie in the CartItem and it as far as I can see works fine. The only thing I think might be worth noting is not to use the browser cookie for the GUID value when updating a shopping cart item because there are times the cookie might not be there.

Normal workflow: Go to a detail page, click add to cart, the cookie gets created, and all is good.

But:
1. Have items in your cart.
2. Clear cache which deletes the cookie.
3. Open up the web site. Go directly to the checkout page. We generally have this in the menu because people could be leaving things in the cart and returning. At this point the cookie has been erased in step 2 but hasn't been recreated.
4. The custom pipeline code tries to update the cart using the cookie, which doesn't exist because the user hasn't clicked add to cart since clearing the cookies. Kaboom.
5. Solution: At all times the proper GUID looks to be in the CartItem.CartCookie field of the item being updated. Use that instead of the cookie in the browser.

Specific answers:
I may have mis-spoke (mis-typed?) To see the problem you need to clear cookies before one opens the site and goes directly to the checkout page. While deleting the cookies after clicking add to cart and before going to the checkout page would create the error, I agree it's irrational. If one does that they get what they deserve and that's not your or my problem!

On this site, the setting is indeed set to Persist by Login. We're on DNN 9.x.

The cookie is being created every time add to cart is clicked. There's no issue with this. It only happens when you get to the checkout page (or to where you execute pipeline code) without having clicked add to cart.

For a scenario, consider this:
1. User has a browser that is set up to delete cookies when closed. It's a RazorCart site that persists by login and has a link to the Checkout page on the top menu.
2. The user goes into the site and adds 3 items to the cart.
3. The user closes the browser. It deletes the cookies but the items are still in the cart,
4. The user opens the browser again and navigates to the site and logs in.
5. The user clicks on the "Checkout" link and goes straight to the checkout page without ever clicking add to cart and without recreating the cookie, since there are 3 items in their cart and all the user wants is to buy them now.
6. The custom pipeline code calls the UpdateCartItem method, which looks to the cookie for the GUID. But the cookie does not exist. The call fails.

Solution: The GUID is also in the CartItem.CartCookie field. Use that in the update statement instead.

In response to an earlier forum question I was provided sample code showing me how to use UpdateCartItem, which workes great and I am completely grateful for. The example code got the GUID from the cookie and we found the a way to run that code when the cookie didn't exist.  It's not normal workflow but scenarios where the error could occur were reasonable. I think it might be safer to get the GUID from the CartItem, The actual cookie in the browser might not exist. 

I don't think it's a bug. I think people using custom pipeline code should get the GUID from the CartItem they're updating/deleting and not the browser cookie. I apologize for making a mountain out of a molehill.
 
New Post
4/2/2019 8:58 PM
 
Hi George,

The "_RazorCart-GUID" contains a random value (a new instance initialization of a GUID structure) so restoring the same value after you clear the browser's cache would not be possible, however if you're using "Persist By DNN User" then you would need to pull the shopping cart items by the username not by the cart GUID.
I am not sure how your custom code works and it seems we have a complicated scenario here which will be hard to explain in the forum, would you like me to schedule a meeting so we can share screens and discuss this during the call?

Regards,
Wael
 
Previous
 
Next
HomeHome Product Discus... Product Discus...RazorCartRazorCartUpdateRazorCartItem cookie issueUpdateRazorCartItem cookie issue