Skip to content

Instantly share code, notes, and snippets.

@OZZlE
Created April 17, 2018 08:42
Show Gist options
  • Save OZZlE/67db00264ebfd94ea1f35e3998aa1c16 to your computer and use it in GitHub Desktop.
Save OZZlE/67db00264ebfd94ea1f35e3998aa1c16 to your computer and use it in GitHub Desktop.
M2.1.x Ajax add to cart bugfix patch
--- ./view/frontend/web/js/catalog-add-to-cart.js 2018-04-16 17:21:32.000000000 +0200
+++ ./view/frontend/web/js/catalog-add-to-cart.js 2018-04-16 17:21:32.000000000 +0200
@@ -33,11 +33,14 @@
_bindSubmit: function() {
var self = this;
+ this.element.mage('validation');
this.element.on('submit', function(e) {
e.preventDefault();
- self.submitForm($(this));
+ if(self.element.valid()) {
+ self.submitForm($(this));
+ }
});
- },
+ },
isLoaderEnabled: function() {
return this.options.processStart && this.options.processStop;
@@ -120,7 +123,7 @@
},
disableAddToCartButton: function(form) {
- var addToCartButtonTextWhileAdding = this.options.addToCartButtonTextWhileAdding || $t('Adding...');
+ var addToCartButtonTextWhileAdding = this.options.addToCartButtonTextWhileAdding || $t('Adding to Bag...');
var addToCartButton = $(form).find(this.options.addToCartButtonSelector);
addToCartButton.addClass(this.options.addToCartButtonDisabledClass);
addToCartButton.find('span').text(addToCartButtonTextWhileAdding);
@@ -128,7 +131,7 @@
},
enableAddToCartButton: function(form) {
- var addToCartButtonTextAdded = this.options.addToCartButtonTextAdded || $t('Added');
+ var addToCartButtonTextAdded = this.options.addToCartButtonTextAdded || $t('Added to Bag!');
var self = this,
addToCartButton = $(form).find(this.options.addToCartButtonSelector);
--- ./view/frontend/templates/product/view/addtocart.phtml 2018-04-17 10:40:22.000000000 +0200
+++ ./view/frontend/templates/product/view/addtocart.phtml 2018-04-17 10:40:22.000000000 +0200
@@ -40,17 +40,17 @@
</div>
</div>
<?php endif; ?>
-<?php if ($block->isRedirectToCartEnabled()) : ?>
+
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/product/view/validation": {
- "radioCheckboxClosest": ".nested"
+ "radioCheckboxClosest": ".nested",
+ "bindSubmit": true
}
}
}
</script>
-<?php else : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
@@ -58,4 +58,3 @@
}
}
</script>
-<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment