fields-definition.js 1.1 KB

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