Skip to content

Commit c85a0c7

Browse files
committed
Merge branch 'ACP2E-3402' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-VK-2024-11-27-CE
2 parents 88660e7 + 247db9e commit c85a0c7

File tree

2 files changed

+95
-7
lines changed

2 files changed

+95
-7
lines changed

app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2015 Adobe
3+
* All Rights Reserved.
44
*/
55

66
/**
@@ -17,6 +17,7 @@ define([
1717
'use strict';
1818

1919
var cacheKey = 'checkout-data',
20+
storeCode = window.checkoutConfig.storeCode,
2021

2122
/**
2223
* @param {Object} data
@@ -57,6 +58,20 @@ define([
5758
}
5859

5960
return data;
61+
},
62+
getShippingAddressByStore = function (shippingAddressObj) {
63+
if (!shippingAddressObj) {
64+
return null;
65+
}
66+
67+
return shippingAddressObj[storeCode];
68+
},
69+
setShippingAddressByStore = function (shippingAddressObj, data) {
70+
if (!shippingAddressObj) {
71+
shippingAddressObj = {};
72+
}
73+
shippingAddressObj[storeCode] = utils.filterFormData(data);
74+
return shippingAddressObj;
6075
};
6176

6277
return {
@@ -87,9 +102,9 @@ define([
87102
* @param {Object} data
88103
*/
89104
setShippingAddressFromData: function (data) {
90-
var obj = getData();
105+
let obj = getData();
91106

92-
obj.shippingAddressFromData = utils.filterFormData(data);
107+
obj.shippingAddressFromData = setShippingAddressByStore(obj.shippingAddressFromData, data);
93108
saveData(obj);
94109
},
95110

@@ -99,7 +114,7 @@ define([
99114
* @return {*}
100115
*/
101116
getShippingAddressFromData: function () {
102-
return getData().shippingAddressFromData;
117+
return getShippingAddressByStore(getData().shippingAddressFromData);
103118
},
104119

105120
/**
@@ -110,7 +125,7 @@ define([
110125
setNewCustomerShippingAddress: function (data) {
111126
var obj = getData();
112127

113-
obj.newCustomerShippingAddress = data;
128+
obj.newCustomerShippingAddress = setShippingAddressByStore(obj.newCustomerShippingAddress, data);
114129
saveData(obj);
115130
},
116131

@@ -120,7 +135,7 @@ define([
120135
* @return {*}
121136
*/
122137
getNewCustomerShippingAddress: function () {
123-
return getData().newCustomerShippingAddress;
138+
return getShippingAddressByStore(getData().newCustomerShippingAddress);
124139
},
125140

126141
/**
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright 2024 Adobe
3+
* All Rights Reserved.
4+
*/
5+
6+
define([
7+
'squire'
8+
], function (Squire) {
9+
'use strict';
10+
11+
describe('Magento_Checkout/js/checkout-data', function () {
12+
let checkoutData,
13+
cacheKey = 'checkout-data',
14+
testData = {
15+
shippingAddressFromData: {base: {address1: 'address1'}}
16+
},
17+
18+
/** Stub */
19+
getStorageData = function () {
20+
return function () {
21+
return testData;
22+
};
23+
},
24+
injector = new Squire(),
25+
mocks = {
26+
'Magento_Customer/js/customer-data': {
27+
/** Method stub. */
28+
set: jasmine.createSpy(),
29+
get: jasmine.createSpy().and.callFake(getStorageData)
30+
},
31+
'jquery/jquery-storageapi': jasmine.createSpy(),
32+
'mageUtils': jasmine.createSpy()
33+
};
34+
35+
window.checkoutConfig = {
36+
storeCode: 'base'
37+
};
38+
39+
beforeEach(function (done) {
40+
injector.mock(mocks);
41+
injector.require([
42+
'Magento_Checkout/js/checkout-data'
43+
], function (Constructor) {
44+
checkoutData = Constructor;
45+
done();
46+
});
47+
});
48+
49+
it('should save selected shipping address per website', function () {
50+
checkoutData.setShippingAddressFromData({address1: 'address1'});
51+
expect(mocks['Magento_Customer/js/customer-data'].set).
52+
toHaveBeenCalledWith(cacheKey, jasmine.objectContaining(testData));
53+
});
54+
55+
it('should get shipping address from data per website', function () {
56+
let address = checkoutData.getShippingAddressFromData();
57+
58+
expect(address).toEqual(testData.shippingAddressFromData.base);
59+
});
60+
61+
it('should save new customer shipping address per website', function () {
62+
checkoutData.setNewCustomerShippingAddress({address1: 'address1'});
63+
expect(mocks['Magento_Customer/js/customer-data'].set).
64+
toHaveBeenCalledWith(cacheKey, jasmine.objectContaining(testData));
65+
});
66+
67+
it('should get new customer shipping address from data per website', function () {
68+
let address = checkoutData.getNewCustomerShippingAddress();
69+
70+
expect(address).toEqual(testData.shippingAddressFromData.base);
71+
});
72+
});
73+
});

0 commit comments

Comments
 (0)