addio-admin-sdk 1.7.103 → 1.7.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/dist/Interfaces/Attribute/index.d.ts +1 -0
  2. package/dist/Interfaces/CMS/index.d.ts +3 -0
  3. package/dist/Interfaces/CMS/index.js +3 -0
  4. package/dist/Interfaces/CMS/index.js.map +1 -1
  5. package/dist/Interfaces/Cart/index.js +6 -2
  6. package/dist/Interfaces/Cart/index.js.map +1 -1
  7. package/dist/Interfaces/CartReservedQuantities/index.d.ts +2 -0
  8. package/dist/Interfaces/Customer/IStoreCredit.d.ts +1 -0
  9. package/dist/Interfaces/Customer/index.d.ts +7 -0
  10. package/dist/Interfaces/Customer/index.js +7 -0
  11. package/dist/Interfaces/Customer/index.js.map +1 -1
  12. package/dist/Interfaces/Declination/index.js +8 -2
  13. package/dist/Interfaces/Declination/index.js.map +1 -1
  14. package/dist/Interfaces/Email/IEmail.js +7 -3
  15. package/dist/Interfaces/Email/IEmail.js.map +1 -1
  16. package/dist/Interfaces/G2/index.js +2 -0
  17. package/dist/Interfaces/G2/index.js.map +1 -1
  18. package/dist/Interfaces/Indexed/Product/index.d.ts +3 -0
  19. package/dist/Interfaces/Indexed/Product/index.js +43 -2
  20. package/dist/Interfaces/Indexed/Product/index.js.map +1 -1
  21. package/dist/Interfaces/Menu/index.d.ts +11 -0
  22. package/dist/Interfaces/Product/IImportProduct.js +94 -3
  23. package/dist/Interfaces/Product/IImportProduct.js.map +1 -1
  24. package/dist/Interfaces/Product/IInventoryItem.d.ts +11 -27
  25. package/dist/Interfaces/Product/IInventoryItem.js +13 -4
  26. package/dist/Interfaces/Product/IInventoryItem.js.map +1 -1
  27. package/dist/Interfaces/Product/IPricing.js +6 -0
  28. package/dist/Interfaces/Product/IPricing.js.map +1 -1
  29. package/dist/Interfaces/Product/index.d.ts +8 -0
  30. package/dist/Interfaces/Product/index.js +8 -0
  31. package/dist/Interfaces/Product/index.js.map +1 -1
  32. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +1 -1
  33. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js.map +1 -1
  34. package/dist/Interfaces/Rules/IDiscountRule.d.ts +18 -0
  35. package/dist/Interfaces/Rules/IDiscountRule.js +19 -0
  36. package/dist/Interfaces/Rules/IDiscountRule.js.map +1 -1
  37. package/dist/Interfaces/Services/IService.d.ts +4 -0
  38. package/dist/Interfaces/Shipping/Shiptime/order.js +23 -0
  39. package/dist/Interfaces/Shipping/Shiptime/order.js.map +1 -1
  40. package/dist/Interfaces/Space/index.d.ts +8 -0
  41. package/dist/Interfaces/Space/index.js +9 -0
  42. package/dist/Interfaces/Space/index.js.map +1 -1
  43. package/dist/Interfaces/TCG/index.d.ts +12 -1
  44. package/dist/Interfaces/TCG/index.js +11 -0
  45. package/dist/Interfaces/TCG/index.js.map +1 -1
  46. package/dist/Interfaces/TransferRequest/index.js +3 -0
  47. package/dist/Interfaces/TransferRequest/index.js.map +1 -1
  48. package/dist/constants/services.js +1 -0
  49. package/dist/constants/services.js.map +1 -1
  50. package/dist/index.d.ts +18 -0
  51. package/dist/index.js +24 -0
  52. package/dist/index.js.map +1 -1
  53. package/dist/lib/Attribute/index.js +43 -0
  54. package/dist/lib/Attribute/index.js.map +1 -1
  55. package/dist/lib/BGJob/index.js +5 -1
  56. package/dist/lib/BGJob/index.js.map +1 -1
  57. package/dist/lib/Booking/index.d.ts +15 -0
  58. package/dist/lib/Booking/index.js +20 -0
  59. package/dist/lib/Booking/index.js.map +1 -1
  60. package/dist/lib/Brand/index.d.ts +9 -0
  61. package/dist/lib/Brand/index.js +18 -0
  62. package/dist/lib/Brand/index.js.map +1 -1
  63. package/dist/lib/Cart/index.d.ts +99 -0
  64. package/dist/lib/Cart/index.js +498 -9
  65. package/dist/lib/Cart/index.js.map +1 -1
  66. package/dist/lib/CartReservedQuantities/index.d.ts +29 -0
  67. package/dist/lib/CartReservedQuantities/index.js +41 -0
  68. package/dist/lib/CartReservedQuantities/index.js.map +1 -1
  69. package/dist/lib/Catalogue/index.d.ts +6 -0
  70. package/dist/lib/Catalogue/index.js +9 -0
  71. package/dist/lib/Catalogue/index.js.map +1 -1
  72. package/dist/lib/Category/index.d.ts +6 -0
  73. package/dist/lib/Category/index.js +15 -0
  74. package/dist/lib/Category/index.js.map +1 -1
  75. package/dist/lib/Class/index.d.ts +4 -0
  76. package/dist/lib/Class/index.js +8 -0
  77. package/dist/lib/Class/index.js.map +1 -1
  78. package/dist/lib/Customer/index.d.ts +12 -0
  79. package/dist/lib/Customer/index.js +13 -0
  80. package/dist/lib/Customer/index.js.map +1 -1
  81. package/dist/lib/Declination/index.js +2 -0
  82. package/dist/lib/Declination/index.js.map +1 -1
  83. package/dist/lib/Discount/index.d.ts +9 -0
  84. package/dist/lib/Discount/index.js +23 -0
  85. package/dist/lib/Discount/index.js.map +1 -1
  86. package/dist/lib/ElasticSearch/index.d.ts +5 -0
  87. package/dist/lib/ElasticSearch/index.js +5 -0
  88. package/dist/lib/ElasticSearch/index.js.map +1 -1
  89. package/dist/lib/Elavon/index.js +5 -0
  90. package/dist/lib/Elavon/index.js.map +1 -1
  91. package/dist/lib/Email/AbandonedCartEmail.d.ts +8 -0
  92. package/dist/lib/Email/AbandonedCartEmail.js +8 -0
  93. package/dist/lib/Email/AbandonedCartEmail.js.map +1 -1
  94. package/dist/lib/Email/AccountConfirmationEmail.d.ts +8 -0
  95. package/dist/lib/Email/AccountConfirmationEmail.js +8 -0
  96. package/dist/lib/Email/AccountConfirmationEmail.js.map +1 -1
  97. package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +8 -0
  98. package/dist/lib/Email/AdminOrderConfirmationEmail.js +8 -0
  99. package/dist/lib/Email/AdminOrderConfirmationEmail.js.map +1 -1
  100. package/dist/lib/Email/ApplicationEmail.d.ts +8 -0
  101. package/dist/lib/Email/ApplicationEmail.js +8 -0
  102. package/dist/lib/Email/ApplicationEmail.js.map +1 -1
  103. package/dist/lib/Email/BackInStockEmail.d.ts +8 -0
  104. package/dist/lib/Email/BackInStockEmail.js +8 -0
  105. package/dist/lib/Email/BackInStockEmail.js.map +1 -1
  106. package/dist/lib/Email/ContactEmail.d.ts +8 -0
  107. package/dist/lib/Email/ContactEmail.js +8 -0
  108. package/dist/lib/Email/ContactEmail.js.map +1 -1
  109. package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +8 -0
  110. package/dist/lib/Email/CustomerBookingAdminEmail.js +8 -0
  111. package/dist/lib/Email/CustomerBookingAdminEmail.js.map +1 -1
  112. package/dist/lib/Email/CustomerBookingEmail.d.ts +8 -0
  113. package/dist/lib/Email/CustomerBookingEmail.js +8 -0
  114. package/dist/lib/Email/CustomerBookingEmail.js.map +1 -1
  115. package/dist/lib/Email/OrderConfirmationEmail.d.ts +8 -0
  116. package/dist/lib/Email/OrderConfirmationEmail.js +8 -0
  117. package/dist/lib/Email/OrderConfirmationEmail.js.map +1 -1
  118. package/dist/lib/Email/OrderDenounciationEmail.d.ts +8 -0
  119. package/dist/lib/Email/OrderDenounciationEmail.js +8 -0
  120. package/dist/lib/Email/OrderDenounciationEmail.js.map +1 -1
  121. package/dist/lib/Email/OrderSampleEmail.d.ts +8 -0
  122. package/dist/lib/Email/OrderSampleEmail.js +8 -0
  123. package/dist/lib/Email/OrderSampleEmail.js.map +1 -1
  124. package/dist/lib/Email/OtherTypeEmails.d.ts +8 -0
  125. package/dist/lib/Email/OtherTypeEmails.js +8 -0
  126. package/dist/lib/Email/OtherTypeEmails.js.map +1 -1
  127. package/dist/lib/Email/PasswordResetEmail.d.ts +8 -0
  128. package/dist/lib/Email/PasswordResetEmail.js +8 -0
  129. package/dist/lib/Email/PasswordResetEmail.js.map +1 -1
  130. package/dist/lib/Email/PhotoShootEmail.d.ts +8 -0
  131. package/dist/lib/Email/PhotoShootEmail.js +8 -0
  132. package/dist/lib/Email/PhotoShootEmail.js.map +1 -1
  133. package/dist/lib/Email/PickUpConfirmation.d.ts +8 -0
  134. package/dist/lib/Email/PickUpConfirmation.js +8 -0
  135. package/dist/lib/Email/PickUpConfirmation.js.map +1 -1
  136. package/dist/lib/Email/ShippingConfirmation.d.ts +8 -0
  137. package/dist/lib/Email/ShippingConfirmation.js +8 -0
  138. package/dist/lib/Email/ShippingConfirmation.js.map +1 -1
  139. package/dist/lib/Email/WelcomeEmail.d.ts +8 -0
  140. package/dist/lib/Email/WelcomeEmail.js +8 -0
  141. package/dist/lib/Email/WelcomeEmail.js.map +1 -1
  142. package/dist/lib/Email/index.d.ts +8 -0
  143. package/dist/lib/Email/index.js +8 -0
  144. package/dist/lib/Email/index.js.map +1 -1
  145. package/dist/lib/ExternalService/Ebay.d.ts +12 -0
  146. package/dist/lib/ExternalService/Ebay.js +22 -0
  147. package/dist/lib/ExternalService/Ebay.js.map +1 -1
  148. package/dist/lib/Indexed/IndexedCart.js +5 -0
  149. package/dist/lib/Indexed/IndexedCart.js.map +1 -1
  150. package/dist/lib/Indexed/Product.js +50 -0
  151. package/dist/lib/Indexed/Product.js.map +1 -1
  152. package/dist/lib/Inventory/index.d.ts +59 -0
  153. package/dist/lib/Inventory/index.js +157 -9
  154. package/dist/lib/Inventory/index.js.map +1 -1
  155. package/dist/lib/Invoice/index.d.ts +11 -0
  156. package/dist/lib/Invoice/index.js +11 -0
  157. package/dist/lib/Invoice/index.js.map +1 -1
  158. package/dist/lib/MarketplacePublication/index.js +308 -0
  159. package/dist/lib/MarketplacePublication/index.js.map +1 -1
  160. package/dist/lib/Menu/index.js +2 -0
  161. package/dist/lib/Menu/index.js.map +1 -1
  162. package/dist/lib/Order/index.d.ts +20 -0
  163. package/dist/lib/Order/index.js +23 -0
  164. package/dist/lib/Order/index.js.map +1 -1
  165. package/dist/lib/Org/index.d.ts +41 -0
  166. package/dist/lib/Org/index.js +41 -0
  167. package/dist/lib/Org/index.js.map +1 -1
  168. package/dist/lib/PandaPay/index.js +6 -0
  169. package/dist/lib/PandaPay/index.js.map +1 -1
  170. package/dist/lib/Paysafe/index.js +1 -0
  171. package/dist/lib/Paysafe/index.js.map +1 -1
  172. package/dist/lib/Product/index.d.ts +25 -0
  173. package/dist/lib/Product/index.js +55 -1
  174. package/dist/lib/Product/index.js.map +1 -1
  175. package/dist/lib/PromiseToPurchase/index.d.ts +72 -0
  176. package/dist/lib/PromiseToPurchase/index.js +79 -0
  177. package/dist/lib/PromiseToPurchase/index.js.map +1 -1
  178. package/dist/lib/PurchaseOrder/index.d.ts +11 -0
  179. package/dist/lib/PurchaseOrder/index.js +12 -0
  180. package/dist/lib/PurchaseOrder/index.js.map +1 -1
  181. package/dist/lib/Service/index.d.ts +8 -0
  182. package/dist/lib/Service/index.js +8 -0
  183. package/dist/lib/Service/index.js.map +1 -1
  184. package/dist/lib/Shipment/index.js +13 -0
  185. package/dist/lib/Shipment/index.js.map +1 -1
  186. package/dist/lib/Slider/index.d.ts +6 -0
  187. package/dist/lib/Slider/index.js +6 -0
  188. package/dist/lib/Slider/index.js.map +1 -1
  189. package/dist/lib/Space/index.d.ts +178 -0
  190. package/dist/lib/Space/index.js +495 -6
  191. package/dist/lib/Space/index.js.map +1 -1
  192. package/dist/lib/Supplier/index.js +5 -0
  193. package/dist/lib/Supplier/index.js.map +1 -1
  194. package/dist/lib/Tags/index.js +5 -0
  195. package/dist/lib/Tags/index.js.map +1 -1
  196. package/dist/lib/TransferRequest/index.d.ts +178 -0
  197. package/dist/lib/TransferRequest/index.js +236 -4
  198. package/dist/lib/TransferRequest/index.js.map +1 -1
  199. package/dist/lib/User/index.d.ts +54 -0
  200. package/dist/lib/User/index.js +101 -21
  201. package/dist/lib/User/index.js.map +1 -1
  202. package/dist/lib/baseService.js +26 -0
  203. package/dist/lib/baseService.js.map +1 -1
  204. package/dist/rules/GR/constants/data.js +22 -0
  205. package/dist/rules/GR/constants/data.js.map +1 -1
  206. package/dist/rules/GR/constants/products.d.ts +3 -0
  207. package/dist/rules/GR/constants/products.js +16 -0
  208. package/dist/rules/GR/constants/products.js.map +1 -1
  209. package/dist/rules/GR/interfaces/data.js +7 -1
  210. package/dist/rules/GR/interfaces/data.js.map +1 -1
  211. package/dist/rules/GR/utils/cart.d.ts +41 -0
  212. package/dist/rules/GR/utils/cart.js +107 -1
  213. package/dist/rules/GR/utils/cart.js.map +1 -1
  214. package/dist/rules/GR/utils/data.js +4 -1
  215. package/dist/rules/GR/utils/data.js.map +1 -1
  216. package/dist/rules/GR/utils/expedition.d.ts +69 -0
  217. package/dist/rules/GR/utils/expedition.js +399 -11
  218. package/dist/rules/GR/utils/expedition.js.map +1 -1
  219. package/dist/rules/GR/utils/g2.d.ts +33 -0
  220. package/dist/rules/GR/utils/g2.js +135 -3
  221. package/dist/rules/GR/utils/g2.js.map +1 -1
  222. package/dist/rules/GR/utils/invoices.d.ts +27 -0
  223. package/dist/rules/GR/utils/invoices.js +41 -0
  224. package/dist/rules/GR/utils/invoices.js.map +1 -1
  225. package/dist/rules/GR/utils/products.d.ts +161 -0
  226. package/dist/rules/GR/utils/products.js +272 -1
  227. package/dist/rules/GR/utils/products.js.map +1 -1
  228. package/dist/rules/GR/utils/upsells.d.ts +32 -0
  229. package/dist/rules/GR/utils/upsells.js +32 -0
  230. package/dist/rules/GR/utils/upsells.js.map +1 -1
  231. package/dist/services/database/DatabaseService.d.ts +84 -0
  232. package/dist/services/database/DatabaseService.js +85 -0
  233. package/dist/services/database/DatabaseService.js.map +1 -1
  234. package/dist/services/database/FirebaseProvider.js +17 -0
  235. package/dist/services/database/FirebaseProvider.js.map +1 -1
  236. package/dist/services/database/NotFirebaseProvider.d.ts +14 -0
  237. package/dist/services/database/NotFirebaseProvider.js +19 -0
  238. package/dist/services/database/NotFirebaseProvider.js.map +1 -1
  239. package/dist/services/g2/G2OrderSlip.d.ts +7 -0
  240. package/dist/services/g2/G2OrderSlip.js +18 -0
  241. package/dist/services/g2/G2OrderSlip.js.map +1 -1
  242. package/dist/services/g2/utils.d.ts +10 -0
  243. package/dist/services/g2/utils.js +189 -3
  244. package/dist/services/g2/utils.js.map +1 -1
  245. package/dist/services/logs/index.d.ts +3 -0
  246. package/dist/services/logs/index.js +6 -1
  247. package/dist/services/logs/index.js.map +1 -1
  248. package/dist/services/products/BaseClass.js +2 -0
  249. package/dist/services/products/BaseClass.js.map +1 -1
  250. package/dist/services/products/TCGService.js +17 -1
  251. package/dist/services/products/TCGService.js.map +1 -1
  252. package/dist/services/products/utils.d.ts +22 -0
  253. package/dist/services/products/utils.js +50 -0
  254. package/dist/services/products/utils.js.map +1 -1
  255. package/dist/utils/anonymisation.d.ts +24 -0
  256. package/dist/utils/anonymisation.js +30 -0
  257. package/dist/utils/anonymisation.js.map +1 -1
  258. package/dist/utils/aws.d.ts +22 -0
  259. package/dist/utils/aws.js +28 -0
  260. package/dist/utils/aws.js.map +1 -1
  261. package/dist/utils/booking.d.ts +8 -0
  262. package/dist/utils/booking.js +9 -0
  263. package/dist/utils/booking.js.map +1 -1
  264. package/dist/utils/cart.d.ts +81 -0
  265. package/dist/utils/cart.js +172 -9
  266. package/dist/utils/cart.js.map +1 -1
  267. package/dist/utils/context.js +2 -2
  268. package/dist/utils/context.js.map +1 -1
  269. package/dist/utils/currency.js +31 -1
  270. package/dist/utils/currency.js.map +1 -1
  271. package/dist/utils/data.js +2 -0
  272. package/dist/utils/data.js.map +1 -1
  273. package/dist/utils/discount.d.ts +118 -0
  274. package/dist/utils/discount.js +178 -1
  275. package/dist/utils/discount.js.map +1 -1
  276. package/dist/utils/file-admin.js +1 -0
  277. package/dist/utils/file-admin.js.map +1 -1
  278. package/dist/utils/file.js +9 -1
  279. package/dist/utils/file.js.map +1 -1
  280. package/dist/utils/firebase-admin.d.ts +9 -0
  281. package/dist/utils/firebase-admin.js +12 -0
  282. package/dist/utils/firebase-admin.js.map +1 -1
  283. package/dist/utils/firebase.d.ts +17 -0
  284. package/dist/utils/firebase.js +17 -0
  285. package/dist/utils/firebase.js.map +1 -1
  286. package/dist/utils/inventories.d.ts +52 -0
  287. package/dist/utils/inventories.js +77 -2
  288. package/dist/utils/inventories.js.map +1 -1
  289. package/dist/utils/locale.d.ts +9 -0
  290. package/dist/utils/locale.js +9 -0
  291. package/dist/utils/locale.js.map +1 -1
  292. package/dist/utils/mailchimp.js +36 -0
  293. package/dist/utils/mailchimp.js.map +1 -1
  294. package/dist/utils/mathUtils.js +9 -0
  295. package/dist/utils/mathUtils.js.map +1 -1
  296. package/dist/utils/object.d.ts +19 -0
  297. package/dist/utils/object.js +21 -3
  298. package/dist/utils/object.js.map +1 -1
  299. package/dist/utils/products.d.ts +7 -0
  300. package/dist/utils/products.js +9 -0
  301. package/dist/utils/products.js.map +1 -1
  302. package/dist/utils/promiseToPurchase.d.ts +32 -0
  303. package/dist/utils/promiseToPurchase.js +34 -0
  304. package/dist/utils/promiseToPurchase.js.map +1 -1
  305. package/dist/utils/prosprsearch.d.ts +15 -0
  306. package/dist/utils/prosprsearch.js +15 -0
  307. package/dist/utils/prosprsearch.js.map +1 -1
  308. package/dist/utils/sdc.js +7 -0
  309. package/dist/utils/sdc.js.map +1 -1
  310. package/dist/utils/searchIndexes.d.ts +37 -0
  311. package/dist/utils/searchIndexes.js +37 -0
  312. package/dist/utils/searchIndexes.js.map +1 -1
  313. package/dist/utils/string.js +7 -6
  314. package/dist/utils/string.js.map +1 -1
  315. package/dist/utils/tools.d.ts +4 -0
  316. package/dist/utils/tools.js +4 -0
  317. package/dist/utils/tools.js.map +1 -1
  318. package/dist/utils/transferRequests.d.ts +24 -0
  319. package/dist/utils/transferRequests.js +24 -0
  320. package/dist/utils/transferRequests.js.map +1 -1
  321. package/dist/utils/update.js +12 -0
  322. package/dist/utils/update.js.map +1 -1
  323. package/package.json +1 -1
