3

In Magento 2.1 When I enable Ajax on add to cart on Product detailed Page by "bindSubmit": true in add-to-cart.phtml

<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>

Now after clearing cache, I added a simple product to cart which was perfect, but on product with Option(Configurable option) when I add to cart without selecting the option, It show error "This is a required field.", but the ajax starts already and refresh the page giving error "Please specify product's required option(s).". Meaning Ajax add to cart don't wait for me to select the option, when I do not select option.

Hope you understand, what I am trying to say.

6

Should add more validation:

vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js

_bindSubmit: function() {
            var self = this;
            this.element.mage('validation');
            this.element.on('submit', function(e) {
                e.preventDefault();
                if(self.element.valid()) {
                    self.submitForm($(this));
                }
            });
        },

See more here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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