addio-admin-sdk 1.7.102 → 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 (325) hide show
  1. package/dist/Interfaces/Algolia/index.d.ts +1 -0
  2. package/dist/Interfaces/Attribute/index.d.ts +1 -0
  3. package/dist/Interfaces/CMS/index.d.ts +3 -0
  4. package/dist/Interfaces/CMS/index.js +3 -0
  5. package/dist/Interfaces/CMS/index.js.map +1 -1
  6. package/dist/Interfaces/Cart/index.d.ts +1 -0
  7. package/dist/Interfaces/Cart/index.js +6 -2
  8. package/dist/Interfaces/Cart/index.js.map +1 -1
  9. package/dist/Interfaces/CartReservedQuantities/index.d.ts +2 -0
  10. package/dist/Interfaces/Customer/IStoreCredit.d.ts +1 -0
  11. package/dist/Interfaces/Customer/index.d.ts +7 -0
  12. package/dist/Interfaces/Customer/index.js +7 -0
  13. package/dist/Interfaces/Customer/index.js.map +1 -1
  14. package/dist/Interfaces/Declination/index.js +8 -2
  15. package/dist/Interfaces/Declination/index.js.map +1 -1
  16. package/dist/Interfaces/Email/IEmail.js +7 -3
  17. package/dist/Interfaces/Email/IEmail.js.map +1 -1
  18. package/dist/Interfaces/G2/index.js +2 -0
  19. package/dist/Interfaces/G2/index.js.map +1 -1
  20. package/dist/Interfaces/Indexed/Product/index.d.ts +3 -0
  21. package/dist/Interfaces/Indexed/Product/index.js +43 -2
  22. package/dist/Interfaces/Indexed/Product/index.js.map +1 -1
  23. package/dist/Interfaces/Menu/index.d.ts +11 -0
  24. package/dist/Interfaces/Product/IImportProduct.js +94 -3
  25. package/dist/Interfaces/Product/IImportProduct.js.map +1 -1
  26. package/dist/Interfaces/Product/IInventoryItem.d.ts +11 -27
  27. package/dist/Interfaces/Product/IInventoryItem.js +13 -4
  28. package/dist/Interfaces/Product/IInventoryItem.js.map +1 -1
  29. package/dist/Interfaces/Product/IPricing.js +6 -0
  30. package/dist/Interfaces/Product/IPricing.js.map +1 -1
  31. package/dist/Interfaces/Product/index.d.ts +8 -0
  32. package/dist/Interfaces/Product/index.js +8 -0
  33. package/dist/Interfaces/Product/index.js.map +1 -1
  34. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +1 -1
  35. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js.map +1 -1
  36. package/dist/Interfaces/Rules/IDiscountRule.d.ts +18 -0
  37. package/dist/Interfaces/Rules/IDiscountRule.js +19 -0
  38. package/dist/Interfaces/Rules/IDiscountRule.js.map +1 -1
  39. package/dist/Interfaces/Services/IService.d.ts +4 -0
  40. package/dist/Interfaces/Shipping/Shiptime/order.js +23 -0
  41. package/dist/Interfaces/Shipping/Shiptime/order.js.map +1 -1
  42. package/dist/Interfaces/Space/index.d.ts +8 -0
  43. package/dist/Interfaces/Space/index.js +9 -0
  44. package/dist/Interfaces/Space/index.js.map +1 -1
  45. package/dist/Interfaces/TCG/index.d.ts +12 -1
  46. package/dist/Interfaces/TCG/index.js +11 -0
  47. package/dist/Interfaces/TCG/index.js.map +1 -1
  48. package/dist/Interfaces/TransferRequest/index.js +3 -0
  49. package/dist/Interfaces/TransferRequest/index.js.map +1 -1
  50. package/dist/constants/services.js +1 -0
  51. package/dist/constants/services.js.map +1 -1
  52. package/dist/index.d.ts +18 -0
  53. package/dist/index.js +24 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/lib/Attribute/index.js +43 -0
  56. package/dist/lib/Attribute/index.js.map +1 -1
  57. package/dist/lib/BGJob/index.js +5 -1
  58. package/dist/lib/BGJob/index.js.map +1 -1
  59. package/dist/lib/Booking/index.d.ts +15 -0
  60. package/dist/lib/Booking/index.js +20 -0
  61. package/dist/lib/Booking/index.js.map +1 -1
  62. package/dist/lib/Brand/index.d.ts +9 -0
  63. package/dist/lib/Brand/index.js +18 -0
  64. package/dist/lib/Brand/index.js.map +1 -1
  65. package/dist/lib/Cart/index.d.ts +99 -0
  66. package/dist/lib/Cart/index.js +498 -9
  67. package/dist/lib/Cart/index.js.map +1 -1
  68. package/dist/lib/CartReservedQuantities/index.d.ts +29 -0
  69. package/dist/lib/CartReservedQuantities/index.js +41 -0
  70. package/dist/lib/CartReservedQuantities/index.js.map +1 -1
  71. package/dist/lib/Catalogue/index.d.ts +6 -0
  72. package/dist/lib/Catalogue/index.js +9 -0
  73. package/dist/lib/Catalogue/index.js.map +1 -1
  74. package/dist/lib/Category/index.d.ts +6 -0
  75. package/dist/lib/Category/index.js +15 -0
  76. package/dist/lib/Category/index.js.map +1 -1
  77. package/dist/lib/Class/index.d.ts +4 -0
  78. package/dist/lib/Class/index.js +8 -0
  79. package/dist/lib/Class/index.js.map +1 -1
  80. package/dist/lib/Customer/index.d.ts +12 -0
  81. package/dist/lib/Customer/index.js +13 -0
  82. package/dist/lib/Customer/index.js.map +1 -1
  83. package/dist/lib/Declination/index.js +2 -0
  84. package/dist/lib/Declination/index.js.map +1 -1
  85. package/dist/lib/Discount/index.d.ts +9 -0
  86. package/dist/lib/Discount/index.js +23 -0
  87. package/dist/lib/Discount/index.js.map +1 -1
  88. package/dist/lib/ElasticSearch/index.d.ts +5 -0
  89. package/dist/lib/ElasticSearch/index.js +5 -0
  90. package/dist/lib/ElasticSearch/index.js.map +1 -1
  91. package/dist/lib/Elavon/index.js +5 -0
  92. package/dist/lib/Elavon/index.js.map +1 -1
  93. package/dist/lib/Email/AbandonedCartEmail.d.ts +8 -0
  94. package/dist/lib/Email/AbandonedCartEmail.js +8 -0
  95. package/dist/lib/Email/AbandonedCartEmail.js.map +1 -1
  96. package/dist/lib/Email/AccountConfirmationEmail.d.ts +8 -0
  97. package/dist/lib/Email/AccountConfirmationEmail.js +8 -0
  98. package/dist/lib/Email/AccountConfirmationEmail.js.map +1 -1
  99. package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +8 -0
  100. package/dist/lib/Email/AdminOrderConfirmationEmail.js +8 -0
  101. package/dist/lib/Email/AdminOrderConfirmationEmail.js.map +1 -1
  102. package/dist/lib/Email/ApplicationEmail.d.ts +8 -0
  103. package/dist/lib/Email/ApplicationEmail.js +8 -0
  104. package/dist/lib/Email/ApplicationEmail.js.map +1 -1
  105. package/dist/lib/Email/BackInStockEmail.d.ts +8 -0
  106. package/dist/lib/Email/BackInStockEmail.js +8 -0
  107. package/dist/lib/Email/BackInStockEmail.js.map +1 -1
  108. package/dist/lib/Email/ContactEmail.d.ts +8 -0
  109. package/dist/lib/Email/ContactEmail.js +8 -0
  110. package/dist/lib/Email/ContactEmail.js.map +1 -1
  111. package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +8 -0
  112. package/dist/lib/Email/CustomerBookingAdminEmail.js +8 -0
  113. package/dist/lib/Email/CustomerBookingAdminEmail.js.map +1 -1
  114. package/dist/lib/Email/CustomerBookingEmail.d.ts +8 -0
  115. package/dist/lib/Email/CustomerBookingEmail.js +8 -0
  116. package/dist/lib/Email/CustomerBookingEmail.js.map +1 -1
  117. package/dist/lib/Email/OrderConfirmationEmail.d.ts +8 -0
  118. package/dist/lib/Email/OrderConfirmationEmail.js +8 -0
  119. package/dist/lib/Email/OrderConfirmationEmail.js.map +1 -1
  120. package/dist/lib/Email/OrderDenounciationEmail.d.ts +8 -0
  121. package/dist/lib/Email/OrderDenounciationEmail.js +8 -0
  122. package/dist/lib/Email/OrderDenounciationEmail.js.map +1 -1
  123. package/dist/lib/Email/OrderSampleEmail.d.ts +8 -0
  124. package/dist/lib/Email/OrderSampleEmail.js +8 -0
  125. package/dist/lib/Email/OrderSampleEmail.js.map +1 -1
  126. package/dist/lib/Email/OtherTypeEmails.d.ts +8 -0
  127. package/dist/lib/Email/OtherTypeEmails.js +8 -0
  128. package/dist/lib/Email/OtherTypeEmails.js.map +1 -1
  129. package/dist/lib/Email/PasswordResetEmail.d.ts +8 -0
  130. package/dist/lib/Email/PasswordResetEmail.js +8 -0
  131. package/dist/lib/Email/PasswordResetEmail.js.map +1 -1
  132. package/dist/lib/Email/PhotoShootEmail.d.ts +8 -0
  133. package/dist/lib/Email/PhotoShootEmail.js +8 -0
  134. package/dist/lib/Email/PhotoShootEmail.js.map +1 -1
  135. package/dist/lib/Email/PickUpConfirmation.d.ts +8 -0
  136. package/dist/lib/Email/PickUpConfirmation.js +8 -0
  137. package/dist/lib/Email/PickUpConfirmation.js.map +1 -1
  138. package/dist/lib/Email/ShippingConfirmation.d.ts +8 -0
  139. package/dist/lib/Email/ShippingConfirmation.js +8 -0
  140. package/dist/lib/Email/ShippingConfirmation.js.map +1 -1
  141. package/dist/lib/Email/WelcomeEmail.d.ts +8 -0
  142. package/dist/lib/Email/WelcomeEmail.js +8 -0
  143. package/dist/lib/Email/WelcomeEmail.js.map +1 -1
  144. package/dist/lib/Email/index.d.ts +8 -0
  145. package/dist/lib/Email/index.js +8 -0
  146. package/dist/lib/Email/index.js.map +1 -1
  147. package/dist/lib/ExternalService/Ebay.d.ts +12 -0
  148. package/dist/lib/ExternalService/Ebay.js +22 -0
  149. package/dist/lib/ExternalService/Ebay.js.map +1 -1
  150. package/dist/lib/Indexed/IndexedCart.js +5 -0
  151. package/dist/lib/Indexed/IndexedCart.js.map +1 -1
  152. package/dist/lib/Indexed/Product.js +50 -0
  153. package/dist/lib/Indexed/Product.js.map +1 -1
  154. package/dist/lib/Inventory/index.d.ts +59 -0
  155. package/dist/lib/Inventory/index.js +157 -9
  156. package/dist/lib/Inventory/index.js.map +1 -1
  157. package/dist/lib/Invoice/index.d.ts +11 -0
  158. package/dist/lib/Invoice/index.js +11 -0
  159. package/dist/lib/Invoice/index.js.map +1 -1
  160. package/dist/lib/MarketplacePublication/index.js +308 -0
  161. package/dist/lib/MarketplacePublication/index.js.map +1 -1
  162. package/dist/lib/Menu/index.js +2 -0
  163. package/dist/lib/Menu/index.js.map +1 -1
  164. package/dist/lib/Order/index.d.ts +20 -0
  165. package/dist/lib/Order/index.js +23 -0
  166. package/dist/lib/Order/index.js.map +1 -1
  167. package/dist/lib/Org/index.d.ts +41 -0
  168. package/dist/lib/Org/index.js +41 -0
  169. package/dist/lib/Org/index.js.map +1 -1
  170. package/dist/lib/PandaPay/index.js +6 -0
  171. package/dist/lib/PandaPay/index.js.map +1 -1
  172. package/dist/lib/Paysafe/index.js +1 -0
  173. package/dist/lib/Paysafe/index.js.map +1 -1
  174. package/dist/lib/Product/index.d.ts +25 -0
  175. package/dist/lib/Product/index.js +55 -1
  176. package/dist/lib/Product/index.js.map +1 -1
  177. package/dist/lib/PromiseToPurchase/index.d.ts +72 -0
  178. package/dist/lib/PromiseToPurchase/index.js +79 -0
  179. package/dist/lib/PromiseToPurchase/index.js.map +1 -1
  180. package/dist/lib/PurchaseOrder/index.d.ts +11 -0
  181. package/dist/lib/PurchaseOrder/index.js +12 -0
  182. package/dist/lib/PurchaseOrder/index.js.map +1 -1
  183. package/dist/lib/Service/index.d.ts +8 -0
  184. package/dist/lib/Service/index.js +8 -0
  185. package/dist/lib/Service/index.js.map +1 -1
  186. package/dist/lib/Shipment/index.js +13 -0
  187. package/dist/lib/Shipment/index.js.map +1 -1
  188. package/dist/lib/Slider/index.d.ts +6 -0
  189. package/dist/lib/Slider/index.js +6 -0
  190. package/dist/lib/Slider/index.js.map +1 -1
  191. package/dist/lib/Space/index.d.ts +178 -0
  192. package/dist/lib/Space/index.js +495 -6
  193. package/dist/lib/Space/index.js.map +1 -1
  194. package/dist/lib/Supplier/index.js +5 -0
  195. package/dist/lib/Supplier/index.js.map +1 -1
  196. package/dist/lib/Tags/index.js +5 -0
  197. package/dist/lib/Tags/index.js.map +1 -1
  198. package/dist/lib/TransferRequest/index.d.ts +178 -0
  199. package/dist/lib/TransferRequest/index.js +236 -4
  200. package/dist/lib/TransferRequest/index.js.map +1 -1
  201. package/dist/lib/User/index.d.ts +54 -0
  202. package/dist/lib/User/index.js +101 -21
  203. package/dist/lib/User/index.js.map +1 -1
  204. package/dist/lib/baseService.js +26 -0
  205. package/dist/lib/baseService.js.map +1 -1
  206. package/dist/rules/GR/constants/data.js +22 -0
  207. package/dist/rules/GR/constants/data.js.map +1 -1
  208. package/dist/rules/GR/constants/products.d.ts +3 -0
  209. package/dist/rules/GR/constants/products.js +16 -0
  210. package/dist/rules/GR/constants/products.js.map +1 -1
  211. package/dist/rules/GR/interfaces/data.js +7 -1
  212. package/dist/rules/GR/interfaces/data.js.map +1 -1
  213. package/dist/rules/GR/utils/cart.d.ts +41 -0
  214. package/dist/rules/GR/utils/cart.js +107 -1
  215. package/dist/rules/GR/utils/cart.js.map +1 -1
  216. package/dist/rules/GR/utils/data.js +4 -1
  217. package/dist/rules/GR/utils/data.js.map +1 -1
  218. package/dist/rules/GR/utils/expedition.d.ts +69 -0
  219. package/dist/rules/GR/utils/expedition.js +399 -11
  220. package/dist/rules/GR/utils/expedition.js.map +1 -1
  221. package/dist/rules/GR/utils/g2.d.ts +33 -0
  222. package/dist/rules/GR/utils/g2.js +135 -3
  223. package/dist/rules/GR/utils/g2.js.map +1 -1
  224. package/dist/rules/GR/utils/invoices.d.ts +27 -0
  225. package/dist/rules/GR/utils/invoices.js +41 -0
  226. package/dist/rules/GR/utils/invoices.js.map +1 -1
  227. package/dist/rules/GR/utils/products.d.ts +161 -0
  228. package/dist/rules/GR/utils/products.js +272 -1
  229. package/dist/rules/GR/utils/products.js.map +1 -1
  230. package/dist/rules/GR/utils/upsells.d.ts +32 -0
  231. package/dist/rules/GR/utils/upsells.js +32 -0
  232. package/dist/rules/GR/utils/upsells.js.map +1 -1
  233. package/dist/services/database/DatabaseService.d.ts +84 -0
  234. package/dist/services/database/DatabaseService.js +85 -0
  235. package/dist/services/database/DatabaseService.js.map +1 -1
  236. package/dist/services/database/FirebaseProvider.js +17 -0
  237. package/dist/services/database/FirebaseProvider.js.map +1 -1
  238. package/dist/services/database/NotFirebaseProvider.d.ts +14 -0
  239. package/dist/services/database/NotFirebaseProvider.js +19 -0
  240. package/dist/services/database/NotFirebaseProvider.js.map +1 -1
  241. package/dist/services/g2/G2OrderSlip.d.ts +7 -0
  242. package/dist/services/g2/G2OrderSlip.js +18 -0
  243. package/dist/services/g2/G2OrderSlip.js.map +1 -1
  244. package/dist/services/g2/utils.d.ts +10 -0
  245. package/dist/services/g2/utils.js +189 -3
  246. package/dist/services/g2/utils.js.map +1 -1
  247. package/dist/services/logs/index.d.ts +3 -0
  248. package/dist/services/logs/index.js +6 -1
  249. package/dist/services/logs/index.js.map +1 -1
  250. package/dist/services/products/BaseClass.js +2 -0
  251. package/dist/services/products/BaseClass.js.map +1 -1
  252. package/dist/services/products/TCGService.js +17 -1
  253. package/dist/services/products/TCGService.js.map +1 -1
  254. package/dist/services/products/utils.d.ts +22 -0
  255. package/dist/services/products/utils.js +50 -0
  256. package/dist/services/products/utils.js.map +1 -1
  257. package/dist/utils/anonymisation.d.ts +24 -0
  258. package/dist/utils/anonymisation.js +30 -0
  259. package/dist/utils/anonymisation.js.map +1 -1
  260. package/dist/utils/aws.d.ts +22 -0
  261. package/dist/utils/aws.js +28 -0
  262. package/dist/utils/aws.js.map +1 -1
  263. package/dist/utils/booking.d.ts +8 -0
  264. package/dist/utils/booking.js +9 -0
  265. package/dist/utils/booking.js.map +1 -1
  266. package/dist/utils/cart.d.ts +81 -0
  267. package/dist/utils/cart.js +175 -10
  268. package/dist/utils/cart.js.map +1 -1
  269. package/dist/utils/context.js +2 -2
  270. package/dist/utils/context.js.map +1 -1
  271. package/dist/utils/currency.js +31 -1
  272. package/dist/utils/currency.js.map +1 -1
  273. package/dist/utils/data.js +2 -0
  274. package/dist/utils/data.js.map +1 -1
  275. package/dist/utils/discount.d.ts +118 -0
  276. package/dist/utils/discount.js +178 -1
  277. package/dist/utils/discount.js.map +1 -1
  278. package/dist/utils/file-admin.js +1 -0
  279. package/dist/utils/file-admin.js.map +1 -1
  280. package/dist/utils/file.js +9 -1
  281. package/dist/utils/file.js.map +1 -1
  282. package/dist/utils/firebase-admin.d.ts +9 -0
  283. package/dist/utils/firebase-admin.js +12 -0
  284. package/dist/utils/firebase-admin.js.map +1 -1
  285. package/dist/utils/firebase.d.ts +17 -0
  286. package/dist/utils/firebase.js +17 -0
  287. package/dist/utils/firebase.js.map +1 -1
  288. package/dist/utils/inventories.d.ts +52 -0
  289. package/dist/utils/inventories.js +77 -2
  290. package/dist/utils/inventories.js.map +1 -1
  291. package/dist/utils/locale.d.ts +9 -0
  292. package/dist/utils/locale.js +9 -0
  293. package/dist/utils/locale.js.map +1 -1
  294. package/dist/utils/mailchimp.js +36 -0
  295. package/dist/utils/mailchimp.js.map +1 -1
  296. package/dist/utils/mathUtils.js +9 -0
  297. package/dist/utils/mathUtils.js.map +1 -1
  298. package/dist/utils/object.d.ts +19 -0
  299. package/dist/utils/object.js +21 -3
  300. package/dist/utils/object.js.map +1 -1
  301. package/dist/utils/products.d.ts +7 -0
  302. package/dist/utils/products.js +9 -0
  303. package/dist/utils/products.js.map +1 -1
  304. package/dist/utils/promiseToPurchase.d.ts +32 -0
  305. package/dist/utils/promiseToPurchase.js +34 -0
  306. package/dist/utils/promiseToPurchase.js.map +1 -1
  307. package/dist/utils/prosprsearch.d.ts +16 -0
  308. package/dist/utils/prosprsearch.js +34 -0
  309. package/dist/utils/prosprsearch.js.map +1 -1
  310. package/dist/utils/sdc.js +7 -0
  311. package/dist/utils/sdc.js.map +1 -1
  312. package/dist/utils/searchIndexes.d.ts +37 -0
  313. package/dist/utils/searchIndexes.js +37 -0
  314. package/dist/utils/searchIndexes.js.map +1 -1
  315. package/dist/utils/string.js +7 -6
  316. package/dist/utils/string.js.map +1 -1
  317. package/dist/utils/tools.d.ts +4 -0
  318. package/dist/utils/tools.js +4 -0
  319. package/dist/utils/tools.js.map +1 -1
  320. package/dist/utils/transferRequests.d.ts +24 -0
  321. package/dist/utils/transferRequests.js +24 -0
  322. package/dist/utils/transferRequests.js.map +1 -1
  323. package/dist/utils/update.js +12 -0
  324. package/dist/utils/update.js.map +1 -1
  325. package/package.json +1 -1
