Skip to content

Commit 56b6f42

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-91712' into 2.3-develop-pr8
2 parents e993e81 + 39f283f commit 56b6f42

File tree

8 files changed

+152
-11
lines changed

8 files changed

+152
-11
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
define([
77
'jquery',
88
'mage/translate',
9+
'underscore',
10+
'Magento_Catalog/js/product/view/product-ids-resolver',
911
'jquery/ui'
10-
], function ($, $t) {
12+
], function ($, $t, _, idsResolver) {
1113
'use strict';
1214

1315
$.widget('mage.catalogAddToCart', {
@@ -76,17 +78,18 @@ define([
7678
/**
7779
* Handler for the form 'submit' event
7880
*
79-
* @param {Object} form
81+
* @param {jQuery} form
8082
*/
8183
submitForm: function (form) {
8284
this.ajaxSubmit(form);
8385
},
8486

8587
/**
86-
* @param {String} form
88+
* @param {jQuery} form
8789
*/
8890
ajaxSubmit: function (form) {
8991
var self = this,
92+
productIds = idsResolver(form),
9093
formData;
9194

9295
$(self.options.minicartSelector).trigger('contentLoading');
@@ -115,6 +118,7 @@ define([
115118

116119
$(document).trigger('ajax:addToCart', {
117120
'sku': form.data().productSku,
121+
'productIds': productIds,
118122
'form': form,
119123
'response': res
120124
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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-ids'
8+
], function (_, productIds) {
9+
'use strict';
10+
11+
/**
12+
* Returns id's of products in form.
13+
*
14+
* @param {jQuery} $form
15+
* @return {Array}
16+
*/
17+
return function ($form) {
18+
var idSet = productIds(),
19+
product = _.findWhere($form.serializeArray(), {
20+
name: 'product'
21+
});
22+
23+
if (!_.isUndefined(product)) {
24+
idSet.push(product.value);
25+
}
26+
27+
return _.uniq(idSet);
28+
};
29+
});
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ define([
226226
var productData = this._getProductById(Number(elem.data('cart-item')));
227227

228228
if (!_.isUndefined(productData)) {
229-
$(document).trigger('ajax:updateCartItemQty', productData['product_sku']);
229+
$(document).trigger('ajax:updateCartItemQty');
230230
}
231231
this._hideItemButton(elem);
232232
},
@@ -253,7 +253,9 @@ define([
253253
var productData = this._getProductById(Number(elem.data('cart-item')));
254254

255255
if (!_.isUndefined(productData)) {
256-
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
256+
$(document).trigger('ajax:removeFromCart', {
257+
productIds: [productData['product_id']]
258+
});
257259
}
258260
},
259261

app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
2020

2121
<div class="table-wrapper grouped">
22-
<table class="table data grouped" id="super-product-table">
22+
<table class="table data grouped"
23+
id="super-product-table"
24+
data-mage-init='{ "Magento_GroupedProduct/js/product-ids-resolver": {} }'>
2325
<caption class="table-caption"><?= /* @escapeNotVerified */ __('Grouped product items') ?></caption>
2426
<thead>
2527
<tr>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'Magento_Catalog/js/product/view/product-ids'
8+
], function ($, productIds) {
9+
'use strict';
10+
11+
/**
12+
* Returns id's of products in form.
13+
*
14+
* @param {Object} config
15+
* @param {HTMLElement} element
16+
* @return {Array}
17+
*/
18+
return function (config, element) {
19+
$(element).find('div[data-product-id]').each(function () {
20+
productIds.push($(this).data('productId').toString());
21+
});
22+
23+
return productIds();
24+
};
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable max-nested-callbacks */
7+
define([
8+
'squire',
9+
'jquery',
10+
'ko',
11+
'jquery/ui'
12+
], function (Squire, $, ko) {
13+
'use strict';
14+
15+
var injector = new Squire(),
16+
mocks = {
17+
'Magento_Catalog/js/product/view/product-ids': ko.observableArray([])
18+
},
19+
form = $(
20+
'<form>' +
21+
'<input type="hidden" name="product" value="1">' +
22+
'</form>'
23+
),
24+
productIdResolver;
25+
26+
beforeAll(function (done) {
27+
28+
injector.mock(mocks);
29+
injector.require(
30+
[
31+
'Magento_Catalog/js/product/view/product-ids-resolver'
32+
], function (resolver) {
33+
productIdResolver = resolver;
34+
done();
35+
}
36+
);
37+
});
38+
39+
describe('Magento_Catalog/js/product/view/product-ids-resolver', function () {
40+
var dataProvider = [
41+
{
42+
ids: [],
43+
expected: ['1']
44+
},
45+
{
46+
ids: ['2', '3'],
47+
expected: ['2', '3', '1']
48+
},
49+
{
50+
ids: ['3', '1', '5'],
51+
expected: ['3', '1', '5']
52+
}
53+
];
54+
55+
dataProvider.forEach(function (data) {
56+
it('resolved product id\'s', function () {
57+
mocks['Magento_Catalog/js/product/view/product-ids'](data.ids);
58+
expect(productIdResolver(form)).toEqual(data.expected);
59+
});
60+
});
61+
});
62+
});

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ define([
2626
'items': [
2727
{
2828
'item_id': 1,
29-
'product_sku': 'bundle'
29+
'product_sku': 'bundle',
30+
'product_id': '1'
3031
},
3132
{
3233
'item_id': 5,
33-
'product_sku': 'simple'
34+
'product_sku': 'simple',
35+
'product_id': '5'
3436
},
3537
{
3638
'item_id': 7,
37-
'product_sku': 'configurable'
39+
'product_sku': 'configurable',
40+
'product_id': '7'
3841
}
3942
]
4043
},
@@ -63,7 +66,9 @@ define([
6366

6467
sidebar._removeItemAfter(elem);
6568
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
66-
expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:removeFromCart', 'simple');
69+
expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:removeFromCart', {
70+
'productIds': ['5']
71+
});
6772
});
6873

6974
it('Cart item doesn\'t exists', function () {
@@ -91,7 +96,7 @@ define([
9196

9297
sidebar._updateItemQtyAfter(elem);
9398
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
94-
expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:updateCartItemQty', 'simple');
99+
expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:updateCartItemQty');
95100
expect(sidebar._hideItemButton).toHaveBeenCalledWith(elem);
96101
});
97102

0 commit comments

Comments
 (0)