@@ -50,10 +50,13 @@ const updateCartItems = async (currentCart, items, fetchInventory, shouldCheckIn
50
50
  }
51
51
  if (!!inventoryItem) {
52
52
  const webStore = inventoryItem.web_inventory;
53
+ // If the item is NOT infinite_stock ans is NOT a service
53
54
  if (!!!inventoryItem.is_infinite_stock && !!!cartItem.is_service) {
55
+ // If webstore is not defined or the avaibility = 0
54
56
  if (!!!webStore || !!!webStore.available) {
55
57
  continue;
56
58
  }
59
+ // If the quantity we are setting is more than the available qte of the item
57
60
  if (item.qte > webStore.available) {
58
61
  if (!!handleInventoryError) {
59
62
  await handleInventoryError(true);
@@ -74,6 +77,16 @@ const updateCartItems = async (currentCart, items, fetchInventory, shouldCheckIn
74
77
  return { updatedCart, updatedItems };
75
78
  };
76
79
  exports.updateCartItems = updateCartItems;
80
+ /**
81
+ * For now, copy of `updateCartItems` function in most aspects, with slight optim. Meant to replace updateCartItems eventually!
82
+ * Verify a list of items that could be added to a cart. Returns the list of items to update as well as the updated cart data.
83
+ * @param currentCart
84
+ * @param items
85
+ * @param fetchInventory
86
+ * @param options.shouldCheckInventory
87
+ * @param options.handleInventoryError
88
+ * @param options.shouldCheckStoreInventory
89
+ */
77
90
  const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetchInventory, options = {}) => {
78
91
  let updatedCartItems = [...currentCartItems];
79
92
  const updatedDetails = [];
@@ -90,6 +103,7 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
90
103
  console.log('error on fetching inventoryItem: ', e);
91
104
  }
92
105
  if (!!inventoryItem) {
106
+ // Check store inventory if specified, or default to web inventory
93
107
  let inventoryToCheck;
94
108
  if (options.shouldCheckStoreInventory) {
95
109
  const sameStoreInventory = inventoryItem.inventories.find((i) => i.store_id == options.shouldCheckStoreInventory);
@@ -100,6 +114,7 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
100
114
  else {
101
115
  inventoryToCheck = (0, object_1.recursiveCheckObject)(inventoryItem, 'web_inventory.available');
102
116
  }
117
+ // If no inventory found, continue
103
118
  if (typeof inventoryToCheck == 'undefined') {
104
119
  updatedDetails.push({
105
120
  sku: item.sku,
@@ -107,7 +122,9 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
107
122
  });
108
123
  continue;
109
124
  }
125
+ // If the item is NOT infinite_stock ans is NOT a service
110
126
  if (!!!inventoryItem.is_infinite_stock && !!!cartItem.is_service) {
127
+ // If the avaibility = 0
111
128
  if (!inventoryToCheck) {
112
129
  updatedDetails.push({
113
130
  sku: item.sku,
@@ -115,6 +132,7 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
115
132
  });
116
133
  continue;
117
134
  }
135
+ // If the quantity we are setting is more than the available qte of the item
118
136
  if (item.qte > inventoryToCheck) {
119
137
  if (!!options.handleInventoryError) {
120
138
  await options.handleInventoryError(true);
@@ -152,9 +170,9 @@ const priceWasOverridden = (itemToCheck) => {
152
170
  exports.priceWasOverridden = priceWasOverridden;
153
171
  const getActualPromoPrice = (item, output) => {
154
172
  const orgPrice = (0, exports.getActualDiscountPrice)(item, '$');
155
- let price = orgPrice;
173
+ let price = orgPrice; // default value
156
174
  if (!!item.promo_price) {
157
- price = item.promo_price.amount;
175
+ price = item.promo_price.amount; // this is the first promo
158
176
  }
159
177
  if (output === '%')
160
178
  return !!!orgPrice ? 0 : (1 - price / orgPrice) * 100;
@@ -162,20 +180,28 @@ const getActualPromoPrice = (item, output) => {
162
180
  };
163
181
  exports.getActualPromoPrice = getActualPromoPrice;
164
182
  const getActualDiscountPrice = (item, output) => {
165
- let price = item.regular_price.amount;
183
+ let price = item.regular_price.amount; // default value
166
184
  if (!!item.discount_price) {
167
- price = item.discount_price.amount;
185
+ price = item.discount_price.amount; // this is the first promo
168
186
  }
169
187
  if (output === '%')
170
188
  return (1 - price / item.regular_price.amount) * 100;
171
189
  return price;
172
190
  };
173
191
  exports.getActualDiscountPrice = getActualDiscountPrice;
192
+ /**
193
+ * Generate a cart item from corresonding indexedProduct
194
+ * @param indexedProduct
195
+ * @param sku
196
+ * @param qte
197
+ */
174
198
  const generateCartItemForSku = async (indexedProduct, sku, qte) => {
175
199
  try {
200
+ // Isolate decli with corresponding sku
176
201
  const sameDecli = indexedProduct.declinations.find((d) => d.sku == sku);
177
202
  if (!sameDecli)
178
203
  throw new Error('Could not find decli in product!');
204
+ // Construct CartItem from decli and prod values
179
205
  let decliImgs = sameDecli.images_path;
180
206
  if (!decliImgs || decliImgs.length == 0) {
181
207
  const parentImgs = indexedProduct.image_files;
@@ -212,8 +238,10 @@ const addCartItems = async (currentCart, newItems, fetchInventory, shouldCheckIn
212
238
  }
213
239
  const itemAlreadyInCart = (0, findIndex_1.default)(newCart.items, (item) => item.sku === cartItem.sku);
214
240
  if (!!checkInventory) {
241
+ // If inventory not found, return error
215
242
  if (!!!inventoryItem)
216
243
  return 'already_max_qte';
244
+ // If the webstore is not defined or the avaibility = 0
217
245
  if (!!inventoryItem.is_infinite_stock || !!cartItem.is_service || !!cartItem.is_sample)
218
246
  return cartItem;
219
247
  if (!!!inventoryItem.web_inventory || !!!inventoryItem.web_inventory.available) {
@@ -223,6 +251,7 @@ const addCartItems = async (currentCart, newItems, fetchInventory, shouldCheckIn
223
251
  return 'already_max_qte';
224
252
  }
225
253
  if (itemAlreadyInCart !== -1 && !!!isServiceUpsellOfSku) {
254
+ // If the quantity we are adding is more than the available qte of the item
226
255
  if (!!shouldCheckInventory && !!inventoryItem.web_inventory && !!inventoryItem.web_inventory.available) {
227
256
  if ((0, toNumber_1.default)(newCart.items[itemAlreadyInCart].qte) + (0, toNumber_1.default)(cartItem.qte) >
228
257
  (0, toNumber_1.default)(inventoryItem.web_inventory.available)) {
@@ -272,6 +301,14 @@ const addCartItems = async (currentCart, newItems, fetchInventory, shouldCheckIn
272
301
  };
273
302
  };
274
303
  exports.addCartItems = addCartItems;
304
+ /**
305
+ * Optimized copy of addCartItems function for now. Will eventually replace addCartItems.
306
+ * Verify a list of items to be potentially added to cart.
307
+ * @param currentCart
308
+ * @param newItems
309
+ * @param fetchInventory
310
+ * @param options
311
+ */
275
312
  const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInventory, options = {}) => {
276
313
  let newCart = Object.assign({}, currentCart);
277
314
  let items = [...newItems];
@@ -292,10 +329,13 @@ const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInv
292
329
  }
293
330
  const itemAlreadyInCart = (0, findIndex_1.default)(newCart.items, (item) => item.sku === cartItem.sku);
294
331
  if (!!checkInventory) {
332
+ // If inventory not found, return error
295
333
  if (!!!inventoryItem)
296
334
  return 'inventory_not_found';
335
+ // Check if item's inventory is not followed (if item is a service, a sample, etc...). Skip check if true
297
336
  if (inventoryItem.is_infinite_stock || cartItem.is_service || cartItem.is_sample)
298
337
  return cartItem;
338
+ // Check store inventory if specified, or default to web inventory
299
339
  let inventoryToCheck;
300
340
  if (options.shouldCheckStoreInventory) {
301
341
  const sameStoreInventory = inventoryItem.inventories.find((i) => i.store_id == options.shouldCheckStoreInventory);
@@ -306,13 +346,16 @@ const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInv
306
346
  else {
307
347
  inventoryToCheck = (0, object_1.recursiveCheckObject)(inventoryItem, 'web_inventory.available');
308
348
  }
349
+ // If no inventory found, return false
309
350
  if (typeof inventoryToCheck == 'undefined') {
310
351
  return 'inventory_not_found';
311
352
  }
312
353
  if (cartItem.qte > inventoryToCheck) {
313
354
  return 'already_max_qte';
314
355
  }
356
+ // If item already in cart
315
357
  if (itemAlreadyInCart !== -1 && !!!options.isServiceUpsellOfSku) {
358
+ // If the quantity we are adding is more than the available qte of the item
316
359
  if (!!options.shouldCheckInventory && !!inventoryToCheck) {
317
360
  if ((0, toNumber_1.default)(newCart.items[itemAlreadyInCart].qte) + (0, toNumber_1.default)(cartItem.qte) > (0, toNumber_1.default)(inventoryToCheck)) {
318
361
  return 'already_max_qte';
@@ -360,6 +403,7 @@ const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInv
360
403
  };
361
404
  };
362
405
  exports.verifyAndReturnToBeAddedCartItems = verifyAndReturnToBeAddedCartItems;
406
+ // Get province from province array with english, french or abbreviation
363
407
  const getCurrentProvince = (provinceToCheck) => {
364
408
  let formattedProvince = (0, string_1.stripAccents)(provinceToCheck.toLowerCase());
365
409
  return (0, find_1.default)(data_1.provinces, (province) => (0, string_1.stripAccents)(province.value.toLowerCase()) === formattedProvince ||
@@ -378,6 +422,17 @@ const getTaxProvinceFromShippingAddress = (address) => {
378
422
  return taxProvince;
379
423
  };
380
424
  exports.getTaxProvinceFromShippingAddress = getTaxProvinceFromShippingAddress;
425
+ /**
426
+ * Constructs and returns data for indexed cart (algolia or addio)
427
+ * @param cartData - Current cart data
428
+ * @param space - Space object
429
+ * @param options.setPaidAtIfUndefined - Optionnal - If true, will set paid_at with current date
430
+ * @param options.customer - Optionnal - If defined, adds info based on customer to indexedCart
431
+ * @param option.createdAt - Optionnal - If defined, added to indexedCart, else null value added
432
+ * @param option.updatedAt - Optionnal - If defined, added to indexedCart, else null value added
433
+ * @param associatedTransfers - Optionnal, used to pass transfers and statuses to indexed cart. Will only be added if cart's has_transfers prop is true
434
+ * @returns <IIndexedCart>
435
+ */
381
436
  const getIndexedCartData = (cartData, space, options = {}) => {
382
437
  var _a, _b, _c, _d, _e;
383
438
  const getPaidAt = () => {
@@ -402,6 +457,7 @@ const getIndexedCartData = (cartData, space, options = {}) => {
402
457
  : {}));
403
458
  }
404
459
  const cartPromos = (0, discount_1.getCartPromo)(cartData);
460
+ // If the cart has a promo applied with a promo code, or a discount on a product added via the POS, save info to index
405
461
  let hasPromos = !!cartPromos && !!cartPromos.length;
406
462
  let hasCustomDiscount = !!cartData.items.some((i) => !!(0, object_1.recursiveCheckObject)(i, 'promo_price.authorization.note') ||
407
463
  !!(0, object_1.recursiveCheckObject)(i, 'discount_price.authorization.note'));
@@ -413,7 +469,26 @@ const getIndexedCartData = (cartData, space, options = {}) => {
413
469
  ? (0, moment_1.default)((0, data_1.formatDate)(cartData.processed_by.date)).unix()
414
470
  : null }, (typeof cartData.to_be_verified_by_clerk !== 'undefined'
415
471
  ? { to_be_verified_by_clerk: cartData.to_be_verified_by_clerk }
416
- : {})), { cart_promos_applied: cartPromos !== null && cartPromos !== void 0 ? cartPromos : null, has_promos: !!hasPromos ? hasPromos : null, has_custom_discount: !!hasCustomDiscount ? hasCustomDiscount : null, items: itemDict, is_booking: !!cartData.is_booking, is_promise_to_purchase: !!cartData.promise_to_purchase, has_transfers: !!cartData.has_transfers && !!options.associatedTransfers ? options.associatedTransfers : undefined }), getPaidAt()), (0, exports.getPaidByForIndexedCart)(cartData)), { subtotal: cartData.subtotal, total: cartData.total, is_pickup: !!cartData.is_pickup, out_of_zone: !!cartData.shipping_payload && !!cartData.shipping_payload.isOutOfArea, billing_phone: cartData.billing_address ? cartData.billing_address.expedition_recipient_phone : null, shipping_phone: cartData.shipping_address ? cartData.shipping_address.expedition_recipient_phone : null, customer_id: !!cartData.customer_id ? cartData.customer_id : null, customer_name: cartData.billing_address ? cartData.billing_address.expedition_recipient_name : null, customer_email: cartData.customer_info && cartData.customer_info.customer_default_email
472
+ : {})), {
473
+ // --------------------------------
474
+ // #region PROMOS
475
+ cart_promos_applied: cartPromos !== null && cartPromos !== void 0 ? cartPromos : null, has_promos: !!hasPromos ? hasPromos : null, has_custom_discount: !!hasCustomDiscount ? hasCustomDiscount : null,
476
+ // #endregion
477
+ // --------------------------------
478
+ // #region ITEMS AND SPECIFIC TYPES
479
+ items: itemDict, is_booking: !!cartData.is_booking, is_promise_to_purchase: !!cartData.promise_to_purchase,
480
+ // #endregion
481
+ // --------------------------------
482
+ // #region TRANSFERS
483
+ has_transfers: !!cartData.has_transfers && !!options.associatedTransfers ? options.associatedTransfers : undefined }), getPaidAt()), (0, exports.getPaidByForIndexedCart)(cartData)), { subtotal: cartData.subtotal, total: cartData.total,
484
+ // #endregions
485
+ // --------------------------------
486
+ // #region EXPEDITION
487
+ is_pickup: !!cartData.is_pickup, out_of_zone: !!cartData.shipping_payload && !!cartData.shipping_payload.isOutOfArea, billing_phone: cartData.billing_address ? cartData.billing_address.expedition_recipient_phone : null, shipping_phone: cartData.shipping_address ? cartData.shipping_address.expedition_recipient_phone : null,
488
+ // #endregion
489
+ // --------------------------------
490
+ // #region CUSTOMER
491
+ customer_id: !!cartData.customer_id ? cartData.customer_id : null, customer_name: cartData.billing_address ? cartData.billing_address.expedition_recipient_name : null, customer_email: cartData.customer_info && cartData.customer_info.customer_default_email
417
492
  ? cartData.customer_info.customer_default_email
418
493
  : cartData.user_email
419
494
  ? cartData.user_email
@@ -427,7 +502,11 @@ const getIndexedCartData = (cartData, space, options = {}) => {
427
502
  ? Cart_1.CartCustomerEnum.CONNECTED
428
503
  : Cart_1.CartCustomerEnum.GUEST, customer_rep: !!options.customer ? options.customer.represented_by : null, customer_external_class: (0, object_1.recursiveCheckObject)(cartData, 'customer_info.customer_external_class') ||
429
504
  (0, object_1.recursiveCheckObject)(options.customer, 'basic_info.customer_professionnal_info.external_customer_class') ||
430
- null, keywords: (0, uniq_1.default)((0, flatten_1.default)(cartData.items.map((item) => {
505
+ null,
506
+ // #endregion
507
+ // --------------------------------
508
+ // #region SEO / MARKETING
509
+ keywords: (0, uniq_1.default)((0, flatten_1.default)(cartData.items.map((item) => {
431
510
  return [...(item.name || []).map((n) => n.value), item.sku];
432
511
  }))), cart_slug_list: (0, uniq_1.default)(cartData.items.map((item) => {
433
512
  return item.parent_slug || '';
@@ -437,7 +516,9 @@ const getIndexedCartData = (cartData, space, options = {}) => {
437
516
  frOnly: true,
438
517
  slugSafe: (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.BOOKING_BETON, cartData),
439
518
  installAsType: true
440
- }) }, (0, exports.getAssignedToInfo)(cartData)), { project_number: (_e = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.orderOrProjectNumber')) !== null && _e !== void 0 ? _e : null }) : {})) : {}));
519
+ }) }, (0, exports.getAssignedToInfo)(cartData)), { project_number: (_e = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.orderOrProjectNumber')) !== null && _e !== void 0 ? _e : null }) : {})) : {})
520
+ // #endregion
521
+ );
441
522
  return indexedCartData;
442
523
  };
443
524
  exports.getIndexedCartData = getIndexedCartData;
@@ -447,6 +528,7 @@ const getPaidByForIndexedCart = (order) => {
447
528
  const currentPaidBy = !!order.custom_payment_type && !!order.custom_payment_type.method
448
529
  ? order.custom_payment_type.method
449
530
  : order.paid_by;
531
+ // If order has multiple payment types...
450
532
  if (currentPaidBy === Cart_1.PaymentTypeEnum.MULTIPLE && !!order.payment_details && !!order.payment_details.length) {
451
533
  const firstPayment = order.payment_details.length === 1 || order.payment_details[0].method !== Cart_1.PaymentTypeEnum.TOBERECEIVED
452
534
  ? order.payment_details[0]
@@ -499,6 +581,7 @@ const checkIfShippingSameAsBilling = (cart) => {
499
581
  };
500
582
  exports.checkIfShippingSameAsBilling = checkIfShippingSameAsBilling;
501
583
  const getOrderStoreInfo = (spaceData, storeAddress) => {
584
+ // Pour algo, si informations du store correspondant non-trouvés, renvoit un 'all' pour qu'il affiche tout le temps
502
585
  const defaultStoreInfo = {
503
586
  id: 'all',
504
587
  name: 'all'
@@ -525,12 +608,15 @@ const getModifiedItems = (newItems, oldItems) => {
525
608
  let itemsForInventory = [];
526
609
  for (const i of newItems) {
527
610
  const itemInOldArray = oldItems.find((o) => o.sku === i.sku);
611
+ // If the item was not in the old cart, keep all its info
528
612
  if (!!!itemInOldArray) {
529
613
  itemsForInventory = [...itemsForInventory, i];
530
614
  continue;
531
615
  }
616
+ // If the item is the same in the old cart and in the new one, do nothing
532
617
  if (i.qte === itemInOldArray.qte)
533
618
  continue;
619
+ // If we are here, it means the item is still in the cart, but it's quantities changed. If the new qte is smaller, the new qte will be negative to add items back to inventory
534
620
  const newQte = i.qte - itemInOldArray.qte;
535
621
  itemsForInventory = [
536
622
  ...itemsForInventory,
@@ -539,6 +625,7 @@ const getModifiedItems = (newItems, oldItems) => {
539
625
  }
540
626
  for (const i of oldItems) {
541
627
  const itemInNewArray = newItems.find((o) => o.sku === i.sku);
628
+ // If the item used to be in the cart, but is no longer there, save all it's quantity as negative to put it back in the inventory
542
629
  if (!!!itemInNewArray) {
543
630
  itemsForInventory = [
544
631
  ...itemsForInventory,
@@ -549,6 +636,11 @@ const getModifiedItems = (newItems, oldItems) => {
549
636
  return itemsForInventory;
550
637
  };
551
638
  exports.getModifiedItems = getModifiedItems;
639
+ /**
640
+ * Get all active transfers for a cart where given items are found
641
+ * @param allTransfersForCart All transfers associated to a given cart
642
+ * @param cartItems All cart items for whitch to check transfers if found
643
+ */
552
644
  const getActiveTransfersByItemInCart = (allTransfersForCart, cartItems) => {
553
645
  if (!!!allTransfersForCart || !!!allTransfersForCart.length)
554
646
  return [];
@@ -569,11 +661,23 @@ const getActiveTransfersByItemInCart = (allTransfersForCart, cartItems) => {
569
661
  return foundInTransfer;
570
662
  };
571
663
  exports.getActiveTransfersByItemInCart = getActiveTransfersByItemInCart;
664
+ /**
665
+ * Get the sale unit slug for a cart item
666
+ *
667
+ * @param item the cart item
668
+ * @returns unit slug or empty if not found
669
+ */
572
670
  const getItemSaleUnitSlug = (item) => {
573
671
  const unit = (item.other_units || []).find((x) => x.is_sale_unit);
574
672
  return unit ? unit.unit_slug : '';
575
673
  };
576
674
  exports.getItemSaleUnitSlug = getItemSaleUnitSlug;
675
+ /**
676
+ * Constructs an object for each transfer, with corresponding products to update and by which quantity
677
+ * @param allCartTransfers All transfer objects associated to a given cart
678
+ * @param updatedItems Array of pertinent data per item updated to determine which transfers to update quantities for
679
+ * @returns {TransfersWithItemsToUpdate | undefined}
680
+ */
577
681
  const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
578
682
  if (!!!allCartTransfers.length || !!!updatedItems.length)
579
683
  return;
@@ -591,8 +695,10 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
591
695
  const filteredInventoriesByTransferStores = !!upItem.inventoryItem
592
696
  ? upItem.inventoryItem.inventories.filter((i) => transfersWithSameItem.some((t) => !!t.data().from && t.data().from == i.store_id))
593
697
  : undefined;
698
+ // A. If quantities are to be added...
594
699
  if (qteToUpdate > 0) {
595
700
  const inventoryUnitQteToUpdate = (0, inventories_1.getConvertedUnitQuantity)(upItem.item.other_units, qteToUpdate, 'inventory_unit', true);
701
+ // A1. ... If some transfers are currently at status INITIALIZED (with no "from" store set), add to first initialized found (since quantities can be redistributed by store when opening transfer)
596
702
  const initializedStatusTransfers = transfersWithSameItem.filter((t) => t.data().status == TransferRequest_1.TransferRequestStatusEnum.INITIATED);
597
703
  if (!!initializedStatusTransfers.length) {
598
704
  const firstTransfer = initializedStatusTransfers[0];
@@ -607,6 +713,9 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
607
713
  transfersToUpdate[transferID] = dataForTransfer;
608
714
  continue;
609
715
  }
716
+ // A2. ... Else, add to transfer where store has most quantities
717
+ // TODO - Should we check if quantities are available in store before adding to transfer ?
718
+ // TODO - Maybe based on if property space.options.transfer_requests.dont_limit_qty ?
610
719
  const storeWithMostQuantities = !!filteredInventoriesByTransferStores
611
720
  ? filteredInventoriesByTransferStores.reduce((storeA, storeB) => (0, toNumber_1.default)(storeA.qty.available) > (0, toNumber_1.default)(storeB.qty.available) ? storeA : storeB)
612
721
  : undefined;
@@ -620,8 +729,10 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
620
729
  transfersToUpdate[transferToUse.data().id] = dataForTransfer;
621
730
  continue;
622
731
  }
732
+ // B. If quantities are to be removed...
623
733
  if (qteToUpdate < 0) {
624
- let qteToRemove = qteToUpdate * -1;
734
+ // ... remove from all transfers until done, starting with transfers at status INITIALIZED, then by the store with the least quantities currently available
735
+ let qteToRemove = qteToUpdate * -1; // change to positive value to facilitate checks later. Will be changed to negative when saved in qteToUpdate props for each transfer
625
736
  let inventoryUnitQteToRemove = (0, inventories_1.getConvertedUnitQuantity)(upItem.item.other_units, qteToRemove, 'inventory_unit', true);
626
737
  const inventoriesByAvailabilityAsc = (0, orderBy_1.default)(filteredInventoriesByTransferStores, (i) => (0, toNumber_1.default)(i.qty.available));
627
738
  const transfersByInventory = (0, orderBy_1.default)(transfersWithSameItem, (t) => [
@@ -637,7 +748,7 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
637
748
  const currentQte = sameProd.qte;
638
749
  const qteToBeUpdated = currentQte < inventoryUnitQteToRemove ? currentQte : inventoryUnitQteToRemove;
639
750
  const dataForTransfer = transfersToUpdate[transfer.data().id] || [];
640
- dataForTransfer.push({ sku, ajustmentQte: qteToBeUpdated == 0 ? qteToBeUpdated : qteToBeUpdated * -1 });
751
+ dataForTransfer.push({ sku, ajustmentQte: qteToBeUpdated == 0 ? qteToBeUpdated : qteToBeUpdated * -1 }); // value changed back to a negative here
641
752
  transfersToUpdate[transfer.data().id] = dataForTransfer;
642
753
  inventoryUnitQteToRemove -= qteToBeUpdated;
643
754
  if (qteToRemove <= 0)
@@ -660,6 +771,7 @@ const getILangForUpdateType = (updateType) => {
660
771
  };
661
772
  exports.getILangForUpdateType = getILangForUpdateType;
662
773
  const getSubtotalToCheckForPromo = (allCartItems, currentCartSubtotal, space, feePromosTotalRemoved, removeServiceFees) => {
774
+ // ** NEW - Now excludes escompte supp. products from services when checking subtotal for promotions
663
775
  const serviceFeeProducts = !!!removeServiceFees
664
776
  ? []
665
777
  : allCartItems.filter((i) => !!i.is_service && !(0, g2_1.isEscompteSuppItem)(i.sku));
@@ -670,9 +782,11 @@ const getSubtotalToCheckForPromo = (allCartItems, currentCartSubtotal, space, fe
670
782
  return (0, round_1.default)(((0, isNumber_1.default)(itemPrice) ? Number(itemPrice) : 0) * i.qte, space.data().product_preferences.decimals || 2);
671
783
  });
672
784
  let totalRemoved = serviceFeeSubtotal;
785
+ // If there is a service and fees total, calculates the service and fees total after taking into account their promos
673
786
  if (!!totalRemoved) {
674
787
  totalRemoved -= feePromosTotalRemoved;
675
788
  }
789
+ // Removes that calculated total from the current subtotal to get the subtotal without services and fees, in order to calculate the right promo amount
676
790
  return currentCartSubtotal - totalRemoved;
677
791
  };
678
792
  exports.getSubtotalToCheckForPromo = getSubtotalToCheckForPromo;
@@ -680,7 +794,15 @@ const getAllPromoAppliedPrices = (allPromos, subtotalToUse, items, space, isRefu
680
794
  var _a;
681
795
  let promoAmounts = [];
682
796
  let updatedSubtotal = subtotalToUse;
797
+ // REMOVE PAYMENT INCENTIVE PROMOS FROM ARRAY
798
+ // Since this type of promos ('total_after_taxes') must be calculated and
799
+ // removed from total amount AFTER shipping and taxes are calculated,
800
+ // they will be dealt with later in process and must not count in "subtotalWithoutPromotions" prop
683
801
  let cartPromos = allPromos.filter((c) => c.applies_to != Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
802
+ // REORDER PROMOS
803
+ // a. if promos apply to products, bring to front of array
804
+ // b. if promos contain a promo_code that applies to subtotal,
805
+ // push it to the end of the array to check that one last
684
806
  cartPromos = (0, orderBy_1.default)(cartPromos, (p) => {
685
807
  if ([Cart_1.CartPromoAppliesToEnum.PRODUCT, Cart_1.CartPromoAppliesToEnum.ITEMS].includes(p.applies_to))
686
808
  return 1;
@@ -724,6 +846,7 @@ const getAllPromoAppliedPrices = (allPromos, subtotalToUse, items, space, isRefu
724
846
  else {
725
847
  amountToRemove = (_a = aPromo.amount_removed) !== null && _a !== void 0 ? _a : 0;
726
848
  }
849
+ // round amountToRemove before removing from subtotal
727
850
  amountToRemove = (0, round_1.default)(amountToRemove, 2);
728
851
  const newSubtotal = amountUnit === IDiscountRule_1.ResultActionEnum.AMOUNT || aPromo.applies_to === Cart_1.CartPromoAppliesToEnum.PRODUCT
729
852
  ? updatedSubtotal - amountToRemove
@@ -751,6 +874,10 @@ const getAddressStrArray = (address) => {
751
874
  ].filter((addr) => !!addr.trim());
752
875
  };
753
876
  exports.getAddressStrArray = getAddressStrArray;
877
+ /**
878
+ * Returns all payement methods for a given cart
879
+ * @param cartData
880
+ */
754
881
  const getCartPaymentMethods = (cartData) => {
755
882
  return !!cartData.payment_details
756
883
  ? (cartData.payment_details || []).map((p) => p.method)
@@ -759,9 +886,15 @@ const getCartPaymentMethods = (cartData) => {
759
886
  : [];
760
887
  };
761
888
  exports.getCartPaymentMethods = getCartPaymentMethods;
889
+ /**
890
+ * Return last user to take payment for cart. Checks in order : 'completed_by' -> 'updated_by' -> 'processed_by' -> 'created_by'
891
+ * @param cartData The cart to check
892
+ * @param startCheckAt The step to start check at. Defaults to 'processed_by'
893
+ */
762
894
  const getLastUserWhoTookPayment = (cartData, startCheckAt = 'processed_by') => {
763
895
  let foundUser = undefined;
764
896
  let allSteps = ['completed_by', 'updated_by', 'processed_by', 'created_by'];
897
+ // Splice original array to only keep entries from specified startCheckAt property
765
898
  allSteps.splice(allSteps.indexOf(startCheckAt));
766
899
  const checkCartProp = (property) => {
767
900
  const foundData = cartData[property];
@@ -780,6 +913,14 @@ const getLastUserWhoTookPayment = (cartData, startCheckAt = 'processed_by') => {
780
913
  return foundUser;
781
914
  };
782
915
  exports.getLastUserWhoTookPayment = getLastUserWhoTookPayment;
916
+ // #region CUSTOM PRICES AND ESCOMPTES (added by POS)
917
+ /**
918
+ * Calculates applied amout for a custom added promo.
919
+ * @param item Cart item on which custom promo was applied
920
+ * @param type The custom promo type (unit price of added escompte)
921
+ * @param amount The fixed amount or percentage of custom price allocated
922
+ * @returns {number}
923
+ */
783
924
  const calculateAmountForCustomPromo = (item, type, amount) => {
784
925
  if (type === Cart_1.CustomPromoType.UNIT_PRICE)
785
926
  return amount;
@@ -788,6 +929,15 @@ const calculateAmountForCustomPromo = (item, type, amount) => {
788
929
  return initialPrice - promoAmount;
789
930
  };
790
931
  exports.calculateAmountForCustomPromo = calculateAmountForCustomPromo;
932
+ // #endregion
933
+ // #region STORE CREDIT MANAGEMENT
934
+ /**
935
+ * Check if credit quantity for cart is valid and available.
936
+ * @param creditToBeUsedInCart Amount to be used in credits.
937
+ * @param customerID The customer's ID to check for available store credits.
938
+ * @param space The current space obj
939
+ * @param creditSlug La référence au type de store credit à vérifier
940
+ */
791
941
  const validateStoreCreditUsage = async (creditToBeUsedInCart, customerID, space, creditSlug) => {
792
942
  const hasStoreCreditsSet = space.options.checkIfOptionIsSet('payment.space_has_store_credits');
793
943
  if (!hasStoreCreditsSet) {
@@ -809,7 +959,10 @@ const validateStoreCreditUsage = async (creditToBeUsedInCart, customerID, space,
809
959
  };
810
960
  }
811
961
  const creditAmount = creditToBeUsedInCart !== null && creditToBeUsedInCart !== void 0 ? creditToBeUsedInCart : 0;
962
+ // VALIDATIONS
963
+ // a. Valide que le crédit demandé est positif
812
964
  let valid = creditAmount >= 0;
965
+ // b. Valide que le client a le reste nécessaire pour utiliser ses crédits comme mode de paiement
813
966
  if (valid) {
814
967
  let clientCheck = await space.customers.credits.validate(customerID, creditSlug, creditAmount);
815
968
  valid = !clientCheck;
@@ -824,14 +977,24 @@ const validateStoreCreditUsage = async (creditToBeUsedInCart, customerID, space,
824
977
  : {}));
825
978
  };
826
979
  exports.validateStoreCreditUsage = validateStoreCreditUsage;
980
+ // #endregion
981
+ /**
982
+ * Get total quantity of pallets purchased by a customer
983
+ * @param space - Space object
984
+ * @param customerId - Customer ID
985
+ * @returns Total quantity of pallets purchased
986
+ */
827
987
  const getPurchasedPalletsQuantityForCustomer = async (space, customerId) => {
828
988
  const palletSku = '210000000';
829
989
  const completedStatus = Cart_1.CartStatusEnum.COMPLETED;
830
990
  try {
991
+ // 1. Get search index info for the space
831
992
  const searchInfo = (0, searchIndexes_1.getFetchInfoAlgoliaAddioSearch)(space);
993
+ // 2. Fetch indexed completed orders for this customer that contain the pallet SKU (from 2026-01-01)
832
994
  const startDate = (0, moment_1.default)('2026-01-01');
833
995
  const endDate = (0, moment_1.default)();
834
996
  const filterStr = `customer_id:${customerId} AND status:${completedStatus} AND (created_at:${startDate.unix()} TO ${endDate.unix()}) AND (items.${palletSku}.refunded:false OR items.${palletSku}.refunded:true)`;
997
+ // 3. Fetch all pages and sum pallet quantities
835
998
  let totalPallets = 0;
836
999
  let currentPage = 0;
837
1000
  let nbPages = 1;