@@ -24,13 +24,16 @@ const toNumber_1 = __importDefault(require("lodash/toNumber"));
24
24
  const minBy_1 = __importDefault(require("lodash/minBy"));
25
25
  const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
26
26
  const chunk_1 = __importDefault(require("lodash/chunk"));
27
+ // Interfaces générales
27
28
  const Customer_1 = require("../../../Interfaces/Customer");
28
29
  const G2_1 = require("../../../Interfaces/G2");
29
30
  const Cart_1 = require("../../../Interfaces/Cart");
31
+ // Utils généraux
30
32
  const data_1 = require("../../../utils/data");
31
33
  const object_1 = require("../../../utils/object");
32
34
  const context_1 = require("../../../utils/context");
33
35
  const locale_1 = require("../../../utils/locale");
36
+ // Interfaces spécifiques
34
37
  const data_2 = require("../interfaces/data");
35
38
  const flatten_1 = __importDefault(require("lodash/flatten"));
36
39
  const groupBy_1 = __importDefault(require("lodash/groupBy"));
@@ -43,6 +46,8 @@ const cart_1 = require("../../../utils/cart");
43
46
  const round_1 = __importDefault(require("lodash/round"));
44
47
  const products_2 = require("../constants/products");
45
48
  const products_3 = require("./products");
