I have check online demo of Magento 2
http://magento2-demo.nexcess.net/fusion-backpack.html
when we click on add to cart it add product via AJAX but i have Set up demo on localhost it don't to add Product to cart via AJAX.

Can anyone tell where is settings to enable ajax on add to cart ?

  • have you seen any error in console? – Rakesh Jesadiya Jul 14 '16 at 9:16
  • It will redirect to shopping cart page or others? – Khoa TruongDinh Jul 14 '16 at 9:50
  • no error in console – Arun Karnawat Jul 14 '16 at 10:05
  • it don't redirect to cart page but refresh on same page – Arun Karnawat Jul 14 '16 at 10:10
  • Maybe it's because you are with blank theme. Try to switch to Luma and you will get AJAX add to cart. – Miroslav Petroff Jul 14 '16 at 11:04
up vote 31 down vote accepted

You have to just override addtocart.phtml file

app/design/frontend/Packagename/themename/Magento_Catalog/templates/product/view/addtocart.phtml

Replace "bindSubmit": false to "bindSubmit": true

<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "catalogAddToCart": {
                "bindSubmit": false
            }
        }
    }
</script>

to

<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "catalogAddToCart": {
                "bindSubmit": true
            }
        }
    }
</script>

Remove cache and check its in detail page.

  • That was quick and easy. One thing though I have Changed Button text From "Add to Cart" to "Add to Bag" But when it is added to cart the Text Revert Back to "Add to Cart" Where to change it. – Arun Karnawat Aug 9 '16 at 9:16
  • you can try to change name of add to cart from here vendor/magento/module-catalog/i18n/en_US.csv with replace in second column add to cart to add to bag – Rakesh Jesadiya Aug 9 '16 at 9:22
  • How/ where do i override the file vendor/magento/module-catalog/i18n/en_US.csv – Arun Karnawat Aug 9 '16 at 9:32
  • in your app/design/frontend/Vendorname/themename/i18n folder – Rakesh Jesadiya Aug 9 '16 at 9:34
  • 1
    Hello @Rakesh, I have similar issue and got solution from your answer. But in case of Ver 2.1.2. after ajax add to cart page is getting refreshed. You have any solution to prevent the page loading in Magento 2.1.2 ? – Ashish Jagnani Dec 7 '16 at 11:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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