Skip to content

Commit 083e741

Browse files
authored
Merge pull request #5801 from magento-tsg/2.4.0-develop-pr56
[TSG] Fixes for 2.4 (pr56) (2.4.0-develop)
2 parents f984c47 + e116d2c commit 083e741

File tree

7 files changed

+263
-12
lines changed

7 files changed

+263
-12
lines changed

app/code/Magento/Catalog/Controller/Category/View.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ protected function _initCategory()
205205
/**
206206
* Category view action
207207
*
208-
* @return ResultInterface
209208
* @throws NoSuchEntityException
210209
*/
211-
public function execute(): ?ResultInterface
210+
public function execute()
212211
{
213212
$result = null;
214213

app/code/Magento/Checkout/view/frontend/web/js/empty-cart.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
define([
7-
'Magento_Customer/js/customer-data'
8-
], function (customerData) {
6+
define(['Magento_Customer/js/customer-data'], function (customerData) {
97
'use strict';
108

11-
var cartData = customerData.get('cart');
9+
return function () {
10+
var cartData = customerData.get('cart');
1211

13-
if (cartData().items && cartData().items.length !== 0) {
14-
customerData.reload(['cart'], false);
15-
}
12+
customerData.getInitCustomerData().done(function () {
13+
if (cartData().items && cartData().items.length !== 0) {
14+
customerData.reload(['cart'], false);
15+
}
16+
});
17+
};
1618
});

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ define([
2424
invalidateCacheByCloseCookieSession,
2525
dataProvider,
2626
buffer,
27-
customerData;
27+
customerData,
28+
deferred = $.Deferred();
2829

2930
url.setBaseUrl(window.BASE_URL);
3031
options.sectionLoadUrl = url.build('customer/section/load');
@@ -341,6 +342,15 @@ define([
341342
$.cookieStorage.set('section_data_ids', sectionDataIds);
342343
},
343344

345+
/**
346+
* Checks if customer data is initialized.
347+
*
348+
* @returns {jQuery.Deferred}
349+
*/
350+
getInitCustomerData: function () {
351+
return deferred.promise();
352+
},
353+
344354
/**
345355
* @param {Object} settings
346356
* @constructor
@@ -350,6 +360,7 @@ define([
350360
invalidateCacheBySessionTimeOut(settings);
351361
invalidateCacheByCloseCookieSession();
352362
customerData.init();
363+
deferred.resolve();
353364
}
354365
};
355366

app/code/Magento/Multishipping/view/frontend/templates/checkout/addresses.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
?>
1717
<form id="checkout_multishipping_form"
1818
data-mage-init='{
19-
"multiShipping":{},
19+
"multiShipping": {"itemsQty": <?= /* @noEscape */ (int)$block->getCheckout()->getQuote()->getItemsSummaryQty() ?>},
2020
"cartUpdate": {
2121
"validationURL": "<?= $block->escapeUrl($block->getUrl('multishipping/checkout/checkItems')) ?>",
2222
"eventName": "updateMulticartItemQty"

app/code/Magento/Multishipping/view/frontend/web/js/multi-shipping.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
define([
77
'jquery',
8+
'Magento_Customer/js/customer-data',
89
'jquery-ui-modules/widget'
9-
], function ($) {
10+
], function ($, customerData) {
1011
'use strict';
1112

1213
$.widget('mage.multiShipping', {
1314
options: {
15+
itemsQty: 0,
1416
addNewAddressBtn: 'button[data-role="add-new-address"]', // Add a new multishipping address.
1517
addNewAddressFlag: '#add_new_address_flag', // Hidden input field with value 0 or 1.
1618
canContinueBtn: 'button[data-role="can-continue"]', // Continue (update quantity or go to shipping).
@@ -22,10 +24,24 @@ define([
2224
* @private
2325
*/
2426
_create: function () {
27+
this._prepareCartData();
2528
$(this.options.addNewAddressBtn).on('click', $.proxy(this._addNewAddress, this));
2629
$(this.options.canContinueBtn).on('click', $.proxy(this._canContinue, this));
2730
},
2831

32+
/**
33+
* Takes cart items qty from current cart data and compare it with current items qty
34+
* Reloads cart data if cart items qty is wrong
35+
* @private
36+
*/
37+
_prepareCartData: function () {
38+
var cartData = customerData.get('cart');
39+
40+
if (cartData()['summary_count'] !== this.options.itemsQty) {
41+
customerData.reload(['cart'], false);
42+
}
43+
},
44+
2945
/**
3046
* Add a new address. Set the hidden input field and submit the form. Then enter a new shipping address.
3147
* @private
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable max-nested-callbacks */
7+
/*jscs:disable jsDoc*/
8+
define([
9+
'squire', 'jquery', 'ko'
10+
], function (Squire, $, ko) {
11+
'use strict';
12+
13+
describe('Magento_Checkout/js/empty-cart', function () {
14+
var injector = new Squire(),
15+
cartData = ko.observable({}),
16+
mocks = {
17+
'Magento_Customer/js/customer-data': {
18+
get: jasmine.createSpy('get', function () {
19+
return cartData;
20+
}).and.callThrough(),
21+
reload: jasmine.createSpy(),
22+
getInitCustomerData: function () {}
23+
}
24+
},
25+
deferred,
26+
emptyCart;
27+
28+
beforeEach(function (done) {
29+
injector.mock(mocks);
30+
injector.require(['Magento_Checkout/js/empty-cart'], function (instance) {
31+
emptyCart = instance;
32+
done();
33+
});
34+
});
35+
36+
afterEach(function () {
37+
try {
38+
injector.clean();
39+
injector.remove();
40+
} catch (e) {}
41+
42+
cartData({});
43+
});
44+
45+
describe('Check Cart data preparation process', function () {
46+
it('Tests that Cart data is NOT checked before initialization', function () {
47+
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () {
48+
deferred = $.Deferred();
49+
50+
return deferred.promise();
51+
});
52+
expect(emptyCart()).toBe(undefined);
53+
54+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
55+
expect(mocks['Magento_Customer/js/customer-data'].getInitCustomerData).toHaveBeenCalled();
56+
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled();
57+
});
58+
59+
it('Tests that Cart data does NOT reload if there are no items in it', function () {
60+
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () {
61+
deferred = $.Deferred();
62+
63+
deferred.resolve();
64+
65+
return deferred.promise();
66+
});
67+
cartData({
68+
items: []
69+
});
70+
emptyCart();
71+
72+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
73+
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled();
74+
});
75+
76+
it('Tests that Cart data is checked only after initialization', function () {
77+
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () {
78+
deferred = $.Deferred();
79+
80+
return deferred.promise();
81+
});
82+
cartData({
83+
items: [1]
84+
});
85+
emptyCart();
86+
87+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
88+
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled();
89+
90+
deferred.resolve();
91+
92+
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalledWith(['cart'], false);
93+
});
94+
95+
it('Tests that Cart data reloads if it has items', function () {
96+
spyOn(mocks['Magento_Customer/js/customer-data'], 'getInitCustomerData').and.callFake(function () {
97+
deferred = $.Deferred();
98+
99+
deferred.resolve();
100+
101+
return deferred.promise();
102+
});
103+
cartData({
104+
items: [1]
105+
});
106+
emptyCart();
107+
108+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
109+
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalledWith(['cart'], false);
110+
});
111+
});
112+
});
113+
});
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
'multiShipping'
12+
], function (Squire, $, ko, MultiShipping) {
13+
'use strict';
14+
15+
describe('Magento_Multishipping/js/multi-shipping', function () {
16+
var injector = new Squire(),
17+
Obj;
18+
19+
describe('Check Cart data preparation process', function () {
20+
var customerData = ko.observable({}),
21+
mocks = {
22+
'Magento_Customer/js/customer-data': {
23+
get: jasmine.createSpy('get', function () {
24+
return customerData;
25+
}).and.callThrough(),
26+
reload: jasmine.createSpy()
27+
}
28+
},
29+
summaryCount = {};
30+
31+
beforeEach(function (done) {
32+
injector.mock(mocks);
33+
injector.require(['multiShipping'], function (Instance) {
34+
Obj = Instance;
35+
done();
36+
});
37+
});
38+
39+
afterEach(function () {
40+
try {
41+
injector.clean();
42+
injector.remove();
43+
} catch (e) {}
44+
45+
customerData({});
46+
});
47+
48+
it('Prepare Cart data with the same items qty', function () {
49+
summaryCount['summary_count'] = 0;
50+
customerData(summaryCount);
51+
new Obj({});
52+
53+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
54+
expect(mocks['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled();
55+
});
56+
57+
it('Prepare Cart data with different items qty', function () {
58+
summaryCount['summary_count'] = 1;
59+
customerData(summaryCount);
60+
new Obj({});
61+
62+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
63+
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalledWith(['cart'], false);
64+
});
65+
});
66+
67+
describe('Check Multishipping events', function () {
68+
var addNewAddressBtn,
69+
addressflag,
70+
canContinueBtn,
71+
canContinueFlag;
72+
73+
beforeEach(function () {
74+
addNewAddressBtn = $('<button type="button" data-role="add-new-address"/>');
75+
addressflag = $('<input type="hidden" value="0" id="add_new_address_flag"/>');
76+
canContinueBtn = $('<button type="submit" data-role="can-continue" data-flag="1"/>');
77+
canContinueFlag = $('<input type="hidden" value="0" id="can_continue_flag"/>');
78+
$(document.body).append(addNewAddressBtn)
79+
.append(addressflag)
80+
.append(canContinueBtn)
81+
.append(canContinueFlag);
82+
});
83+
84+
afterEach(function () {
85+
addNewAddressBtn.remove();
86+
addressflag.remove();
87+
canContinueBtn.remove();
88+
canContinueFlag.remove();
89+
});
90+
91+
it('Check add new address event', function () {
92+
Obj = new MultiShipping({});
93+
Obj.element = jasmine.createSpyObj('element', ['submit']);
94+
addNewAddressBtn.click();
95+
96+
expect(Obj.element.submit).toHaveBeenCalled();
97+
expect(addressflag.val()).toBe('1');
98+
});
99+
100+
it('Check can continue event', function () {
101+
Obj = new MultiShipping({});
102+
Obj.element = jasmine.createSpyObj('element', ['submit']);
103+
canContinueBtn.click();
104+
105+
expect(Obj.element.submit).not.toHaveBeenCalled();
106+
expect(canContinueFlag.val()).toBe('1');
107+
});
108+
});
109+
});
110+
});

0 commit comments

Comments
 (0)