Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

301 строка
8.1 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /**
  6. * Checkout adapter for customer data storage
  7. *
  8. * @api
  9. */
  10. define([
  11. 'jquery',
  12. 'Magento_Customer/js/customer-data',
  13. 'mageUtils',
  14. 'jquery/jquery-storageapi'
  15. ], function ($, storage, utils) {
  16. 'use strict';
  17. var cacheKey = 'checkout-data',
  18. /**
  19. * @param {Object} data
  20. */
  21. saveData = function (data) {
  22. storage.set(cacheKey, data);
  23. },
  24. /**
  25. * @return {*}
  26. */
  27. initData = function () {
  28. return {
  29. 'selectedShippingAddress': null, //Selected shipping address pulled from persistence storage
  30. 'shippingAddressFromData': null, //Shipping address pulled from persistence storage
  31. 'newCustomerShippingAddress': null, //Shipping address pulled from persistence storage for customer
  32. 'selectedShippingRate': null, //Shipping rate pulled from persistence storage
  33. 'selectedPaymentMethod': null, //Payment method pulled from persistence storage
  34. 'selectedBillingAddress': null, //Selected billing address pulled from persistence storage
  35. 'billingAddressFromData': null, //Billing address pulled from persistence storage
  36. 'newCustomerBillingAddress': null //Billing address pulled from persistence storage for new customer
  37. };
  38. },
  39. /**
  40. * @return {*}
  41. */
  42. getData = function () {
  43. var data = storage.get(cacheKey)();
  44. if ($.isEmptyObject(data)) {
  45. data = $.initNamespaceStorage('mage-cache-storage').localStorage.get(cacheKey);
  46. if ($.isEmptyObject(data)) {
  47. data = initData();
  48. saveData(data);
  49. }
  50. }
  51. return data;
  52. };
  53. return {
  54. /**
  55. * Setting the selected shipping address pulled from persistence storage
  56. *
  57. * @param {Object} data
  58. */
  59. setSelectedShippingAddress: function (data) {
  60. var obj = getData();
  61. obj.selectedShippingAddress = data;
  62. saveData(obj);
  63. },
  64. /**
  65. * Pulling the selected shipping address from persistence storage
  66. *
  67. * @return {*}
  68. */
  69. getSelectedShippingAddress: function () {
  70. return getData().selectedShippingAddress;
  71. },
  72. /**
  73. * Setting the shipping address pulled from persistence storage
  74. *
  75. * @param {Object} data
  76. */
  77. setShippingAddressFromData: function (data) {
  78. var obj = getData();
  79. obj.shippingAddressFromData = utils.filterFormData(data);
  80. saveData(obj);
  81. },
  82. /**
  83. * Pulling the shipping address from persistence storage
  84. *
  85. * @return {*}
  86. */
  87. getShippingAddressFromData: function () {
  88. return getData().shippingAddressFromData;
  89. },
  90. /**
  91. * Setting the shipping address pulled from persistence storage for new customer
  92. *
  93. * @param {Object} data
  94. */
  95. setNewCustomerShippingAddress: function (data) {
  96. var obj = getData();
  97. obj.newCustomerShippingAddress = data;
  98. saveData(obj);
  99. },
  100. /**
  101. * Pulling the shipping address from persistence storage for new customer
  102. *
  103. * @return {*}
  104. */
  105. getNewCustomerShippingAddress: function () {
  106. return getData().newCustomerShippingAddress;
  107. },
  108. /**
  109. * Setting the selected shipping rate pulled from persistence storage
  110. *
  111. * @param {Object} data
  112. */
  113. setSelectedShippingRate: function (data) {
  114. var obj = getData();
  115. obj.selectedShippingRate = data;
  116. saveData(obj);
  117. },
  118. /**
  119. * Pulling the selected shipping rate from local storage
  120. *
  121. * @return {*}
  122. */
  123. getSelectedShippingRate: function () {
  124. return getData().selectedShippingRate;
  125. },
  126. /**
  127. * Setting the selected payment method pulled from persistence storage
  128. *
  129. * @param {Object} data
  130. */
  131. setSelectedPaymentMethod: function (data) {
  132. var obj = getData();
  133. obj.selectedPaymentMethod = data;
  134. saveData(obj);
  135. },
  136. /**
  137. * Pulling the payment method from persistence storage
  138. *
  139. * @return {*}
  140. */
  141. getSelectedPaymentMethod: function () {
  142. return getData().selectedPaymentMethod;
  143. },
  144. /**
  145. * Setting the selected billing address pulled from persistence storage
  146. *
  147. * @param {Object} data
  148. */
  149. setSelectedBillingAddress: function (data) {
  150. var obj = getData();
  151. obj.selectedBillingAddress = data;
  152. saveData(obj);
  153. },
  154. /**
  155. * Pulling the selected billing address from persistence storage
  156. *
  157. * @return {*}
  158. */
  159. getSelectedBillingAddress: function () {
  160. return getData().selectedBillingAddress;
  161. },
  162. /**
  163. * Setting the billing address pulled from persistence storage
  164. *
  165. * @param {Object} data
  166. */
  167. setBillingAddressFromData: function (data) {
  168. var obj = getData();
  169. obj.billingAddressFromData = utils.filterFormData(data);
  170. saveData(obj);
  171. },
  172. /**
  173. * Pulling the billing address from persistence storage
  174. *
  175. * @return {*}
  176. */
  177. getBillingAddressFromData: function () {
  178. return getData().billingAddressFromData;
  179. },
  180. /**
  181. * Setting the billing address pulled from persistence storage for new customer
  182. *
  183. * @param {Object} data
  184. */
  185. setNewCustomerBillingAddress: function (data) {
  186. var obj = getData();
  187. obj.newCustomerBillingAddress = data;
  188. saveData(obj);
  189. },
  190. /**
  191. * Pulling the billing address from persistence storage for new customer
  192. *
  193. * @return {*}
  194. */
  195. getNewCustomerBillingAddress: function () {
  196. return getData().newCustomerBillingAddress;
  197. },
  198. /**
  199. * Pulling the email address from persistence storage
  200. *
  201. * @return {*}
  202. */
  203. getValidatedEmailValue: function () {
  204. var obj = getData();
  205. return obj.validatedEmailValue ? obj.validatedEmailValue : '';
  206. },
  207. /**
  208. * Setting the email address pulled from persistence storage
  209. *
  210. * @param {String} email
  211. */
  212. setValidatedEmailValue: function (email) {
  213. var obj = getData();
  214. obj.validatedEmailValue = email;
  215. saveData(obj);
  216. },
  217. /**
  218. * Pulling the email input field value from persistence storage
  219. *
  220. * @return {*}
  221. */
  222. getInputFieldEmailValue: function () {
  223. var obj = getData();
  224. return obj.inputFieldEmailValue ? obj.inputFieldEmailValue : '';
  225. },
  226. /**
  227. * Setting the email input field value pulled from persistence storage
  228. *
  229. * @param {String} email
  230. */
  231. setInputFieldEmailValue: function (email) {
  232. var obj = getData();
  233. obj.inputFieldEmailValue = email;
  234. saveData(obj);
  235. },
  236. /**
  237. * Pulling the checked email value from persistence storage
  238. *
  239. * @return {*}
  240. */
  241. getCheckedEmailValue: function () {
  242. var obj = getData();
  243. return obj.checkedEmailValue ? obj.checkedEmailValue : '';
  244. },
  245. /**
  246. * Setting the checked email value pulled from persistence storage
  247. *
  248. * @param {String} email
  249. */
  250. setCheckedEmailValue: function (email) {
  251. var obj = getData();
  252. obj.checkedEmailValue = email;
  253. saveData(obj);
  254. }
  255. };
  256. });