Skip to content

Commit a5a2cbc

Browse files
committed
M2C-21768 Validate product quantity on Wishlist update
M2C-21768 Add updateWishlist event
1 parent 6da226d commit a5a2cbc

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ define([
1616
groupedInfo: '#super-product-table input',
1717
downloadableInfo: '#downloadable-links-list input',
1818
customOptionsInfo: '.product-custom-option',
19-
qtyInfo: '#qty'
19+
qtyInfo: '#qty',
20+
actionElement: '[data-action="add-to-wishlist"]'
2021
},
2122

2223
/** @inheritdoc */
@@ -30,8 +31,10 @@ define([
3031
_bind: function () {
3132
var options = this.options,
3233
dataUpdateFunc = '_updateWishlistData',
34+
validateProductQty = '_validateWishlistQty',
3335
changeCustomOption = 'change ' + options.customOptionsInfo,
3436
changeQty = 'change ' + options.qtyInfo,
37+
updateWishlist = 'click ' + options.actionElement,
3538
events = {},
3639
key;
3740

@@ -45,6 +48,7 @@ define([
4548

4649
events[changeCustomOption] = dataUpdateFunc;
4750
events[changeQty] = dataUpdateFunc;
51+
events[updateWishlist] = validateProductQty;
4852

4953
for (key in options.productType) {
5054
if (options.productType.hasOwnProperty(key) && options.productType[key] + 'Info' in options) {
@@ -220,7 +224,24 @@ define([
220224

221225
$(form).attr('action', action).submit();
222226
});
223-
}
227+
},
228+
229+
/**
230+
* Validate product quantity before updating Wish List
231+
*
232+
* @param {jQuery.Event} event
233+
* @private
234+
*/
235+
_validateWishlistQty: function (event) {
236+
var element = $(this.options.qtyInfo);
237+
238+
if (!(element.validation() && element.validation('isValid'))) {
239+
event.preventDefault();
240+
event.stopPropagation();
241+
return;
242+
}
243+
},
244+
224245
});
225246

226247
return $.mage.addToWishlist;

0 commit comments

Comments
 (0)