49
+ // ---------------------------------------------------------------------------------------------
50
+ // #region PRODUCTS
46
51
  const getG2ProductExternalValues = async (sku, g2Service, space, org) => {
47
52
  var _a, _b, _c;
48
53
  const g2Auth = g2Service.external_service_infos.api;
@@ -50,6 +55,7 @@ const getG2ProductExternalValues = async (sku, g2Service, space, org) => {
50
55
  return;
51
56
  let externalValues = undefined;
52
57
  try {
58
+ // Fetch item from G2
53
59
  const productG2 = await (0, exports.fetchProductFromG2WithSku)(sku, space, org);
54
60
  if (!!productG2) {
55
61
  const noArticle = (_a = productG2.article.noArticle) !== null && _a !== void 0 ? _a : undefined;
@@ -95,12 +101,16 @@ const fetchProductFromG2WithSku = async (sku, space, org, logError) => {
95
101
  }
96
102
  };
97
103
  let g2Prod = await callG2(sku);
104
+ // If no result was returned, and sku does not already include -1, call G2 again with added suffix
98
105
  if (!!!g2Prod && !sku.includes('-1')) {
99
106
  g2Prod = await callG2(`${sku}-1`);
100
107
  }
101
108
  return g2Prod;
102
109
  };
103
110
  exports.fetchProductFromG2WithSku = fetchProductFromG2WithSku;
111
+ // #endregion
112
+ // ---------------------------------------------------------------------------------------------
113
+ // #region CUSTOMERS
104
114
  const getG2Customer = async (spaceToken, customerId) => {
105
115
  let allG2Customers = [];
106
116
  try {
@@ -224,6 +234,9 @@ const transformG2CustomerToCustomer = (g2Customer, prevCustomer, allGroups) => {
224
234
  const sameGroup = allGroups.find((g) => g.external_slug === type);
225
235
  return !!sameGroup ? sameGroup.slug : defaultProGroup;
226
236
  };
237
+ // Mapping langue G2 -> Addio
238
+ // G2: 1=Français, 2=Anglais
239
+ // Addio: 'fr' | 'en' (default 'fr')
227
240
  const mapG2LangToAddioPreferredLang = (g2Lang) => {
228
241
  return g2Lang === 2 ? 'en' : 'fr';
229
242
  };
@@ -237,6 +250,7 @@ const transformG2CustomerToCustomer = (g2Customer, prevCustomer, allGroups) => {
237
250
  ? {
238
251
  has_credit_line: true,
239
252
  credit_line_max: client.limiteDeCrédit
253
+ // credit_line_used: ',
240
254
  }
241
255
  : {})), (!!client.noReprésentant ? { represented_by: client.noReprésentant } : {})), { basic_info: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (0, Customer_1.getDefaultBasicCustomer)()), (!!prevCustomer ? prevCustomer.basic_info : { customer_type: Customer_1.BasicCustomerTypeEnum.PRO })), (!!client.email ? { customer_email: client.email.split(';')[0].toLowerCase() } : {})), (!!client.fax ? { customer_photocopier: client.fax } : {})), (!!client.personneRessourceVentes ? getCustomerNameInfo(client.personneRessourceVentes) : {})), (preferredLang ? { customer_prefered_lang: preferredLang } : {})), { customer_professionnal_info: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (!!prevCustomer ? prevCustomer.basic_info.customer_professionnal_info : {})), { professionnal_title: !!client.groupeDeClient && !!(0, exports.getG2CustomerTypeFromCode)(client.groupeDeClient)
242
256
  ? getCustomerGroupFromTypeCode((0, exports.getG2CustomerTypeFromCode)(client.groupeDeClient))
@@ -281,6 +295,7 @@ const transformG2CustomerToCustomer = (g2Customer, prevCustomer, allGroups) => {
281
295
  expedition_recipient_phone: !!client.téléphone ? (0, data_1.formatPhoneNumberDB)(client.téléphone) : ''
282
296
  }
283
297
  ] });
