File tree Expand file tree Collapse file tree 2 files changed +62
-11
lines changed
app/code/Magento/Checkout/view/frontend/web/js
dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view Expand file tree Collapse file tree 2 files changed +62
-11
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * Copyright © Magento, Inc. All rights reserved.
3
- * See COPYING.txt for license details.
4
- */
5
-
6
- /**
7
- * Checkout adapter for customer data storage
8
- *
9
- * @api
2
+ * Copyright 2015 Adobe
3
+ * All Rights Reserved.
10
4
*/
11
5
define ( [
12
6
'jquery' ,
@@ -87,9 +81,13 @@ define([
87
81
* @param {Object } data
88
82
*/
89
83
setShippingAddressFromData : function ( data ) {
90
- var obj = getData ( ) ;
84
+ let obj = getData ( ) ,
85
+ websiteCode = window . checkoutConfig . websiteCode ;
91
86
92
- obj . shippingAddressFromData = utils . filterFormData ( data ) ;
87
+ if ( ! obj . shippingAddressFromData ) {
88
+ obj . shippingAddressFromData = { } ;
89
+ }
90
+ obj . shippingAddressFromData [ websiteCode ] = utils . filterFormData ( data ) ;
93
91
saveData ( obj ) ;
94
92
} ,
95
93
@@ -99,7 +97,13 @@ define([
99
97
* @return {* }
100
98
*/
101
99
getShippingAddressFromData : function ( ) {
102
- return getData ( ) . shippingAddressFromData ;
100
+ let websiteCode = window . checkoutConfig . websiteCode ;
101
+
102
+ if ( ! getData ( ) . shippingAddressFromData ) {
103
+ return null ;
104
+ }
105
+
106
+ return getData ( ) . shippingAddressFromData [ websiteCode ] ;
103
107
} ,
104
108
105
109
/**
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright 2024 Adobe
3
+ * All Rights Reserved.
4
+ */
5
+
6
+ define ( [
7
+ 'Magento_Checkout/js/checkout-data' ,
8
+ 'Magento_Customer/js/customer-data'
9
+ ] , function ( checkoutData , storage ) {
10
+ 'use strict' ;
11
+
12
+ describe ( 'Magento_Checkout/js/checkout-data' , function ( ) {
13
+ let cacheKey = 'checkout-data' ,
14
+ testData = {
15
+ shippingAddressFromData : { base : { address1 : 'address1' } }
16
+ } ,
17
+
18
+ /** Stub */
19
+ getStorageData = function ( ) {
20
+ return testData ;
21
+ } ;
22
+
23
+ window . checkoutConfig = {
24
+ websiteCode : 'base'
25
+ } ;
26
+
27
+ beforeEach ( function ( ) {
28
+ spyOn ( storage , 'set' ) ;
29
+ } ) ;
30
+
31
+ it ( 'should save selected shipping address per website' , function ( ) {
32
+ checkoutData . setShippingAddressFromData ( { address1 : 'address1' } ) ;
33
+ expect ( storage . set ) . toHaveBeenCalledWith ( cacheKey , jasmine . objectContaining ( testData ) ) ;
34
+ } ) ;
35
+
36
+ it ( 'should return null if no shipping address data exists' , function ( ) {
37
+ expect ( checkoutData . getShippingAddressFromData ( ) ) . toBeNull ( ) ;
38
+ } ) ;
39
+
40
+ it ( 'should get shipping address from data per website' , function ( ) {
41
+ spyOn ( storage , 'get' ) . and . returnValue ( getStorageData ) ;
42
+ let address = checkoutData . getShippingAddressFromData ( ) ;
43
+
44
+ expect ( address ) . toEqual ( testData . shippingAddressFromData . base ) ;
45
+ } ) ;
46
+ } ) ;
47
+ } ) ;
You can’t perform that action at this time.
0 commit comments