1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
*/
define([
'underscore',
'ko',
'Magento_Customer/js/customer-data'
], function (_, ko, customerData) {
'use strict';
var cacheKey = 'checkout-fields';
return {
getFields: function () {
var sectionData = customerData.get(cacheKey);
_.each(sectionData().fields, function (field) {
if ((field.value === undefined) && field.defaultValue) {
field.value = field.defaultValue;
}
});
return sectionData().fields;
},
updateFieldValue: function (fieldId, fieldValue) {
var sectionData = customerData.get(cacheKey);
if (fieldValue === undefined) {
fieldValue = '';
}
_.each(sectionData().fields, function (field) {
if (field.id === fieldId) {
field.value = fieldValue;
}
});
customerData.set(cacheKey, sectionData());
}
};
});