298
+ // If is test env, and anonymisation process was already done for customer, keep prev customer info for specific props
284
299
  if (!!__1.isTestEnv &&
285
300
  !!prevCustomer &&
286
301
  !!prevCustomer.basic_info.customer_email &&
@@ -297,6 +312,12 @@ const transformG2CustomerToCustomer = (g2Customer, prevCustomer, allGroups) => {
297
312
  return customerWithNewInfo;
298
313
  };
299
314
  exports.transformG2CustomerToCustomer = transformG2CustomerToCustomer;
315
+ /**
316
+ * Verifies if customer exists in G2.
317
+ * @param customerID - Customer ID for G2 fetch
318
+ * @param space - Space Object
319
+ * @param org - Org Object
320
+ */
300
321
  const checkIfCustomerExistsInG2 = async (customerID, space, org) => {
301
322
  try {
302
323
  const token = (0, context_1.getSpaceToken)(space, org);
@@ -321,6 +342,14 @@ const checkIfCustomerExistsInG2 = async (customerID, space, org) => {
321
342
  }
322
343
  };
323
344
  exports.checkIfCustomerExistsInG2 = checkIfCustomerExistsInG2;
345
+ /**
346
+ * Updates customer in database with new info found in G2.
347
+ * @param customerID - Customer ID for G2 fetch
348
+ * @param space - Space Object
349
+ * @param org - Org Object
350
+ * @param addToDB - if updated customer should be saved to database (defaults to true)
351
+ * @param skipEmailCheck - if check for unique email should be skiped or not (defaults to false)
352
+ */
324
353
  const updateCustomerWithG2Info = async (customerID, space, org, addToDB = true, skipEmailCheck = false) => {
325
354
  console.log('===============');
326
355
  console.log('in v2 sdk updateCustomerWithG2Info');
@@ -360,6 +389,9 @@ const updateCustomerWithG2Info = async (customerID, space, org, addToDB = true,
360
389
  }
361
390
  };
362
391
  exports.updateCustomerWithG2Info = updateCustomerWithG2Info;
392
+ // #endregion
393
+ // ---------------------------------------------------------------------------------------------
394
+ // #region ESCOMPTES
363
395
  const getG2DiscountFromCode = (code) => {
364
396
  const onlyNb = code.replace(/[^0-9]/gi, '');
365
397
  return !!!onlyNb || !!isNaN(Number(onlyNb)) ? undefined : (0, toNumber_1.default)(onlyNb);
@@ -367,11 +399,14 @@ const getG2DiscountFromCode = (code) => {
367
399
  exports.getG2DiscountFromCode = getG2DiscountFromCode;
368
400
  const getG2CustomerTypeFromCode = (code) => {
369
401
  let parsedCode = code;
402
+ // 1. Remove prefix
370
403
  const possiblePrefixes = ['BASE', 'PAYS', 'RENC'];
371
404
  for (let prefix of possiblePrefixes) {
372
405
  parsedCode = parsedCode.replace(prefix, '');
373
406
  }
407
+ // 2. Remove numbers
374
408
  parsedCode = parsedCode.replace(/[0-9]/gi, '');
409
+ // 3. Remove all non-wanted characters
375
410
  const possibleTypes = ['AM', 'AL', 'AS', 'AMN'];
376
411
  const checkWithPossibleTypes = (codeToCheck, removeFrom) => {
377
412
  if (!!!possibleTypes.includes(codeToCheck)) {
@@ -419,10 +454,18 @@ const fetchCustomPriceList = async (spaceToken, customerId, ignoreDashPriceList,
419
454
  return prices;
420
455
  };
421
456
  exports.fetchCustomPriceList = fetchCustomPriceList;
457
+ /**
458
+ * Constructs a custom price list for a PRO Groupe Richer customer, based on data from G2 and AddioCommerce.
459
+ * @param space - The space Object for appointed customer
460
+ * @param idClient - The customer's G2 ID
461
+ * @param ignoreDashPriceList - Optionnal. If customer group prices found in Addio should be ignored, and only G2 prices be considered.
462
+ * @param onlyForProductSlugs - Optionnal. Array of skus for which the list should be generated (used to not go through all products in database if only certain products are needed)
463
+ */
422
464
  const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForProductSlugs) => {
423
465
  let priceList = [];
424
466
  let escomptesClient = [];
425
467
  let ententesClient = [];
468
+ // Fetch api info from space
426
469
  let G2Auth = '';
427
470
  let G2Url = '';
428
471
  const G2Service = space.services({ field: 'external_service_name', value: 'G2' });
@@ -432,6 +475,8 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
432
475
  }
433
476
  if (!!!G2Auth || !!!G2Url)
434
477
  throw `Error on fetching G2 API info from space`;
478
+ // -------------------------------------------------------------------
479
+ // 0. Fetch customer from G2
435
480
  try {
436
481
  const customerReq = await fetch(`${G2Url}/clients?noClient=${idClient}`, {
437
482
  method: 'GET',
@@ -447,6 +492,8 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
447
492
  const g2Customer = allG2Customers[0];
448
493
  if (!!!g2Customer)
449
494
  return priceList;
495
+ // -------------------------------------------------------------------
496
+ // #region 1. Fetch ententesClient from G2
450
497
  const today = (0, moment_1.default)();
451
498
  const allCurrentEntentes = g2Customer.soumissions.filter((s) => !!s.soumission.actif &&
452
499
  !!s.soumission.dateDébut &&
@@ -456,9 +503,14 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
456
503
  if (!!mostRecent) {
457
504
  ententesClient = mostRecent;
458
505
  }
506
+ // #endregion ---------------------------------------------------------
507
+ // -------------------------------------------------------------------
508
+ // #region 2. Fetch escomptesClient from G2
459
509
  const { noClient, groupeDeClient, classePrix } = g2Customer.client;
460
510
  const customerType = !!!groupeDeClient ? undefined : (0, exports.getG2CustomerTypeFromCode)(groupeDeClient);
511
+ // const normalCustomerEscompte = !!!groupeDeClient ? undefined : getG2DiscountFromCode(groupeDeClient)
461
512
  try {
513
+ // 2.a fetch escomptes with noClient
462
514
  const escomptesNumClient = await fetch(`${G2Url}/escompteclient?code=${noClient}`, {
463
515
  method: 'GET',
464
516
  headers: {
@@ -477,6 +529,9 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
477
529
  console.log('error on fetching escomptesClient from G2: ', e.toString());
478
530
  }
479
531
  try {
532
+ // 2.b fetch escomptes with groupeDeClient
533
+ // + added logic if groupeClient is same as noClient to no check twice same value
534
+ // (happens with test G2 customers)
480
535
  if (!!groupeDeClient && groupeDeClient !== noClient) {
481
536
  const escomptesGroupeClient = await fetch(`${G2Url}/escompteclient?code=${groupeDeClient}`, {
482
537
  method: 'GET',
@@ -490,6 +545,7 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
490
545
  }
491
546
  else {
492
547
  const groupeClientEscomptes = groupeClientResults.map((r) => r.escompteClient);
548
+ // Specific user promos always have priority over "group" promos, so we filter out escomptes where code2 is found in numClientEscomptes
493
549
  const noDuplicates = groupeClientEscomptes.filter((es) => !!!es.code2 || !!!escomptesClient.some((e) => !!e.code2 && e.code2 === es.code2));
494
550
  escomptesClient = [...escomptesClient, ...noDuplicates];
495
551
  }
@@ -501,6 +557,9 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
501
557
  catch (e) {
502
558
  console.log('error on fetching escomptesClient from G2: ', e.toString());
503
559
  }
560
+ // #endregion ---------------------------------------------------------
561
+ // -------------------------------------------------------------------
562
+ // #region 3. Fetch products (except drafts) from DB
504
563
  let allProducts = [];
505
564
  try {
506
565
  if (!!onlyForProductSlugs && !!onlyForProductSlugs.length) {
@@ -531,6 +590,9 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
531
590
  }
532
591
  if (!!!allProducts.length)
533
592
  return priceList;
593
+ // #endregion ---------------------------------------------------------
594
+ // -------------------------------------------------------------------
595
+ // #region 4. Check each product for custom price to push
534
596
  const allCustomerGroups = space.preferences.customers.groups() || [];
535
597
  const customerGroupByPriceClass = !!classePrix
536
598
  ? allCustomerGroups.find((g) => g.external_price_list_slug == classePrix.toString())
@@ -542,20 +604,27 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
542
604
  continue;
543
605
  const type = !!data.attributes && data.attributes[data_2.AttributesIdEnumGR.TYPE];
544
606
  for (let decli of data.declinations.filter((d) => !!!d.is_sample)) {
607
+ // const isSpecificBetonProd =
608
+ // !!decli.external_values && ['BOLDUC', 'RINOX', 'RICHER', 'OAKS'].includes(decli.external_values['catégorie2'])
609
+ // let shouldApplyNormalEscompte = !!!data.is_service && !!isSpecificBetonProd
545
610
  let isNetPrice = !!decli.external_values && decli.external_values['catégorie2'] === 'NET';
546
611
  const sku = decli.sku;
547
612
  if (!!decli.external_values && decli.external_values['catégorie1'] === products_2.allInclusiveCategory) {
548
613
  allIncSkus.push(sku);
549
614
  }
615
+ // Establish base price for sku ...
550
616
  let basePrice = (0, toNumber_1.default)(decli.regular_price.amount);
617
+ // ... if groupeDeClient is set, check dashboard pricelist for pro price if !!!ignoreDashPriceList
551
618
  if (!!decli.prices_list && !!decli.prices_list.length && !!!ignoreDashPriceList) {
552
619
  let priceListItemToUse = undefined;
620
+ // ... a. Check group with classe de prix
553
621
  const samePriceClassInPriceList = !!customerGroupByPriceClass
554
622
  ? decli.prices_list.find((pl) => pl.group_id == customerGroupByPriceClass.slug)
555
623
  : undefined;
556
624
  if (!!samePriceClassInPriceList && !isNaN((0, toNumber_1.default)(samePriceClassInPriceList.amount))) {
557
625
  priceListItemToUse = samePriceClassInPriceList;
558
626
  }
627
+ // ... a. Check group with groupeDeClient
559
628
  else if (!!groupeDeClient) {
560
629
  const samePriceInPriceList = !!customerType
561
630
  ? decli.prices_list.find((p) => !!p.external_slug && p.external_slug === customerType)
@@ -571,10 +640,13 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
571
640
  if (!!priceListItemToUse) {
572
641
  basePrice = (0, toNumber_1.default)(priceListItemToUse.amount);
573
642
  if (!!!isNetPrice) {
643
+ // shouldApplyNormalEscompte = !!priceListItemToUse.custom_promo_applies && !!isSpecificBetonProd
574
644
  isNetPrice = !!priceListItemToUse.is_net_price;
575
645
  }
576
646
  }
577
647
  }
648
+ // Array to stock all promos that could be applied for customer and declination
649
+ // By default, contains regular price + regular escompted price
578
650
  let comparePrices = [
579
651
  Object.assign(Object.assign({ price: basePrice, type: G2_1.CustomPriceItemTypeEnum.REG }, (!!(0, object_1.recursiveCheckObject)(decli, 'external_values.catégorie1')
580
652
  ? { code1: (0, object_1.recursiveCheckObject)(decli, 'external_values.catégorie1') }
@@ -582,6 +654,9 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
582
654
  ? { code2: (0, object_1.recursiveCheckObject)(decli, 'external_values.catégorie2') }
583
655
  : {}))
584
656
  ];
657
+ // Other promo checks, if found, are added to comparePrices array
658
+ // -------------------------------------------------------------------
659
+ // #region 4.1 Check ententeClient for same sku
585
660
  let foundEntenteForProduct = false;
586
661
  if (!!ententesClient.length) {
587
662
  for (let entente of ententesClient) {
@@ -607,6 +682,9 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
607
682
  }
608
683
  }
609
684
  }
685
+ // #endregion ---------------------------------------------------------
686
+ // -------------------------------------------------------------------
687
+ // #region 4.2 Check escompteClient array
610
688
  if (!!escomptesClient.length) {
611
689
  const findBestDeal = (escomptesToCheck) => {
612
690
  const bestDeal = (0, maxBy_1.default)(escomptesToCheck, (escompte) => (0, toNumber_1.default)(escompte.pourcEscompte));
@@ -614,7 +692,11 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
614
692
  comparePrices.push(Object.assign({ price: basePrice * ((100 - (0, toNumber_1.default)(bestDeal.pourcEscompte)) / 100), type: G2_1.CustomPriceItemTypeEnum.ESCOMPTE, percent: (0, toNumber_1.default)(bestDeal.pourcEscompte), code1: bestDeal.code1 }, (!!bestDeal.code2 ? { code2: bestDeal.code2 } : {})));
615
693
  }
616
694
  };
695
+ // Check only if :
696
+ // - foundEntenteForProduct = false (entente always has priority over escompte)
617
697
  if (!!!foundEntenteForProduct) {
698
+ // If isNetPrice, check if escompte for cat1 DALLE is found for user. If so, apply escompte even if NET
699
+ // ** WORKAROUND pour nouvelle logique GR où certains produits à prix NET dans G2 doivent pouvoir être escomptés dans certaines régions (ici à QC) **
618
700
  if (!!isNetPrice) {
619
701
  const sameCat1Escompte = escomptesClient.filter((e) => {
620
702
  if (!!!e.code2)
@@ -626,10 +708,12 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
626
708
  }
627
709
  }
628
710
  else {
711
+ // a. No 2nd code is found (applies to client or client group directly)
629
712
  const no2ndCode = escomptesClient.filter((e) => !!!e.code2);
630
713
  if (!!no2ndCode.length) {
631
714
  findBestDeal(no2ndCode);
632
715
  }
716
+ // b. 2nd code is current sku && no entente was found for sku
633
717
  let sameSkuEscompte = escomptesClient.filter((e) => e.code2 && e.code2 === sku);
634
718
  if (!!!sameSkuEscompte.length) {
635
719
  sameSkuEscompte = escomptesClient.filter((e) => e.code2 && e.code2.includes(sku));
@@ -637,6 +721,8 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
637
721
  if (!!sameSkuEscompte.length) {
638
722
  findBestDeal(sameSkuEscompte);
639
723
  }
724
+ // c. 2nd code is prod brand or type
725
+ // Only check if no sameSkuEscompte found (precise promo always has precedence over "group" promo)
640
726
  if (!!!sameSkuEscompte.length) {
641
727
  const sameBrandEscompte = escomptesClient.filter((e) => {
642
728
  if (!!!e.code2)
@@ -651,6 +737,9 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
651
737
  }
652
738
  }
653
739
  }
740
+ // #endregion ---------------------------------------------------------
741
+ // -------------------------------------------------------------------
742
+ // #region 4.3 Set price to apply to variable, ready to be pushed
654
743
  comparePrices = (0, uniqBy_1.default)(comparePrices, (p) => p.price);
655
744
  const lowestPrice = (0, minBy_1.default)(comparePrices, (p) => p.price);
656
745
  let appliedPrice;
@@ -660,8 +749,10 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
660
749
  }
661
750
  else {
662
751
  appliedPrice = lowestPrice;
752
+ // If lowestPrice is regular price and entente is found in product, override with entente price, even if amount is higher
663
753
  if (!!lowestPrice && lowestPrice.type == G2_1.CustomPriceItemTypeEnum.REG) {
664
754
  const ententeFound = comparePrices.find((p) => p.type == G2_1.CustomPriceItemTypeEnum.ENTENTE);
755
+ // set reg props to entente price so both prices have same value, but keep all other props as entente
665
756
  if (!!ententeFound)
666
757
  appliedPrice = Object.assign(Object.assign({}, ententeFound), { reg: ententeFound.price });
667
758
  }
@@ -677,14 +768,21 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
677
768
  }
678
769
  : {})), appliedPrice);
679
770
  }
771
+ // #endregion ---------------------------------------------------------
772
+ // ----------------------------------------------------------------
773
+ // 6. Push lowest price from comparePrice to priceList
680
774
  if (!!customPriceItemToPush) {
681
775
  priceList.push(customPriceItemToPush);
682
776
  }
683
777
  }
684
778
  }
779
+ // #endregion ---------------------------------------------------------
780
+ // -------------------------------------------------------------------
781
+ // #region 5. Use ALLINC decli when all-inclusive installation is active
685
782
  if (!!allIncSkus.length && !!(0, products_3.getInstallationAllInclusiveFromPriceList)(priceList)) {
686
783
  priceList = priceList.map((item) => (allIncSkus.includes(item.sku) ? Object.assign(Object.assign({}, item), { price: 0 }) : item));
687
784
  }
785
+ // #endregion ---------------------------------------------------------
688
786
  return priceList;
689
787
  }
690
788
  catch (e) {
@@ -693,13 +791,21 @@ const getCustomPriceList = async (space, idClient, ignoreDashPriceList, onlyForP
693
791
  }
694
792
  };
695
793
  exports.getCustomPriceList = getCustomPriceList;
794
+ /**
795
+ * Get promise to purchase additionnal escompte equivalent from customPriceList for specific cart item
796
+ * @param customPriceList - The pro customers custom price list
797
+ * @param item - The cart item to check
798
+ */
696
799
  const getItemEscompteSupp = (customPriceList, item) => {
800
+ // Get catégorie 2 from item
697
801
  const code2InItem = (0, object_1.recursiveCheckObject)(item, `external_values.catégorie2`);
802
+ // Get code2 from customPriceList item
698
803
  let code2InPriceList = undefined;
699
804
  const customPriceItem = customPriceList.find((priceItem) => priceItem.sku === item.sku);
700
805
  if (!!customPriceItem && !!customPriceItem.code2) {
701
806
  code2InPriceList = customPriceItem.code2;
702
807
  }
808
+ // Use customPriceList item code2 if defined, else item's catégorie 2
703
809
  const code2ToCheck = code2InPriceList !== null && code2InPriceList !== void 0 ? code2InPriceList : code2InItem;
704
810
  if (!!!code2ToCheck)
705
811
  return;
@@ -721,6 +827,7 @@ const buildEscompteSuppCartItem = (escompteItems, customPriceList, escompteSuppI
721
827
  const escompteDecli = escompteItems[0].data().declinations.find((decli) => decli.sku === escompteSuppItem.sku);
722
828
  if (!!!escompteDecli)
723
829
  return;
830
+ // If esc supp found in price list has type reg price and has price of 0.00, it means the escompte does not apply to the customer
724
831
  const sameInCustomPriceList = customPriceList.find((c) => c.sku === escompteDecli.sku);
725
832
  if (!!sameInCustomPriceList &&
726
833
  sameInCustomPriceList.type === G2_1.CustomPriceItemTypeEnum.REG &&
@@ -734,11 +841,22 @@ const isEscompteSuppItem = (itemSku) => {
734
841
  return Object.values(G2_1.EscomptesDeclinationSkusEnum).some((subString) => itemSku.includes(subString));
735
842
  };
736
843
  exports.isEscompteSuppItem = isEscompteSuppItem;
844
+ // #endregion
845
+ // ---------------------------------------------------------------------------------------------
846
+ // #region FORMAT CART ITEMS
847
+ /**
848
+ * Adjusts prices in item provided with corresponding custom price list item, if it exists.
849
+ * @param item - The cart item or indexed declination
850
+ * @param customPriceList - The customers custom price list
851
+ * @param options.removeTierPricing - Optionnal. If tier-pricing should be removed from item returned
852
+ * @param options.setNetPriceAsRegular - Optionnal. If true and custom price found is NET (entente), sets the NET price as regular price (normaly set to discount_price)
853
+ */
737
854
  const checkForCustomPriceEquivalent = (item, customPriceList, options = {}) => {
738
855
  var _a;
739
856
  const sameInCustomPriceList = customPriceList.find((i) => i.sku === item.sku);
740
857
  if (!!!sameInCustomPriceList)
741
858
  return item;
859
+ // If price was already overridden and price found in customPriceList is of type regular, return
742
860
  const hasOverriddenPrice = item.price_override;
743
861
  if (!!hasOverriddenPrice && sameInCustomPriceList.type === G2_1.CustomPriceItemTypeEnum.REG)
744
862
  return item;
@@ -749,6 +867,8 @@ const checkForCustomPriceEquivalent = (item, customPriceList, options = {}) => {
749
867
  const isEntente = sameInCustomPriceList.type === G2_1.CustomPriceItemTypeEnum.ENTENTE;
750
868
  const isPA = !!sameInCustomPriceList.PA_percent;
751
869
  const shouldUseCustomPriceForRegPrice = (!!isReg && !!!sameInCustomPriceList.percent) || (!!options.setNetPriceAsRegular && !!isEntente);
870
+ // MODIF. FRAIS 2024 - Si le prix de la liste de prix est 0, et que le type du priceItem est REG ou ENTENTE, on pousse 0 comme valeur pour le prix régulier
871
+ // Le code se chargera alors de retirer le frais de ceux ajoutés au panier si c'est le cas
752
872
  const currentDiscountPrice = item.discount_price || { currency: 'CAD' };
753
873
  const currentPromoPrice = item.promo_price || { currency: 'CAD' };
754
874
  const calculatedRegPrice = !!item.price_override
@@ -758,7 +878,10 @@ const checkForCustomPriceEquivalent = (item, customPriceList, options = {}) => {
758
878
  : !!shouldUseCustomPriceForRegPrice
759
879
  ? sameInCustomPriceList.price
760
880
  : sameInCustomPriceList.reg;
761
- let updatedCartItem = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { regular_price: Object.assign(Object.assign(Object.assign({}, regular_price), { amount: calculatedRegPrice }), (sameInCustomPriceList.type !== G2_1.CustomPriceItemTypeEnum.REG && !!!regular_price.price_type
881
+ // #region RECREATE CART ITEM WITH UPDATED PRICES
882
+ let updatedCartItem = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), {
883
+ // a. Set regular price for product with price_type if not already defined
884
+ regular_price: Object.assign(Object.assign(Object.assign({}, regular_price), { amount: calculatedRegPrice }), (sameInCustomPriceList.type !== G2_1.CustomPriceItemTypeEnum.REG && !!!regular_price.price_type
762
885
  ? { price_type: sameInCustomPriceList.type }
763
886
  : {})) }), (!!!hasOverriddenPrice
764
887
  ? Object.assign(Object.assign({}, (sameInCustomPriceList.percent || !!!isReg
@@ -772,14 +895,15 @@ const checkForCustomPriceEquivalent = (item, customPriceList, options = {}) => {
772
895
  }
773
896
  : {}))
774
897
  }
775
- :
898
+ : // c2. Add discount price data if custom price list item has no Net Price as regular price indicator.
899
+ // ONLY if current discount price for item is not already overriden!
776
900
  !!!options.setNetPriceAsRegular
777
901
  ? Object.assign({ discount_price: Object.assign(Object.assign({}, currentDiscountPrice), (!currentDiscountPrice.overridden
778
902
  ? {
779
903
  amount: sameInCustomPriceList.price,
780
904
  price_type: sameInCustomPriceList.type
781
905
  }
782
- : {})) }, (!!currentPromoPrice.overridden ? { promo_price: currentPromoPrice } : {})) : {})) :
906
+ : {})) }, (!!currentPromoPrice.overridden ? { promo_price: currentPromoPrice } : {})) : {})) : // d. Add discount price data if price is tier pricing price and tier pricing should be kept for product
783
907
  currentDiscountPrice.price_type === 'tierpricing' && !!!options.removeTierPricing
784
908
  ? {
785
909
  discount_price: Object.assign(Object.assign({}, item.discount_price), { original_amount: !!isReg || !!!options.setNetPriceAsRegular ? null : sameInCustomPriceList.price })
@@ -794,6 +918,7 @@ const checkForCustomPriceEquivalent = (item, customPriceList, options = {}) => {
794
918
  tier_pricing
795
919
  }
796
920
  : {}));
921
+ // g. If promo price was overriden in POS, and discount_price or reg_price changed, recalculate promo price applied from percentage
797
922
  const priceUsedForPromoCalculations = !!updatedCartItem.discount_price
798
923
  ? updatedCartItem.discount_price.amount
799
924
  : updatedCartItem.regular_price.amount;
@@ -803,15 +928,20 @@ const checkForCustomPriceEquivalent = (item, customPriceList, options = {}) => {
803
928
  priceUsedForPromoCalculations != initialPriceToCompare) {
804
929
  updatedCartItem = Object.assign(Object.assign({}, updatedCartItem), { promo_price: Object.assign(Object.assign({}, (updatedCartItem.promo_price || { currency: 'CAD' })), { amount: (0, round_1.default)((0, cart_1.calculateAmountForCustomPromo)(updatedCartItem, Cart_1.CustomPromoType.EXTRA_PROMO, currentPromoPrice.percent_applied), priceUsedForPromoCalculations.toString().split('.').length) }) });
805
930
  }
931
+ // #endregion
806
932
  return updatedCartItem;
807
933
  };
808
934
  exports.checkForCustomPriceEquivalent = checkForCustomPriceEquivalent;
935
+ // #endregion
936
+ // ---------------------------------------------------------------------------------------------
937
+ // #region CUSTOM INCENTIVE
809
938
  const getCustomIncentiveAmount = (customPriceList) => {
810
939
  if (!!!customPriceList)
811
940
  return;
812
941
  const ententeSku = 'INCITATIF';
813
942
  let amount = 0;
814
943
  const entente = customPriceList.find((priceItem) => priceItem.sku === ententeSku);
944
+ // Si l'incitatif n'est pas trouvé dans l'entente, ou correspond au prix "régulier", ne pas le retourner
815
945
  if (!!!entente || !!!entente.price || entente.type == G2_1.CustomPriceItemTypeEnum.REG)
816
946
  return;
817
947
  amount = entente.price * -100;
@@ -843,6 +973,7 @@ const getCustomIncentiveInfo = (customPriceList, discountRules, defaultIncentive
843
973
  let customIncentiveAmount = (0, exports.getCustomIncentiveAmount)(customPriceList);
844
974
  const incentiveDiscountRule = (0, discount_1.getPaymentIncentiveDiscount)(discountRules);
845
975
  if (!!!customIncentiveAmount) {
976
+ // If already overridden, reset incentive discount if no custom incentive found for customer
846
977
  if (!!incentiveDiscountRule && !!incentiveDiscountRule.overridden) {
847
978
  return {
848
979
  amount: defaultIncentiveAmount || 0,
@@ -865,4 +996,5 @@ const getCustomIncentiveInfo = (customPriceList, discountRules, defaultIncentive
865
996
  };
866
997
  };
867
998
  exports.getCustomIncentiveInfo = getCustomIncentiveInfo;
999
+ // #endregion
868
1000
  //# sourceMappingURL=g2.js.map