Page 1 of 1

R10 issue with adding to cart after adding from More Items

Posted: Mon Feb 22, 2016 4:21 am
by AbleMods
Adding an item from the More Items In Category control bugs the product page's main add-to-cart button when the browser back button is used to return to the product page.

Steps To Reproduce

From the shopper side...
Clear your basket
Find a product that doesn't have variants or choices.
Scroll down and find a product in the 'More Products In Category...' control. This product should have "Add To Cart" button text, not "More Details".
Click the Add-to-Cart button for the product in the More Products In Category... control.
You should now be on the basket page and see the more-products-in-category product you clicked.
Now click the browser back button. You should now be on the product page you were on before.
Click the product page Add-to-Cart button.
You should now be on the basket page again.

But instead of two different products in the basket, you now have a quantity 2 of the more-products-in-category product you added first.

Is there a quick fix to this? I've got a client rather concerned about it as they do a lot of related-product business.

Re: R10 issue with adding to cart after adding from More Items

Posted: Mon Feb 22, 2016 5:06 am
by Katie
I can reproduce it in Gold R11 as well. It works if I add the main product first. The problem only happens if you add the item from the "Also in..." section, then back to the product itself.

It can be reproduced by using either the "Product Display in Rows" or "Basic Product" display template. You have to make sure the mini-basket is disabled.

I'll report the issue. AC8-3047

Re: R10 issue with adding to cart after adding from More Items

Posted: Mon Feb 22, 2016 5:51 am
by AbleMods
Awesome thanks for the quick review Katie!

I don't know about you at 6:06 am, but I sure wasn't awake at 5:21 am :)

Re: R10 issue with adding to cart after adding from More Items

Posted: Tue Feb 23, 2016 3:27 am
by mazhar
This seems to be happening due back button, browser cache and how ASP.NET handles post backs in javascript. It seems like it happened to other people too as being discussed here
http://weblog.west-wind.com/posts/2007/ ... ack-Button

The simplest fix in our case should be to clear the special ASP.NET fields called __EVENTTARGET and __EVENTARGUMENT upon JQUERY ready event. Edit Website/ConLib/BuyProductDialog.ascx file and following javascript to it. I used regular expression to narrow the scope of this change to use of Add To Cart Link.

Code: Select all

<script type="text/javascript">
// CLEAR CACHED __EVENTTARGET AND __EVENTARGUMENT VALUES UPON DOM READY
    $(function () {
        var addToCartExp = new RegExp('\\$AddToCart_([0-9]+)$');
        var eventtarget = $('#__EVENTTARGET').val();
        if (addToCartExp.test(eventtarget)) {
            $('#__EVENTTARGET').val('');
            $('#__EVENTARGUMENT').val('');
        }
    });
</script>

Re: R10 issue with adding to cart after adding from More Items

Posted: Wed Feb 24, 2016 8:25 am
by AbleMods
Wow, what an unusual set of circumstances. Leave it to me to find the really good stuff eh? :)

I'll give your script a try and let you know the results.