Skip to content

Commit 0f19848

Browse files
committed
Merge remote-tracking branch 'origin/MC-32772' into 2.4-develop-pr20
2 parents 61d1bae + dbbd90e commit 0f19848

File tree

9 files changed

+158
-6
lines changed

9 files changed

+158
-6
lines changed

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ define([
88
'mage/translate',
99
'underscore',
1010
'Magento_Catalog/js/product/view/product-ids-resolver',
11+
'Magento_Catalog/js/product/view/product-info-resolver',
1112
'jquery-ui-modules/widget'
12-
], function ($, $t, _, idsResolver) {
13+
], function ($, $t, _, idsResolver, productInfoResolver) {
1314
'use strict';
1415

1516
$.widget('mage.catalogAddToCart', {
@@ -24,7 +25,8 @@ define([
2425
addToCartButtonDisabledClass: 'disabled',
2526
addToCartButtonTextWhileAdding: '',
2627
addToCartButtonTextAdded: '',
27-
addToCartButtonTextDefault: ''
28+
addToCartButtonTextDefault: '',
29+
productInfoResolver: productInfoResolver
2830
},
2931

3032
/** @inheritdoc */
@@ -90,6 +92,7 @@ define([
9092
ajaxSubmit: function (form) {
9193
var self = this,
9294
productIds = idsResolver(form),
95+
productInfo = self.options.productInfoResolver(form),
9396
formData;
9497

9598
$(self.options.minicartSelector).trigger('contentLoading');
@@ -119,6 +122,7 @@ define([
119122
$(document).trigger('ajax:addToCart', {
120123
'sku': form.data().productSku,
121124
'productIds': productIds,
125+
'productInfo': productInfo,
122126
'form': form,
123127
'response': res
124128
});
@@ -172,6 +176,7 @@ define([
172176
$(document).trigger('ajax:addToCart:error', {
173177
'sku': form.data().productSku,
174178
'productIds': productIds,
179+
'productInfo': productInfo,
175180
'form': form,
176181
'response': res
177182
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'Magento_Catalog/js/product/view/product-info'
8+
], function (_, productInfo) {
9+
'use strict';
10+
11+
/**
12+
* Returns info about products in form.
13+
*
14+
* @param {jQuery} $form
15+
* @return {Array}
16+
*/
17+
return function ($form) {
18+
var product = _.findWhere($form.serializeArray(), {
19+
name: 'product'
20+
});
21+
22+
if (!_.isUndefined(product)) {
23+
productInfo().push(
24+
{
25+
'id': product.value
26+
}
27+
);
28+
}
29+
30+
return _.uniq(productInfo(), function (item) {
31+
return item.id;
32+
});
33+
};
34+
});
35+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'ko'
8+
], function (ko) {
9+
'use strict';
10+
11+
return ko.observableArray([]);
12+
});

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ define([
260260

261261
if (!_.isUndefined(productData)) {
262262
$(document).trigger('ajax:removeFromCart', {
263-
productIds: [productData['product_id']]
263+
productIds: [productData['product_id']],
264+
productInfo: [
265+
{
266+
'id': productData['product_id']
267+
}
268+
]
264269
});
265270

266271
if (window.location.href.indexOf(this.shoppingCartUrl) === 0) {

app/code/Magento/ConfigurableProduct/view/frontend/requirejs-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@ var config = {
88
'*': {
99
configurable: 'Magento_ConfigurableProduct/js/configurable'
1010
}
11+
},
12+
config: {
13+
mixins: {
14+
'Magento_Catalog/js/catalog-add-to-cart': {
15+
'Magento_ConfigurableProduct/js/catalog-add-to-cart-mixin': true
16+
}
17+
}
1118
}
1219
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'jquery',
8+
'Magento_ConfigurableProduct/js/product/view/product-info-resolver'
9+
], function (_, $, productInfoResolver) {
10+
'use strict';
11+
12+
return function (widget) {
13+
14+
$.widget('mage.catalogAddToCart', widget, {
15+
/**
16+
* @param {jQuery} form
17+
*/
18+
ajaxSubmit: function (form) {
19+
var isConfigurable = !!_.find(form.serializeArray(), function (item) {
20+
return item.name.indexOf('super_attribute') !== -1;
21+
});
22+
23+
if (isConfigurable) {
24+
this.options.productInfoResolver = productInfoResolver;
25+
}
26+
27+
return this._super(form);
28+
}
29+
});
30+
31+
return $.mage.catalogAddToCart;
32+
};
33+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'Magento_Catalog/js/product/view/product-info'
8+
], function (_, productInfo) {
9+
'use strict';
10+
11+
/**
12+
* Returns info about configurable products in form.
13+
*
14+
* @param {jQuery} $form
15+
* @return {Array}
16+
*/
17+
return function ($form) {
18+
var optionValues = [],
19+
product = _.findWhere($form.serializeArray(), {
20+
name: 'product'
21+
}),
22+
productId;
23+
24+
if (!_.isUndefined(product)) {
25+
productId = product.value;
26+
_.each($form.serializeArray(), function (item) {
27+
if (item.name.indexOf('super_attribute') !== -1) {
28+
optionValues.push(item.value);
29+
}
30+
});
31+
optionValues.sort();
32+
productInfo().push(
33+
{
34+
'id': productId,
35+
'optionValues': optionValues
36+
}
37+
);
38+
}
39+
40+
return _.uniq(productInfo(), function (item) {
41+
var optionValuesStr = item.optionValues ? item.optionValues.join() : '';
42+
43+
return item.id + optionValuesStr;
44+
});
45+
};
46+
});
47+

app/code/Magento/GroupedProduct/view/frontend/web/js/product-ids-resolver.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*/
55
define([
66
'jquery',
7-
'Magento_Catalog/js/product/view/product-ids'
8-
], function ($, productIds) {
7+
'Magento_Catalog/js/product/view/product-ids',
8+
'Magento_Catalog/js/product/view/product-info'
9+
], function ($, productIds, productInfo) {
910
'use strict';
1011

1112
/**
@@ -18,6 +19,11 @@ define([
1819
return function (config, element) {
1920
$(element).find('div[data-product-id]').each(function () {
2021
productIds.push($(this).data('productId').toString());
22+
productInfo.push(
23+
{
24+
'id': $(this).data('productId').toString()
25+
}
26+
);
2127
});
2228

2329
return productIds();

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ define([
6767
sidebar._removeItemAfter(elem);
6868
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
6969
expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:removeFromCart', {
70-
'productIds': ['5']
70+
'productIds': ['5'], 'productInfo': [{
71+
'id': '5'
72+
}]
7173
});
7274
});
7375

0 commit comments

Comments
 (0)