0

Is their a way to disable ajax add to cart only on the product page but keep it working on other pages in Magento 2?

Edit: After the answer of William. I have checked the addtocart.phtml file but their is no piece of code like he suggested. Their are code available which is as follows:

<?php  if($block->isRedirectToCartEnabled()) : ?>

    <script type="text/x-magento-init">

        {

            "#product_addtocart_form": {

                "Magento_Catalog/product/view/validation": {

                    "radioCheckboxClosest": ".nested"

                }

            }

        }

    </script>

    <?php else : ?>

    <script type="text/x-magento-init">

        {

            "#product_addtocart_form": {

                "Magento_Catalog/js/validate-product": {}

            }

        }

    </script>

    <?php endif; ?>

Please help me to figure it out. Thanks

marked as duplicate by Prince Patel, Dhiren Vasoya, Jai, Priyank, Manoj Deswal Feb 17 '18 at 15:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Replace your this code

<script type="text/x-magento-init">
        {
            "#product_addtocart_form": {
                "Magento_Catalog/product/view/validation": {
                    "radioCheckboxClosest": ".nested"
                }
            }
        }
</script>

WITH

<script type="text/x-magento-init">
{
    "#product_addtocart_form": {
        "Magento_Catalog/product/view/validation": {
            "bindSubmit": true,
            "radioCheckboxClosest": ".nested"
        }
    }
}
</script>
  • Make sure we have to set Yes from Store->Configuration->Sales->Checkout->Shopping Cart->After Adding a Product Redirect to Shopping Cart to Yes. Then it will work. Correct Dhiren? That's how it works for me. – Magento Team Feb 17 '18 at 13:15
  • If my answer help you, please accept it. So it will help other in community as well. – Dhiren Vasoya Feb 17 '18 at 13:17
0

In your theme, override /Magento_Catalog/templates/product/view/addtocart.phtml (see http://devdocs.magento.com/guides/v2.2/frontend-dev-guide/templates/template-override.html) Assuming that your theme is based on the Magento's core theme, find the following script:

"catalogAddToCart": {
                "bindSubmit": true
            }

And change to bindSubmit to false.

  • Hi William , I have checked and found that their is no piece of code which you mentioned in addtocart.phtml file. Their are two scripts which I have added in my Question. Please check. Thanks – Magento Team Feb 17 '18 at 9:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.