addio-admin-sdk 1.7.21 → 1.7.23

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 (522) hide show
  1. package/.babelrc +17 -17
  2. package/.env +14 -14
  3. package/.env.dev +14 -14
  4. package/.github/workflows/publish_coverage.yaml +69 -69
  5. package/addio-sdk-doc.md +1380 -1380
  6. package/changelog.md +469 -469
  7. package/dist/Interfaces/Address/index.d.ts +21 -21
  8. package/dist/Interfaces/Address/index.js +16 -16
  9. package/dist/Interfaces/Algolia/index.d.ts +148 -148
  10. package/dist/Interfaces/Algolia/index.js +2 -2
  11. package/dist/Interfaces/Attachement/index.d.ts +5 -5
  12. package/dist/Interfaces/Attachement/index.js +2 -2
  13. package/dist/Interfaces/Attribute/index.d.ts +47 -47
  14. package/dist/Interfaces/Attribute/index.js +10 -10
  15. package/dist/Interfaces/BGJob/index.d.ts +56 -56
  16. package/dist/Interfaces/BGJob/index.js +36 -36
  17. package/dist/Interfaces/BaseClass/index.d.ts +8 -8
  18. package/dist/Interfaces/BaseClass/index.js +2 -2
  19. package/dist/Interfaces/Blog/IBlogArticle.d.ts +18 -18
  20. package/dist/Interfaces/Blog/IBlogArticle.js +2 -2
  21. package/dist/Interfaces/Blog/IBlogAuthor.d.ts +7 -7
  22. package/dist/Interfaces/Blog/IBlogAuthor.js +2 -2
  23. package/dist/Interfaces/Blog/IBlogCategory.d.ts +9 -9
  24. package/dist/Interfaces/Blog/IBlogCategory.js +2 -2
  25. package/dist/Interfaces/Blog/IBlogComment.d.ts +13 -13
  26. package/dist/Interfaces/Blog/IBlogComment.js +2 -2
  27. package/dist/Interfaces/Blog/IBlogKeywords.d.ts +9 -9
  28. package/dist/Interfaces/Blog/IBlogKeywords.js +2 -2
  29. package/dist/Interfaces/Booking/index.d.ts +68 -68
  30. package/dist/Interfaces/Booking/index.js +17 -17
  31. package/dist/Interfaces/Brand/index.d.ts +13 -13
  32. package/dist/Interfaces/Brand/index.js +2 -2
  33. package/dist/Interfaces/CMS/index.d.ts +25 -25
  34. package/dist/Interfaces/CMS/index.js +2 -2
  35. package/dist/Interfaces/Cart/IPandaPayload.d.ts +64 -64
  36. package/dist/Interfaces/Cart/IPandaPayload.js +18 -18
  37. package/dist/Interfaces/Cart/IPaymentCard.d.ts +22 -22
  38. package/dist/Interfaces/Cart/IPaymentCard.js +44 -44
  39. package/dist/Interfaces/Cart/IPaypalPayload.d.ts +9 -9
  40. package/dist/Interfaces/Cart/IPaypalPayload.js +2 -2
  41. package/dist/Interfaces/Cart/IPaysafePayload.d.ts +72 -72
  42. package/dist/Interfaces/Cart/IPaysafePayload.js +2 -2
  43. package/dist/Interfaces/Cart/IStripePayload.d.ts +66 -66
  44. package/dist/Interfaces/Cart/IStripePayload.js +2 -2
  45. package/dist/Interfaces/Cart/index.d.ts +410 -410
  46. package/dist/Interfaces/Cart/index.js +191 -191
  47. package/dist/Interfaces/Catalogue/index.d.ts +68 -68
  48. package/dist/Interfaces/Catalogue/index.js +37 -37
  49. package/dist/Interfaces/Category/index.d.ts +26 -26
  50. package/dist/Interfaces/Category/index.js +2 -2
  51. package/dist/Interfaces/Chart/index.d.ts +11 -11
  52. package/dist/Interfaces/Chart/index.js +2 -2
  53. package/dist/Interfaces/Class/index.d.ts +8 -8
  54. package/dist/Interfaces/Class/index.js +2 -2
  55. package/dist/Interfaces/Consent/index.d.ts +6 -6
  56. package/dist/Interfaces/Consent/index.js +2 -2
  57. package/dist/Interfaces/Context/IContextProps.d.ts +4 -4
  58. package/dist/Interfaces/Context/IContextProps.js +2 -2
  59. package/dist/Interfaces/Context/IContextState.d.ts +15 -15
  60. package/dist/Interfaces/Context/IContextState.js +2 -2
  61. package/dist/Interfaces/Customer/ICustomerBadge.d.ts +2 -2
  62. package/dist/Interfaces/Customer/ICustomerBadge.js +2 -2
  63. package/dist/Interfaces/Customer/ICustomerRating.d.ts +10 -10
  64. package/dist/Interfaces/Customer/ICustomerRating.js +2 -2
  65. package/dist/Interfaces/Customer/index.d.ts +95 -95
  66. package/dist/Interfaces/Customer/index.js +158 -158
  67. package/dist/Interfaces/Declination/index.d.ts +111 -111
  68. package/dist/Interfaces/Declination/index.js +77 -77
  69. package/dist/Interfaces/Document/index.d.ts +8 -8
  70. package/dist/Interfaces/Document/index.js +2 -2
  71. package/dist/Interfaces/Elastic/index.d.ts +89 -89
  72. package/dist/Interfaces/Elastic/index.js +2 -2
  73. package/dist/Interfaces/Email/CustomGR/I3DPrintEmail.d.ts +11 -11
  74. package/dist/Interfaces/Email/CustomGR/I3DPrintEmail.js +2 -2
  75. package/dist/Interfaces/Email/CustomGR/IBorrowToolsEmail.d.ts +15 -15
  76. package/dist/Interfaces/Email/CustomGR/IBorrowToolsEmail.js +2 -2
  77. package/dist/Interfaces/Email/CustomGR/IPickupMaterialsEmail.d.ts +12 -12
  78. package/dist/Interfaces/Email/CustomGR/IPickupMaterialsEmail.js +2 -2
  79. package/dist/Interfaces/Email/CustomGR/IPreMeetingFormEmail.d.ts +36 -36
  80. package/dist/Interfaces/Email/CustomGR/IPreMeetingFormEmail.js +2 -2
  81. package/dist/Interfaces/Email/CustomGR/ISponsorRequestEmail.d.ts +12 -12
  82. package/dist/Interfaces/Email/CustomGR/ISponsorRequestEmail.js +2 -2
  83. package/dist/Interfaces/Email/CustomGR/ITransportEmail.d.ts +12 -12
  84. package/dist/Interfaces/Email/CustomGR/ITransportEmail.js +2 -2
  85. package/dist/Interfaces/Email/CustomGR/ITransportQuoteEmail.d.ts +12 -12
  86. package/dist/Interfaces/Email/CustomGR/ITransportQuoteEmail.js +2 -2
  87. package/dist/Interfaces/Email/CustomGR/IVegetalsEmail.d.ts +16 -16
  88. package/dist/Interfaces/Email/CustomGR/IVegetalsEmail.js +2 -2
  89. package/dist/Interfaces/Email/CustomGR/IWishlistEmail.d.ts +15 -15
  90. package/dist/Interfaces/Email/CustomGR/IWishlistEmail.js +2 -2
  91. package/dist/Interfaces/Email/IAbandonnedCartEmail.d.ts +29 -29
  92. package/dist/Interfaces/Email/IAbandonnedCartEmail.js +2 -2
  93. package/dist/Interfaces/Email/IAccountConfirmationEmail.d.ts +22 -22
  94. package/dist/Interfaces/Email/IAccountConfirmationEmail.js +2 -2
  95. package/dist/Interfaces/Email/IApplicationEmail.d.ts +19 -19
  96. package/dist/Interfaces/Email/IApplicationEmail.js +2 -2
  97. package/dist/Interfaces/Email/IBackInStockEmail.d.ts +21 -21
  98. package/dist/Interfaces/Email/IBackInStockEmail.js +2 -2
  99. package/dist/Interfaces/Email/IContactEmail.d.ts +20 -20
  100. package/dist/Interfaces/Email/IContactEmail.js +2 -2
  101. package/dist/Interfaces/Email/ICustomerBookingAdminEmail.d.ts +15 -15
  102. package/dist/Interfaces/Email/ICustomerBookingAdminEmail.js +2 -2
  103. package/dist/Interfaces/Email/ICustomerBookingEmail.d.ts +14 -14
  104. package/dist/Interfaces/Email/ICustomerBookingEmail.js +2 -2
  105. package/dist/Interfaces/Email/IEmail.d.ts +20 -20
  106. package/dist/Interfaces/Email/IEmail.js +69 -69
  107. package/dist/Interfaces/Email/IOrderConfirmationEmail.d.ts +47 -47
  108. package/dist/Interfaces/Email/IOrderConfirmationEmail.js +2 -2
  109. package/dist/Interfaces/Email/IPasswordResetEmail.d.ts +17 -17
  110. package/dist/Interfaces/Email/IPasswordResetEmail.js +2 -2
  111. package/dist/Interfaces/Email/IPhotoShootEmail.d.ts +14 -14
  112. package/dist/Interfaces/Email/IPhotoShootEmail.js +2 -2
  113. package/dist/Interfaces/Email/IPickupConfirmation.d.ts +23 -23
  114. package/dist/Interfaces/Email/IPickupConfirmation.js +2 -2
  115. package/dist/Interfaces/Email/IShippingConfirmation.d.ts +23 -23
  116. package/dist/Interfaces/Email/IShippingConfirmation.js +2 -2
  117. package/dist/Interfaces/Email/IWelcomeEmail.d.ts +19 -19
  118. package/dist/Interfaces/Email/IWelcomeEmail.js +2 -2
  119. package/dist/Interfaces/ExportSchema/index.d.ts +7 -7
  120. package/dist/Interfaces/ExportSchema/index.js +2 -2
  121. package/dist/Interfaces/ExternalService/BaseExternalService.d.ts +12 -12
  122. package/dist/Interfaces/ExternalService/BaseExternalService.js +2 -2
  123. package/dist/Interfaces/ExternalService/index.d.ts +9 -9
  124. package/dist/Interfaces/ExternalService/index.js +2 -2
  125. package/dist/Interfaces/FirstOrderTracking/index.d.ts +5 -5
  126. package/dist/Interfaces/FirstOrderTracking/index.js +2 -2
  127. package/dist/Interfaces/G2/index.d.ts +556 -556
  128. package/dist/Interfaces/G2/index.js +36 -36
  129. package/dist/Interfaces/Indexed/Product/IIndexedLastSavedProduct.d.ts +20 -20
  130. package/dist/Interfaces/Indexed/Product/IIndexedLastSavedProduct.js +2 -2
  131. package/dist/Interfaces/Indexed/Product/index.d.ts +94 -94
  132. package/dist/Interfaces/Indexed/Product/index.js +287 -287
  133. package/dist/Interfaces/Inventory/index.d.ts +19 -19
  134. package/dist/Interfaces/Inventory/index.js +8 -8
  135. package/dist/Interfaces/Invoice/index.d.ts +4 -4
  136. package/dist/Interfaces/Invoice/index.js +2 -2
  137. package/dist/Interfaces/MarketplacePublication/MarketplaceOrderData.d.ts +3 -3
  138. package/dist/Interfaces/MarketplacePublication/MarketplaceOrderData.js +2 -2
  139. package/dist/Interfaces/MarketplacePublication/index.d.ts +23 -23
  140. package/dist/Interfaces/MarketplacePublication/index.js +33 -33
  141. package/dist/Interfaces/Operations/ICreatedBy.d.ts +6 -6
  142. package/dist/Interfaces/Operations/ICreatedBy.js +2 -2
  143. package/dist/Interfaces/Operations/IUpdate.d.ts +5 -5
  144. package/dist/Interfaces/Operations/IUpdate.js +2 -2
  145. package/dist/Interfaces/Order/index.d.ts +4 -4
  146. package/dist/Interfaces/Order/index.js +2 -2
  147. package/dist/Interfaces/Org/IRelUser.d.ts +9 -9
  148. package/dist/Interfaces/Org/IRelUser.js +2 -2
  149. package/dist/Interfaces/Org/index.d.ts +29 -29
  150. package/dist/Interfaces/Org/index.js +12 -12
  151. package/dist/Interfaces/Payment/index.d.ts +13 -13
  152. package/dist/Interfaces/Payment/index.js +2 -2
  153. package/dist/Interfaces/Product/IAttributeFamily.d.ts +6 -6
  154. package/dist/Interfaces/Product/IAttributeFamily.js +2 -2
  155. package/dist/Interfaces/Product/IImportProduct.d.ts +42 -42
  156. package/dist/Interfaces/Product/IImportProduct.js +971 -971
  157. package/dist/Interfaces/Product/IInventoryItem.d.ts +84 -84
  158. package/dist/Interfaces/Product/IInventoryItem.js +36 -36
  159. package/dist/Interfaces/Product/IPricing.d.ts +177 -177
  160. package/dist/Interfaces/Product/IPricing.js +174 -174
  161. package/dist/Interfaces/Product/index.d.ts +121 -121
  162. package/dist/Interfaces/Product/index.js +56 -56
  163. package/dist/Interfaces/ProductAttribute/index.d.ts +11 -11
  164. package/dist/Interfaces/ProductAttribute/index.js +2 -2
  165. package/dist/Interfaces/PromiseToPurchase/BankType.d.ts +41 -41
  166. package/dist/Interfaces/PromiseToPurchase/BankType.js +42 -42
  167. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.d.ts +33 -33
  168. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +15 -15
  169. package/dist/Interfaces/PromiseToPurchase/IIndexedCustomerPromiseToPurchase.d.ts +19 -19
  170. package/dist/Interfaces/PromiseToPurchase/IIndexedCustomerPromiseToPurchase.js +2 -2
  171. package/dist/Interfaces/PromiseToPurchase/index.d.ts +50 -50
  172. package/dist/Interfaces/PromiseToPurchase/index.js +13 -13
  173. package/dist/Interfaces/PurchaseOrder/index.d.ts +17 -17
  174. package/dist/Interfaces/PurchaseOrder/index.js +2 -2
  175. package/dist/Interfaces/Query/IBrandQueryOptions.d.ts +11 -11
  176. package/dist/Interfaces/Query/IBrandQueryOptions.js +2 -2
  177. package/dist/Interfaces/Query/ICategoryQueryOptions.d.ts +11 -11
  178. package/dist/Interfaces/Query/ICategoryQueryOptions.js +2 -2
  179. package/dist/Interfaces/Query/IProductQueryOptions.d.ts +16 -16
  180. package/dist/Interfaces/Query/IProductQueryOptions.js +2 -2
  181. package/dist/Interfaces/Quote/index.d.ts +5 -5
  182. package/dist/Interfaces/Quote/index.js +2 -2
  183. package/dist/Interfaces/Refunds/index.d.ts +106 -106
  184. package/dist/Interfaces/Refunds/index.js +2 -2
  185. package/dist/Interfaces/Rules/IDiscountRule.d.ts +137 -137
  186. package/dist/Interfaces/Rules/IDiscountRule.js +107 -107
  187. package/dist/Interfaces/Schedule/index.d.ts +47 -46
  188. package/dist/Interfaces/Schedule/index.js +2 -2
  189. package/dist/Interfaces/Services/IAddServiceResponse.d.ts +4 -4
  190. package/dist/Interfaces/Services/IAddServiceResponse.js +2 -2
  191. package/dist/Interfaces/Services/IService.d.ts +12 -12
  192. package/dist/Interfaces/Services/IService.js +2 -2
  193. package/dist/Interfaces/Services/IServiceSecret.d.ts +8 -8
  194. package/dist/Interfaces/Services/IServiceSecret.js +2 -2
  195. package/dist/Interfaces/Shipping/Shipstation/carriers.d.ts +10 -10
  196. package/dist/Interfaces/Shipping/Shipstation/carriers.js +2 -2
  197. package/dist/Interfaces/Shipping/Shipstation/order.d.ts +227 -227
  198. package/dist/Interfaces/Shipping/Shipstation/order.js +2 -2
  199. package/dist/Interfaces/Shipping/Shipstation/quote.d.ts +31 -31
  200. package/dist/Interfaces/Shipping/Shipstation/quote.js +2 -2
  201. package/dist/Interfaces/Shipping/Shiptime/order.d.ts +54 -54
  202. package/dist/Interfaces/Shipping/Shiptime/order.js +48 -48
  203. package/dist/Interfaces/Shipping/Shiptime/quote.d.ts +111 -111
  204. package/dist/Interfaces/Shipping/Shiptime/quote.js +2 -2
  205. package/dist/Interfaces/Slider/GR.d.ts +130 -130
  206. package/dist/Interfaces/Slider/GR.js +271 -271
  207. package/dist/Interfaces/Slider/index.d.ts +14 -14
  208. package/dist/Interfaces/Slider/index.js +2 -2
  209. package/dist/Interfaces/Space/IMember.d.ts +16 -16
  210. package/dist/Interfaces/Space/IMember.js +9 -9
  211. package/dist/Interfaces/Space/index.d.ts +387 -387
  212. package/dist/Interfaces/Space/index.js +123 -123
  213. package/dist/Interfaces/Specials/gr.d.ts +61 -61
  214. package/dist/Interfaces/Specials/gr.js +2 -2
  215. package/dist/Interfaces/StockNotification/index.d.ts +7 -7
  216. package/dist/Interfaces/StockNotification/index.js +2 -2
  217. package/dist/Interfaces/Store/index.d.ts +62 -62
  218. package/dist/Interfaces/Store/index.js +27 -27
  219. package/dist/Interfaces/Supplier/ICommand.d.ts +11 -11
  220. package/dist/Interfaces/Supplier/ICommand.js +2 -2
  221. package/dist/Interfaces/Supplier/index.d.ts +36 -36
  222. package/dist/Interfaces/Supplier/index.js +24 -24
  223. package/dist/Interfaces/Tag/index.d.ts +18 -18
  224. package/dist/Interfaces/Tag/index.js +2 -2
  225. package/dist/Interfaces/Tax/index.d.ts +12 -12
  226. package/dist/Interfaces/Tax/index.js +2 -2
  227. package/dist/Interfaces/TransferRequest/index.d.ts +59 -59
  228. package/dist/Interfaces/TransferRequest/index.js +31 -31
  229. package/dist/Interfaces/Translation/index.d.ts +4 -4
  230. package/dist/Interfaces/Translation/index.js +2 -2
  231. package/dist/Interfaces/Update/index.d.ts +10 -10
  232. package/dist/Interfaces/Update/index.js +2 -2
  233. package/dist/Interfaces/User/IUser.d.ts +65 -65
  234. package/dist/Interfaces/User/IUser.js +8 -8
  235. package/dist/Interfaces/Version/index.d.ts +11 -11
  236. package/dist/Interfaces/Version/index.js +2 -2
  237. package/dist/Interfaces/Wishlist/index.d.ts +7 -7
  238. package/dist/Interfaces/Wishlist/index.js +2 -2
  239. package/dist/constants/Interfaces/IBaseApi.d.ts +15 -15
  240. package/dist/constants/Interfaces/IBaseApi.js +2 -2
  241. package/dist/constants/Interfaces/IEndpointResult.d.ts +9 -9
  242. package/dist/constants/Interfaces/IEndpointResult.js +2 -2
  243. package/dist/constants/enums.d.ts +6 -6
  244. package/dist/constants/enums.js +10 -10
  245. package/dist/constants/version.d.ts +2 -2
  246. package/dist/constants/version.js +5 -5
  247. package/dist/index.d.ts +32 -32
  248. package/dist/index.js +416 -416
  249. package/dist/lib/Attribute/index.d.ts +14 -14
  250. package/dist/lib/Attribute/index.js +248 -248
  251. package/dist/lib/BGJob/index.d.ts +9 -9
  252. package/dist/lib/BGJob/index.js +376 -376
  253. package/dist/lib/BackgroundWorker/index.d.ts +34 -34
  254. package/dist/lib/BackgroundWorker/index.js +72 -72
  255. package/dist/lib/Blog/BlogArticle.d.ts +5 -5
  256. package/dist/lib/Blog/BlogArticle.js +28 -28
  257. package/dist/lib/Blog/BlogAuthor.d.ts +5 -5
  258. package/dist/lib/Blog/BlogAuthor.js +28 -28
  259. package/dist/lib/Blog/BlogCategory.d.ts +5 -5
  260. package/dist/lib/Blog/BlogCategory.js +28 -28
  261. package/dist/lib/Blog/BlogKeyword.d.ts +5 -5
  262. package/dist/lib/Blog/BlogKeyword.js +28 -28
  263. package/dist/lib/Booking/index.d.ts +65 -65
  264. package/dist/lib/Booking/index.js +839 -839
  265. package/dist/lib/Brand/index.d.ts +17 -17
  266. package/dist/lib/Brand/index.js +275 -275
  267. package/dist/lib/Cart/index.d.ts +186 -186
  268. package/dist/lib/Cart/index.js +3982 -3982
  269. package/dist/lib/Catalogue/index.d.ts +9 -9
  270. package/dist/lib/Catalogue/index.js +207 -207
  271. package/dist/lib/Category/index.d.ts +26 -26
  272. package/dist/lib/Category/index.js +361 -361
  273. package/dist/lib/Class/index.d.ts +12 -12
  274. package/dist/lib/Class/index.js +159 -159
  275. package/dist/lib/Consent/index.d.ts +4 -4
  276. package/dist/lib/Consent/index.js +79 -79
  277. package/dist/lib/Customer/index.d.ts +10 -10
  278. package/dist/lib/Customer/index.js +147 -147
  279. package/dist/lib/Declination/index.d.ts +9 -9
  280. package/dist/lib/Declination/index.js +84 -84
  281. package/dist/lib/Discount/index.d.ts +18 -18
  282. package/dist/lib/Discount/index.js +759 -759
  283. package/dist/lib/ElasticSearch/index.d.ts +8 -8
  284. package/dist/lib/ElasticSearch/index.js +101 -101
  285. package/dist/lib/Email/AbandonedCartEmail.d.ts +8 -8
  286. package/dist/lib/Email/AbandonedCartEmail.js +78 -78
  287. package/dist/lib/Email/AccountConfirmationEmail.d.ts +11 -11
  288. package/dist/lib/Email/AccountConfirmationEmail.js +95 -95
  289. package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +8 -8
  290. package/dist/lib/Email/AdminOrderConfirmationEmail.js +78 -78
  291. package/dist/lib/Email/ApplicationEmail.d.ts +8 -8
  292. package/dist/lib/Email/ApplicationEmail.js +78 -78
  293. package/dist/lib/Email/BackInStockEmail.d.ts +8 -8
  294. package/dist/lib/Email/BackInStockEmail.js +78 -78
  295. package/dist/lib/Email/ContactEmail.d.ts +8 -8
  296. package/dist/lib/Email/ContactEmail.js +78 -78
  297. package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +8 -8
  298. package/dist/lib/Email/CustomerBookingAdminEmail.js +78 -78
  299. package/dist/lib/Email/CustomerBookingEmail.d.ts +8 -8
  300. package/dist/lib/Email/CustomerBookingEmail.js +78 -78
  301. package/dist/lib/Email/OrderConfirmationEmail.d.ts +8 -8
  302. package/dist/lib/Email/OrderConfirmationEmail.js +78 -78
  303. package/dist/lib/Email/OrderDenounciationEmail.d.ts +8 -8
  304. package/dist/lib/Email/OrderDenounciationEmail.js +78 -78
  305. package/dist/lib/Email/OrderSampleEmail.d.ts +8 -8
  306. package/dist/lib/Email/OrderSampleEmail.js +78 -78
  307. package/dist/lib/Email/OtherTypeEmails.d.ts +8 -8
  308. package/dist/lib/Email/OtherTypeEmails.js +90 -90
  309. package/dist/lib/Email/PasswordResetEmail.d.ts +8 -8
  310. package/dist/lib/Email/PasswordResetEmail.js +78 -78
  311. package/dist/lib/Email/PhotoShootEmail.d.ts +8 -8
  312. package/dist/lib/Email/PhotoShootEmail.js +78 -78
  313. package/dist/lib/Email/PickUpConfirmation.d.ts +8 -8
  314. package/dist/lib/Email/PickUpConfirmation.js +78 -78
  315. package/dist/lib/Email/ShippingConfirmation.d.ts +8 -8
  316. package/dist/lib/Email/ShippingConfirmation.js +78 -78
  317. package/dist/lib/Email/WelcomeEmail.d.ts +8 -8
  318. package/dist/lib/Email/WelcomeEmail.js +78 -78
  319. package/dist/lib/Email/index.d.ts +8 -8
  320. package/dist/lib/Email/index.js +82 -82
  321. package/dist/lib/ExternalService/Ebay.d.ts +62 -62
  322. package/dist/lib/ExternalService/Ebay.js +184 -184
  323. package/dist/lib/ExternalService/index.d.ts +5 -5
  324. package/dist/lib/ExternalService/index.js +28 -28
  325. package/dist/lib/FirstOrderTracking/index.d.ts +5 -5
  326. package/dist/lib/FirstOrderTracking/index.js +28 -28
  327. package/dist/lib/Indexed/IndexedCart.d.ts +13 -13
  328. package/dist/lib/Indexed/IndexedCart.js +194 -194
  329. package/dist/lib/Indexed/Product.d.ts +17 -17
  330. package/dist/lib/Indexed/Product.js +116 -116
  331. package/dist/lib/Inventory/index.d.ts +32 -32
  332. package/dist/lib/Inventory/index.js +579 -579
  333. package/dist/lib/Invoice/index.d.ts +5 -5
  334. package/dist/lib/Invoice/index.js +28 -28
  335. package/dist/lib/MarketplacePublication/index.d.ts +9 -9
  336. package/dist/lib/MarketplacePublication/index.js +220 -220
  337. package/dist/lib/MongoDB/BaseAPI.d.ts +18 -18
  338. package/dist/lib/MongoDB/BaseAPI.js +308 -308
  339. package/dist/lib/Order/index.d.ts +7 -7
  340. package/dist/lib/Order/index.js +62 -62
  341. package/dist/lib/Org/index.d.ts +26 -26
  342. package/dist/lib/Org/index.js +283 -283
  343. package/dist/lib/PandaPay/index.d.ts +16 -16
  344. package/dist/lib/PandaPay/index.js +218 -218
  345. package/dist/lib/Paysafe/index.d.ts +11 -11
  346. package/dist/lib/Paysafe/index.js +100 -100
  347. package/dist/lib/Product/index.d.ts +143 -143
  348. package/dist/lib/Product/index.js +1326 -1326
  349. package/dist/lib/ProductAttribute/index.d.ts +15 -15
  350. package/dist/lib/ProductAttribute/index.js +114 -114
  351. package/dist/lib/PromiseToPurchase/index.d.ts +37 -37
  352. package/dist/lib/PromiseToPurchase/index.js +475 -475
  353. package/dist/lib/PurchaseOrder/index.d.ts +9 -9
  354. package/dist/lib/PurchaseOrder/index.js +72 -72
  355. package/dist/lib/Schedule/index.d.ts +5 -5
  356. package/dist/lib/Schedule/index.js +30 -30
  357. package/dist/lib/Service/Enum/ServiceEnum.d.ts +3 -3
  358. package/dist/lib/Service/Enum/ServiceEnum.js +7 -7
  359. package/dist/lib/Service/index.d.ts +5 -5
  360. package/dist/lib/Service/index.js +57 -57
  361. package/dist/lib/Shipment/index.d.ts +28 -28
  362. package/dist/lib/Shipment/index.js +562 -562
  363. package/dist/lib/Slider/index.d.ts +16 -16
  364. package/dist/lib/Slider/index.js +235 -235
  365. package/dist/lib/Space/index.d.ts +801 -801
  366. package/dist/lib/Space/index.js +6862 -6862
  367. package/dist/lib/StockNotification/index.d.ts +4 -4
  368. package/dist/lib/StockNotification/index.js +26 -26
  369. package/dist/lib/Store/index.d.ts +5 -5
  370. package/dist/lib/Store/index.js +30 -30
  371. package/dist/lib/Supplier/Command.d.ts +5 -5
  372. package/dist/lib/Supplier/Command.js +28 -28
  373. package/dist/lib/Supplier/index.d.ts +25 -25
  374. package/dist/lib/Supplier/index.js +86 -86
  375. package/dist/lib/Tags/index.d.ts +6 -6
  376. package/dist/lib/Tags/index.js +84 -84
  377. package/dist/lib/Tax/index.d.ts +8 -8
  378. package/dist/lib/Tax/index.js +136 -136
  379. package/dist/lib/TransferRequest/index.d.ts +21 -21
  380. package/dist/lib/TransferRequest/index.js +302 -302
  381. package/dist/lib/Update/index.d.ts +10 -10
  382. package/dist/lib/Update/index.js +71 -71
  383. package/dist/lib/User/index.d.ts +33 -33
  384. package/dist/lib/User/index.js +360 -360
  385. package/dist/lib/Wishlist/index.d.ts +5 -5
  386. package/dist/lib/Wishlist/index.js +28 -28
  387. package/dist/lib/base.d.ts +14 -14
  388. package/dist/lib/base.js +135 -135
  389. package/dist/lib/baseService.d.ts +17 -17
  390. package/dist/lib/baseService.js +113 -113
  391. package/dist/rules/GR/constants/data.d.ts +25 -25
  392. package/dist/rules/GR/constants/data.js +54 -54
  393. package/dist/rules/GR/constants/products.d.ts +8 -8
  394. package/dist/rules/GR/constants/products.js +234 -234
  395. package/dist/rules/GR/interfaces/cart.d.ts +83 -83
  396. package/dist/rules/GR/interfaces/cart.js +51 -51
  397. package/dist/rules/GR/interfaces/data.d.ts +97 -97
  398. package/dist/rules/GR/interfaces/data.js +104 -104
  399. package/dist/rules/GR/interfaces/products.d.ts +61 -61
  400. package/dist/rules/GR/interfaces/products.js +10 -10
  401. package/dist/rules/GR/utils/cart.d.ts +53 -53
  402. package/dist/rules/GR/utils/cart.js +767 -767
  403. package/dist/rules/GR/utils/data.d.ts +3 -3
  404. package/dist/rules/GR/utils/data.js +25 -25
  405. package/dist/rules/GR/utils/expedition.d.ts +65 -65
  406. package/dist/rules/GR/utils/expedition.js +1676 -1676
  407. package/dist/rules/GR/utils/g2.d.ts +174 -174
  408. package/dist/rules/GR/utils/g2.js +1025 -1025
  409. package/dist/rules/GR/utils/invoices.d.ts +16 -16
  410. package/dist/rules/GR/utils/invoices.js +181 -181
  411. package/dist/rules/GR/utils/products.d.ts +96 -96
  412. package/dist/rules/GR/utils/products.js +1085 -1085
  413. package/dist/rules/GR/utils/upsells.d.ts +75 -75
  414. package/dist/rules/GR/utils/upsells.js +278 -278
  415. package/dist/services/database/BaseProvider.d.ts +29 -29
  416. package/dist/services/database/BaseProvider.js +77 -77
  417. package/dist/services/database/BatchUtils.d.ts +14 -14
  418. package/dist/services/database/BatchUtils.js +88 -88
  419. package/dist/services/database/Config.d.ts +2 -2
  420. package/dist/services/database/Config.js +5 -5
  421. package/dist/services/database/DatabaseService.d.ts +41 -41
  422. package/dist/services/database/DatabaseService.js +297 -297
  423. package/dist/services/database/FirebaseProvider.d.ts +17 -17
  424. package/dist/services/database/FirebaseProvider.js +312 -312
  425. package/dist/services/database/NotFirebaseProvider.d.ts +35 -35
  426. package/dist/services/database/NotFirebaseProvider.js +380 -380
  427. package/dist/services/g2/G2OrderSlip.d.ts +42 -42
  428. package/dist/services/g2/G2OrderSlip.js +264 -264
  429. package/dist/services/g2/utils.d.ts +9 -9
  430. package/dist/services/g2/utils.js +919 -919
  431. package/dist/services/logs/index.d.ts +20 -20
  432. package/dist/services/logs/index.js +126 -126
  433. package/dist/utils/algolia.d.ts +6 -6
  434. package/dist/utils/algolia.js +22 -22
  435. package/dist/utils/anonymisation.d.ts +30 -30
  436. package/dist/utils/anonymisation.js +264 -264
  437. package/dist/utils/array.d.ts +5 -5
  438. package/dist/utils/array.js +36 -36
  439. package/dist/utils/aws.d.ts +14 -14
  440. package/dist/utils/aws.js +220 -220
  441. package/dist/utils/booking.d.ts +22 -22
  442. package/dist/utils/booking.js +175 -175
  443. package/dist/utils/cart.d.ts +69 -69
  444. package/dist/utils/cart.js +656 -656
  445. package/dist/utils/cmv.d.ts +10 -10
  446. package/dist/utils/cmv.js +107 -107
  447. package/dist/utils/console.d.ts +6 -6
  448. package/dist/utils/console.js +121 -121
  449. package/dist/utils/context.d.ts +19 -19
  450. package/dist/utils/context.js +41 -41
  451. package/dist/utils/currency.d.ts +6 -6
  452. package/dist/utils/currency.js +62 -62
  453. package/dist/utils/data.d.ts +31 -31
  454. package/dist/utils/data.js +300 -300
  455. package/dist/utils/date.d.ts +1 -1
  456. package/dist/utils/date.js +16 -16
  457. package/dist/utils/dimensions.d.ts +3 -3
  458. package/dist/utils/dimensions.js +18 -18
  459. package/dist/utils/discount.d.ts +46 -46
  460. package/dist/utils/discount.js +981 -981
  461. package/dist/utils/errors.d.ts +113 -113
  462. package/dist/utils/errors.js +113 -113
  463. package/dist/utils/file-admin.d.ts +8 -8
  464. package/dist/utils/file-admin.js +94 -94
  465. package/dist/utils/file.d.ts +38 -38
  466. package/dist/utils/file.js +318 -318
  467. package/dist/utils/firebase-admin.d.ts +2 -2
  468. package/dist/utils/firebase-admin.js +118 -118
  469. package/dist/utils/firebase.d.ts +41 -41
  470. package/dist/utils/firebase.js +220 -220
  471. package/dist/utils/import.d.ts +1 -1
  472. package/dist/utils/import.js +81 -81
  473. package/dist/utils/inventories.d.ts +34 -34
  474. package/dist/utils/inventories.js +432 -432
  475. package/dist/utils/locale.d.ts +13 -13
  476. package/dist/utils/locale.js +67 -67
  477. package/dist/utils/mailchimp.d.ts +58 -58
  478. package/dist/utils/mailchimp.js +735 -735
  479. package/dist/utils/mongodb.d.ts +1 -1
  480. package/dist/utils/mongodb.js +68 -68
  481. package/dist/utils/object.d.ts +12 -12
  482. package/dist/utils/object.js +129 -129
  483. package/dist/utils/payment.d.ts +10 -10
  484. package/dist/utils/payment.js +25 -25
  485. package/dist/utils/products.d.ts +26 -26
  486. package/dist/utils/products.js +301 -301
  487. package/dist/utils/promiseToPurchase.d.ts +56 -56
  488. package/dist/utils/promiseToPurchase.js +228 -228
  489. package/dist/utils/prosprsearch.d.ts +21 -21
  490. package/dist/utils/prosprsearch.js +276 -276
  491. package/dist/utils/refunds.d.ts +2 -2
  492. package/dist/utils/refunds.js +21 -21
  493. package/dist/utils/sdc.d.ts +10 -10
  494. package/dist/utils/sdc.js +1308 -1308
  495. package/dist/utils/searchIndexes.d.ts +21 -21
  496. package/dist/utils/searchIndexes.js +318 -318
  497. package/dist/utils/services.d.ts +40 -40
  498. package/dist/utils/services.js +407 -407
  499. package/dist/utils/shipment.d.ts +110 -110
  500. package/dist/utils/shipment.js +410 -410
  501. package/dist/utils/simpletexting.d.ts +2 -2
  502. package/dist/utils/simpletexting.js +91 -91
  503. package/dist/utils/sliders.d.ts +4 -4
  504. package/dist/utils/sliders.js +70 -70
  505. package/dist/utils/string.d.ts +16 -16
  506. package/dist/utils/string.js +194 -194
  507. package/dist/utils/tools.d.ts +1 -1
  508. package/dist/utils/tools.js +49 -49
  509. package/dist/utils/transferRequests.d.ts +16 -16
  510. package/dist/utils/transferRequests.js +33 -33
  511. package/dist/utils/update.d.ts +7 -7
  512. package/dist/utils/update.js +245 -245
  513. package/dist/utils/weight.d.ts +3 -3
  514. package/dist/utils/weight.js +18 -18
  515. package/dist/utils/zones.d.ts +11 -11
  516. package/dist/utils/zones.js +313 -313
  517. package/package.json +110 -110
  518. package/publish.sh +143 -143
  519. package/readme.md +182 -182
  520. package/dist/lib/Queue/index.d.ts +0 -40
  521. package/dist/lib/Queue/index.js +0 -255
  522. package/dist/lib/Queue/index.js.map +0 -1
@@ -1,1677 +1,1677 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
- var __importDefault = (this && this.__importDefault) || function (mod) {
59
- return (mod && mod.__esModule) ? mod : { "default": mod };
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.checkIfNoDeliveryDateIsNormal = exports.checkIfCartExpired = exports.getStoresForVracProdShipping = exports.calculateShippingForVrac = exports.checkIfShouldRemoveSampleShippingFee = exports.applyFeesToCart = exports.installationFeePalletTier = exports.expeditionFeePalletTier = exports.checkForSameGrassDayFee = exports.checkIfShouldApplySameDayGrassFee = exports.getMinQteInstall = exports.getMinGrassQte = exports.calculatePalFeeForOtherThanGrass = exports.getPalletQtyPalletFee = exports.getGrassRoundedPickupPalletFees = exports.getPalletQty = exports.slugsToCheckFromExpeditionFees = exports.checkIfCartTypeHasBlockedDates = exports.dateIsClosedInSchedule = exports.shouldDisableDate = exports.getMinDateOffset = exports.getMinDatePicker = exports.getAvailableHours = exports.getDefaultTimeValues = void 0;
63
- var moment_1 = __importDefault(require("moment"));
64
- var ceil_1 = __importDefault(require("lodash/ceil"));
65
- var findIndex_1 = __importDefault(require("lodash/findIndex"));
66
- var floor_1 = __importDefault(require("lodash/floor"));
67
- var round_1 = __importDefault(require("lodash/round"));
68
- var sumBy_1 = __importDefault(require("lodash/sumBy"));
69
- var toNumber_1 = __importDefault(require("lodash/toNumber"));
70
- var products_1 = require("../interfaces/products");
71
- var data_1 = require("./data");
72
- var products_2 = require("./products");
73
- var cart_1 = require("./cart");
74
- var g2_1 = require("./g2");
75
- var data_2 = require("../constants/data");
76
- var Cart_1 = require("../../../Interfaces/Cart");
77
- var data_3 = require("../../../utils/data");
78
- var products_3 = require("../../../utils/products");
79
- var cart_2 = require("../interfaces/cart");
80
- var data_4 = require("../interfaces/data");
81
- var products_4 = require("../constants/products");
82
- var object_1 = require("../../../utils/object");
83
- var getDefaultTimeValues = function () {
84
- var values = ['AM', 'PM'];
85
- return values.map(function (v) { return ({ label: v, value: v }); });
86
- };
87
- exports.getDefaultTimeValues = getDefaultTimeValues;
88
- var getAvailableHours = function (minDeliveryDate, selectedDate, grassProduct, concreteOrder, expeditionMethod, selectedDeliveryTime, isPro, isSample, isAccessoriesOnly, testDate, keepHours) {
89
- if (!!!minDeliveryDate)
90
- return { deliveryTimes: (0, exports.getDefaultTimeValues)() };
91
- var deliveryTimes = (0, exports.getDefaultTimeValues)().map(function (t) { return t.value; });
92
- var today = !!testDate
93
- ? !!keepHours
94
- ? (0, moment_1.default)(testDate).toDate()
95
- : (0, moment_1.default)(testDate).set('hours', (0, moment_1.default)().hours()).toDate()
96
- : (0, moment_1.default)().toDate();
97
- if (!!concreteOrder && !!concreteOrder.inStock && expeditionMethod === 'pickup') {
98
- var isPM = today.getHours() >= 12;
99
- if (!!isPM) {
100
- deliveryTimes = ['PM'];
101
- }
102
- return {
103
- deliveryTimes: deliveryTimes.map(function (t) { return ({ label: t, value: t }); }),
104
- newSelectedDeliveryTime: !!isPM ? { label: 'PM', value: 'PM' } : undefined
105
- };
106
- }
107
- var resetHours = function (d) {
108
- d.setHours(0);
109
- d.setMinutes(0);
110
- d.setSeconds(0);
111
- d.setMilliseconds(0);
112
- };
113
- if (!!selectedDate)
114
- resetHours(selectedDate);
115
- resetHours(minDeliveryDate);
116
- var newSelectedDeliveryTime = undefined;
117
- var targetDateDay = minDeliveryDate.getDay();
118
- var selectedDateDay = !!selectedDate ? selectedDate.getDay() : targetDateDay;
119
- var isSelectedSameAsTarget = (0, moment_1.default)(minDeliveryDate).isSame(selectedDate) || !!!selectedDate;
120
- var todayDay = today.getDay();
121
- var isNonSpecialityGrass = !!grassProduct && !![products_4.kentucky, products_4.prestige].includes(grassProduct.sku);
122
- var onlyPm = function () {
123
- if (!!selectedDeliveryTime && selectedDeliveryTime === 'AM') {
124
- newSelectedDeliveryTime = { label: 'PM', value: 'PM' };
125
- }
126
- deliveryTimes = ['PM'];
127
- };
128
- if (selectedDateDay === 0 || (selectedDateDay === 6 && !!!isPro && expeditionMethod === 'pickup')) {
129
- deliveryTimes = [];
130
- newSelectedDeliveryTime = undefined;
131
- }
132
- else {
133
- if (isSelectedSameAsTarget) {
134
- if (!!grassProduct || (!!concreteOrder && concreteOrder.type === 'green')) {
135
- var todayReset = !!testDate ? (0, moment_1.default)(testDate).toDate() : (0, moment_1.default)().toDate();
136
- resetHours(todayReset);
137
- if (!![6, 0].includes(todayReset.getDay())) {
138
- if ((![2].includes(targetDateDay) &&
139
- (!!isNonSpecialityGrass ||
140
- (!!concreteOrder && !concreteOrder.inStock && expeditionMethod === 'pickup'))) ||
141
- (![3, 4].includes(targetDateDay) && !!!isNonSpecialityGrass)) {
142
- if (targetDateDay === 6 && !!!isPro && expeditionMethod === 'pickup') {
143
- newSelectedDeliveryTime = undefined;
144
- deliveryTimes = [];
145
- }
146
- else {
147
- var amTimeToCheck = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
148
- if (today.getHours() >= amTimeToCheck) {
149
- onlyPm();
150
- }
151
- }
152
- }
153
- }
154
- else {
155
- var targetHour = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
156
- if (todayDay == 5 &&
157
- (!!grassProduct || (!!concreteOrder && concreteOrder.type == 'green' && expeditionMethod == 'pickup'))) {
158
- targetHour = 16;
159
- }
160
- if (today.getHours() >= targetHour) {
161
- onlyPm();
162
- }
163
- }
164
- }
165
- if ((!!!grassProduct && !!!concreteOrder) || !!isSample || !!isAccessoriesOnly) {
166
- if (today.getHours() > 10) {
167
- onlyPm();
168
- }
169
- }
170
- }
171
- }
172
- return {
173
- deliveryTimes: deliveryTimes.map(function (t) { return ({ label: t, value: t }); }),
174
- newSelectedDeliveryTime: newSelectedDeliveryTime ? newSelectedDeliveryTime : undefined
175
- };
176
- };
177
- exports.getAvailableHours = getAvailableHours;
178
- var isDegel = function (dateToCheck) {
179
- var date = !!dateToCheck ? (0, moment_1.default)(dateToCheck) : (0, moment_1.default)();
180
- return date.isBetween('2024-03-04 00:00:01', '2024-04-15 23:59:59', undefined, '[]');
181
- };
182
- var getMinDatePicker = function (cartData, grassProduct, concreteOrder, expeditionMethod, isPro, testDate, blockedShippingDates, vracType, isPOS, spaceSchedule) {
183
- var cartContainsInstallation = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.INSTALLATION, cartData);
184
- var cartContainsVrac = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.VRAC, cartData);
185
- var isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
186
- var minDates = {};
187
- if (!!testDate && !isPOS) {
188
- testDate.setHours((0, moment_1.default)().hours());
189
- }
190
- var now = testDate || (0, moment_1.default)().toDate();
191
- var min_date = testDate || (0, moment_1.default)().toDate();
192
- var nbDaysOffset = (0, exports.getMinDateOffset)(now, cartContainsInstallation, cartContainsVrac, cartData, grassProduct, concreteOrder, isAccessoriesOnly, expeditionMethod, vracType);
193
- var typeToCheck = !!concreteOrder
194
- ? 'beton'
195
- : !!grassProduct
196
- ? 'gazon'
197
- : !!cartContainsVrac || (!!!isPro && !!vracType)
198
- ? 'vrac'
199
- : undefined;
200
- var dateToCheck = new Date(min_date);
201
- dateToCheck.setDate(min_date.getDate() + nbDaysOffset);
202
- var pickupDateSameAsNewDate = false;
203
- var blockedDays = {
204
- vrac: [0],
205
- beton: [0],
206
- gazon: [0]
207
- };
208
- var getNextAvailableDay = function (type) {
209
- var dayToCheck = dateToCheck.getDay();
210
- if (!!blockedDays[type]) {
211
- if (blockedDays[type].includes(dayToCheck)) {
212
- dateToCheck.setDate(dateToCheck.getDate() + 1);
213
- return getNextAvailableDay(type);
214
- }
215
- }
216
- if (!!spaceSchedule && expeditionMethod === 'pickup') {
217
- var storeId = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.pickup_store.id');
218
- if (!!storeId && !!(0, exports.dateIsClosedInSchedule)(storeId, dateToCheck, spaceSchedule)) {
219
- dateToCheck.setDate(dateToCheck.getDate() + 1);
220
- return getNextAvailableDay(type);
221
- }
222
- }
223
- min_date = dateToCheck;
224
- min_date.setHours(0);
225
- min_date.setMinutes(0);
226
- min_date.setSeconds(0);
227
- };
228
- if (!!typeToCheck) {
229
- getNextAvailableDay(typeToCheck);
230
- if (typeToCheck === 'vrac') {
231
- pickupDateSameAsNewDate = true;
232
- }
233
- }
234
- if (!!blockedShippingDates && blockedShippingDates.length && !!typeToCheck && expeditionMethod === 'delivery') {
235
- var blockedDatesToCheck = blockedShippingDates.find(function (blockedDate) { return blockedDate.cart_type === typeToCheck; });
236
- if (!!blockedDatesToCheck && !!blockedDatesToCheck.dates && !!blockedDatesToCheck.dates.length) {
237
- var isInBlockedPeriod = blockedDatesToCheck.dates.find(function (blocked) {
238
- return (!!blocked.start_date &&
239
- !!blocked.end_date &&
240
- (0, moment_1.default)(dateToCheck).isBetween((0, moment_1.default)((0, data_3.formatDate)(blocked.start_date)), (0, moment_1.default)((0, data_3.formatDate)(blocked.end_date)), 'date', '[]'));
241
- });
242
- if (!!isInBlockedPeriod) {
243
- dateToCheck = (0, moment_1.default)((0, data_3.formatDate)(isInBlockedPeriod.end_date)).add(1, 'days').toDate();
244
- getNextAvailableDay(typeToCheck);
245
- var pickup_date = !!pickupDateSameAsNewDate ? dateToCheck : (0, moment_1.default)(min_date).toDate();
246
- return {
247
- min_delivery: min_date,
248
- min_pickup: pickup_date
249
- };
250
- }
251
- }
252
- }
253
- if (!!!concreteOrder || concreteOrder.type !== 'yellow') {
254
- min_date.setDate(dateToCheck.getDate());
255
- min_date.setHours(0);
256
- min_date.setMinutes(0);
257
- min_date.setSeconds(0);
258
- var pickup_date = (0, moment_1.default)(min_date).toDate();
259
- minDates = {
260
- min_delivery: min_date,
261
- min_pickup: pickup_date
262
- };
263
- }
264
- return minDates;
265
- };
266
- exports.getMinDatePicker = getMinDatePicker;
267
- var getMinDateOffset = function (now, cartContainsInstallation, cartContainsVrac, cartData, grassProduct, concreteOrder, isAccessoriesOnly, expeditionMethod, vracType) {
268
- var current_hour = now.getHours();
269
- var current_day = now.getDay();
270
- var nb_days_offset = 1;
271
- var allGrassDelaysSameAsNonSpecialityGrasses = true;
272
- if (!!cartContainsInstallation) {
273
- switch (current_day) {
274
- case 5:
275
- nb_days_offset = 3;
276
- break;
277
- default:
278
- nb_days_offset = 2;
279
- break;
280
- }
281
- }
282
- else if (cartData.items.find(function (item) { return item.is_sample; }) || !!isAccessoriesOnly) {
283
- if (expeditionMethod === 'delivery') {
284
- nb_days_offset = 7;
285
- }
286
- else {
287
- switch (current_day) {
288
- case 4:
289
- nb_days_offset = 4;
290
- break;
291
- case 5:
292
- nb_days_offset = current_hour < 10 ? 3 : 4;
293
- break;
294
- case 6:
295
- nb_days_offset = 4;
296
- break;
297
- case 0:
298
- nb_days_offset = 3;
299
- break;
300
- default:
301
- nb_days_offset = 2;
302
- }
303
- }
304
- }
305
- else if (expeditionMethod === 'delivery' &&
306
- !!cartContainsVrac &&
307
- !!(0, object_1.recursiveCheckObject)(vracType, 'vrac_type') &&
308
- [products_1.VracTypeEnum.AUTRE_TONNE, products_1.VracTypeEnum.NOBEL_TONNE].includes(vracType.vrac_type)) {
309
- nb_days_offset = 1;
310
- }
311
- else if ((!!grassProduct &&
312
- ([products_4.kentucky, products_4.prestige].includes(grassProduct.sku) || !!allGrassDelaysSameAsNonSpecialityGrasses)) ||
313
- (!!concreteOrder && concreteOrder.type === 'green' && !concreteOrder.inStock && expeditionMethod === 'pickup')) {
314
- var amTimeToCheck = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
315
- switch (current_day) {
316
- case 5:
317
- nb_days_offset = current_hour < amTimeToCheck ? 1 : current_hour < 16 ? 3 : 3;
318
- break;
319
- case 6:
320
- nb_days_offset = 3;
321
- break;
322
- case 0:
323
- nb_days_offset = 2;
324
- break;
325
- default:
326
- nb_days_offset = 1;
327
- }
328
- }
329
- else if (!!concreteOrder &&
330
- concreteOrder.type === 'green' &&
331
- concreteOrder.inStock &&
332
- expeditionMethod === 'pickup') {
333
- nb_days_offset = 0;
334
- }
335
- else if (!!grassProduct && !!![products_4.kentucky, products_4.prestige].includes(grassProduct.sku)) {
336
- switch (current_day) {
337
- case 5:
338
- case 6:
339
- case 0:
340
- nb_days_offset = 4;
341
- break;
342
- default:
343
- nb_days_offset = 2;
344
- }
345
- }
346
- else if (!!concreteOrder && concreteOrder.type === 'green' && expeditionMethod === 'delivery') {
347
- switch (current_day) {
348
- case 0:
349
- nb_days_offset = 3;
350
- break;
351
- case 1:
352
- case 2:
353
- case 3:
354
- nb_days_offset = current_hour < 10 ? 2 : 3;
355
- break;
356
- case 4:
357
- nb_days_offset = current_hour < 10 ? 2 : current_hour < 16 ? 4 : 5;
358
- break;
359
- case 5:
360
- nb_days_offset = current_hour < 16 ? 4 : 5;
361
- break;
362
- case 6:
363
- nb_days_offset = 4;
364
- break;
365
- default:
366
- break;
367
- }
368
- }
369
- else if (expeditionMethod === 'delivery') {
370
- switch (current_day) {
371
- case 0:
372
- nb_days_offset = 4;
373
- break;
374
- case 1:
375
- case 2:
376
- nb_days_offset = current_hour < 10 ? 3 : 4;
377
- break;
378
- case 3:
379
- nb_days_offset = current_hour < 10 ? 3 : 6;
380
- break;
381
- case 4:
382
- case 5:
383
- nb_days_offset = current_hour < 10 ? 5 : 6;
384
- break;
385
- case 6:
386
- nb_days_offset = 5;
387
- break;
388
- default:
389
- break;
390
- }
391
- }
392
- return nb_days_offset;
393
- };
394
- exports.getMinDateOffset = getMinDateOffset;
395
- var shouldDisableDate = function (date, blockedDates, expeditionMethod, cartData, schedule, selectedStore) {
396
- if (!!!cartData)
397
- return false;
398
- var typeToCheck = (0, cart_1.getCartType)(cartData);
399
- var blockedDays = {
400
- vrac: [0],
401
- beton: [0],
402
- gazon: [0],
403
- only_accessories: [0],
404
- sample: [0]
405
- };
406
- if (!!!typeToCheck || (!!blockedDays[typeToCheck] && !!blockedDays[typeToCheck].includes(date.getDay()))) {
407
- return true;
408
- }
409
- if (expeditionMethod !== 'pickup' && !!typeToCheck && !!blockedDates) {
410
- var sameType = blockedDates.find(function (blocked) { return blocked.cart_type === typeToCheck; });
411
- if (!!sameType && !!sameType.dates) {
412
- for (var _i = 0, _a = sameType.dates; _i < _a.length; _i++) {
413
- var dates = _a[_i];
414
- if (!!dates.start_date &&
415
- !!dates.end_date &&
416
- (0, moment_1.default)(date).isBetween((0, moment_1.default)((0, data_3.formatDate)(dates.start_date)), (0, moment_1.default)((0, data_3.formatDate)(dates.end_date)), 'date', '[]'))
417
- return true;
418
- }
419
- }
420
- }
421
- var storeId = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.pickup_store.id');
422
- if ((!!storeId || !!selectedStore) && expeditionMethod === 'pickup' && !!schedule) {
423
- return !!(0, exports.dateIsClosedInSchedule)(!!storeId ? storeId : selectedStore, date, schedule);
424
- }
425
- return false;
426
- };
427
- exports.shouldDisableDate = shouldDisableDate;
428
- var dateIsClosedInSchedule = function (storeId, dateToCheck, spaceSchedule) {
429
- var _a;
430
- var weekdayIndex = dateToCheck.getDay();
431
- var storeSchedules = spaceSchedule.store_schedules[storeId];
432
- if (!!storeSchedules) {
433
- var selectedDaySchedule = void 0;
434
- if (!!spaceSchedule.space_periods_active) {
435
- var year = dateToCheck.getFullYear().toString();
436
- var periods = (_a = spaceSchedule.year_periods[year]) !== null && _a !== void 0 ? _a : [];
437
- var matchingPeriod = periods.find(function (p) { return new Date(p.starts_at) <= dateToCheck && dateToCheck <= new Date(p.ends_at); });
438
- if (!!matchingPeriod) {
439
- var periodSchedule = storeSchedules[matchingPeriod.id];
440
- if (!!periodSchedule) {
441
- var daySchedule = periodSchedule.weekly_schedule[weekdayIndex];
442
- if (!!daySchedule) {
443
- selectedDaySchedule = daySchedule;
444
- }
445
- }
446
- }
447
- }
448
- if (!!!selectedDaySchedule) {
449
- var generalSchedule = storeSchedules['general'];
450
- if (!!generalSchedule) {
451
- selectedDaySchedule = generalSchedule.weekly_schedule[weekdayIndex];
452
- }
453
- }
454
- if (!!selectedDaySchedule && selectedDaySchedule.open === false) {
455
- return true;
456
- }
457
- }
458
- var isClosed = spaceSchedule.common_closed_days.some(function (c) {
459
- var start = new Date(c.start_date);
460
- var end = c.end_date ? new Date(c.end_date) : start;
461
- start.setFullYear(dateToCheck.getFullYear());
462
- start.setHours(0, 0, 0, 0);
463
- end.setFullYear(dateToCheck.getFullYear());
464
- end.setHours(0, 0, 0, 0);
465
- dateToCheck.setHours(0, 0, 0, 0);
466
- return c.open === false && dateToCheck >= start && dateToCheck <= end && !!c.associated_stores.includes(storeId);
467
- });
468
- return isClosed;
469
- };
470
- exports.dateIsClosedInSchedule = dateIsClosedInSchedule;
471
- var checkIfCartTypeHasBlockedDates = function (cartData, blockedDates) {
472
- if (!!!cartData || !!!blockedDates || !!!blockedDates.length)
473
- return false;
474
- var cartType = (0, cart_1.getCartType)(cartData);
475
- var sameType = blockedDates.find(function (blocked) { return blocked.cart_type === cartType; });
476
- if (!!!sameType)
477
- return false;
478
- return !!sameType.dates && !!sameType.dates.length;
479
- };
480
- exports.checkIfCartTypeHasBlockedDates = checkIfCartTypeHasBlockedDates;
481
- exports.slugsToCheckFromExpeditionFees = {
482
- pickup: ['frais-preparation-general-beton', 'frais-palette', 'minimum-facturable-commande'],
483
- shipping: [
484
- 'livraison-echantillons',
485
- 'livraison-accessoires',
486
- 'livraison-beton-accessoires',
487
- 'livraison-gazon',
488
- 'frais-de-livraison-vrac',
489
- 'minimum-facturable-commande'
490
- ]
491
- };
492
- var getPalletQty = function (items, orderType, minQteGrassOrder) {
493
- if (minQteGrassOrder === void 0) { minQteGrassOrder = 0; }
494
- var total = (0, sumBy_1.default)(items.map(function (item) {
495
- if (!!!item.other_units ||
496
- !!item.is_service ||
497
- !!item.is_sample ||
498
- (!!orderType && !!['grass'].includes(orderType) && item.sku === products_4.kentucky && !!item.is_upsell_of_sku)) {
499
- return 0;
500
- }
501
- var paletteUnit = item.other_units.find(function (u) { return u.unit_slug === 'pal'; });
502
- var sellUnitCheck = item.other_units.find(function (u) { return !!u.is_sale_unit; });
503
- var sellUnit = 1;
504
- if (!!sellUnitCheck) {
505
- sellUnit = !!sellUnitCheck.fitting_unit ? sellUnitCheck.fitting_unit : 1;
506
- }
507
- if (!!!paletteUnit || !!!paletteUnit.fitting_unit) {
508
- return 0;
509
- }
510
- var typeAttr = item.attributes[data_4.AttributesIdEnumGR.TYPE];
511
- if (!!!typeAttr || !!!typeAttr.length) {
512
- return 0;
513
- }
514
- if (!!typeAttr && !typeAttr.includes('gazon') && !typeAttr.includes('beton')) {
515
- return (0, floor_1.default)((item.qte * sellUnit) / paletteUnit.fitting_unit);
516
- }
517
- if (!!typeAttr.includes('gazon') && !!minQteGrassOrder && item.qte < minQteGrassOrder) {
518
- return minQteGrassOrder / paletteUnit.fitting_unit;
519
- }
520
- return (item.qte * sellUnit) / paletteUnit.fitting_unit;
521
- }));
522
- if (orderType === 'concrete') {
523
- return (0, ceil_1.default)(total);
524
- }
525
- return total;
526
- };
527
- exports.getPalletQty = getPalletQty;
528
- var getGrassRoundedPickupPalletFees = function (realPalletNumber) {
529
- var ratio = (0, round_1.default)(400 / 740, 3);
530
- var fraction = (0, round_1.default)(realPalletNumber % 1, 3);
531
- if (fraction >= ratio)
532
- return (0, ceil_1.default)(realPalletNumber);
533
- return (0, floor_1.default)(realPalletNumber);
534
- };
535
- exports.getGrassRoundedPickupPalletFees = getGrassRoundedPickupPalletFees;
536
- var getPalletQtyPalletFee = function (items, expeditionMethod, isGrass, isMixed) {
537
- var totalPalletGrass = 0;
538
- var totalPalletOther = 0;
539
- items = items.filter(function (i) { return !(0, products_2.checkIfProductIsOfType)(i, 'accessoire'); });
540
- if (!!isGrass) {
541
- var grassItemsToCheck = !!isMixed ? items.filter(function (i) { return !!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); }) : items;
542
- var calculatedPalletsGrass = (0, exports.getPalletQty)(grassItemsToCheck, 'grass');
543
- totalPalletGrass =
544
- expeditionMethod === 'pickup'
545
- ? (0, exports.getGrassRoundedPickupPalletFees)(calculatedPalletsGrass)
546
- : (0, ceil_1.default)(calculatedPalletsGrass);
547
- }
548
- if (!!!isGrass || !!isMixed) {
549
- var otherItemsToCheck = !!isMixed ? items.filter(function (i) { return !!!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); }) : items;
550
- totalPalletOther = (0, exports.calculatePalFeeForOtherThanGrass)(otherItemsToCheck);
551
- }
552
- var totalPallet = totalPalletGrass + totalPalletOther;
553
- return totalPallet;
554
- };
555
- exports.getPalletQtyPalletFee = getPalletQtyPalletFee;
556
- var calculatePalFeeForOtherThanGrass = function (items) {
557
- var total = (0, sumBy_1.default)(items.map(function (item) {
558
- if (!!!item.other_units || !!item.is_service || !!item.is_sample) {
559
- return 0;
560
- }
561
- var exceptions = [
562
- 'muret-supra-citadin-180',
563
- 'muret-m-100-serie-moderne-double-face',
564
- 'muret-ora-double-face',
565
- 'pas-japonais-grand',
566
- 'marche-nueva',
567
- 'marche-aria',
568
- 'marche-t-200',
569
- 'marche-solino',
570
- 'marche-caralina',
571
- 'marche-rio-15',
572
- 'marche-appalaches',
573
- 'marche-citadin',
574
- 'marche-laurentien',
575
- 'marche-m-100-serie-moderne',
576
- 'marche-citadin-180',
577
- 'marche-ora',
578
- 'marche-t-100-serie-traditionnelle',
579
- 'marche-prestige-180'
580
- ];
581
- var itemIsException = item.parent_slug && exceptions.includes(item.parent_slug);
582
- var palUnit = item.other_units.find(function (u) { return u.unit_slug === 'pal'; });
583
- var rgUnit = item.other_units.find(function (u) { return u.unit_slug === 'rg'; });
584
- var unitUnit = item.other_units.find(function (u) { return !!u.fitting_unit && u.fitting_unit === 1; });
585
- var sellUnitCheck = item.other_units.find(function (u) { return !!u.is_sale_unit; });
586
- var sellUnit = 1;
587
- if (!!sellUnitCheck) {
588
- sellUnit = !!sellUnitCheck.fitting_unit ? sellUnitCheck.fitting_unit : 1;
589
- }
590
- var typeAttr = item.attributes[data_4.AttributesIdEnumGR.TYPE];
591
- if (!!!palUnit || !!!palUnit.fitting_unit || !!!typeAttr || !!!typeAttr.length) {
592
- if (!!itemIsException)
593
- return 1;
594
- if (!!!rgUnit || !!!rgUnit.fitting_unit) {
595
- return 0;
596
- }
597
- else {
598
- var nbRang = (item.qte * sellUnit) / rgUnit.fitting_unit;
599
- if (nbRang > 0 && nbRang <= 1) {
600
- return 0;
601
- }
602
- else {
603
- return 1;
604
- }
605
- }
606
- }
607
- if (!!typeAttr && !typeAttr.includes('gazon') && !typeAttr.includes('beton')) {
608
- return (0, floor_1.default)((item.qte * sellUnit) / palUnit.fitting_unit);
609
- }
610
- var palQty = (item.qte * sellUnit) / (palUnit.fitting_unit || 1);
611
- var rgQty = !!rgUnit ? (item.qte * sellUnit) / (rgUnit.fitting_unit || 1) : 0;
612
- var unitQty = !!unitUnit ? (item.qte * sellUnit) / (unitUnit.fitting_unit || 1) : !!sellUnit ? item.qte : 0;
613
- var totalPal = (0, floor_1.default)(palQty);
614
- var unitsInRg = !!rgUnit ? rgUnit.fitting_unit || 0 : 0;
615
- var unitsInPal = palUnit.fitting_unit || 0;
616
- if (item.qte / unitsInPal === totalPal)
617
- return totalPal;
618
- if (!!rgQty && !!rgUnit) {
619
- var rgInPal = (palUnit.fitting_unit || 1) / (rgUnit.fitting_unit || 1);
620
- if (palQty >= 1 && (0, ceil_1.default)(rgQty % rgInPal) >= 2) {
621
- totalPal += 1;
622
- }
623
- else {
624
- if (palQty < 1) {
625
- if (!!unitQty) {
626
- if (!!itemIsException && unitQty % unitsInPal !== 0) {
627
- totalPal += 1;
628
- }
629
- else if (!!unitsInRg && unitQty > unitsInRg && unitQty / unitsInRg > 1) {
630
- totalPal += 1;
631
- }
632
- }
633
- }
634
- }
635
- }
636
- else {
637
- if (!!unitQty && !!itemIsException) {
638
- if (unitQty % unitsInPal !== 0) {
639
- totalPal += 1;
640
- }
641
- }
642
- }
643
- return totalPal;
644
- }));
645
- return total;
646
- };
647
- exports.calculatePalFeeForOtherThanGrass = calculatePalFeeForOtherThanGrass;
648
- var getMinGrassQte = function (_grassProduct, expeditionMethod, _isPro) {
649
- var minQteGrassOrder = 0;
650
- if (expeditionMethod != 'pickup') {
651
- minQteGrassOrder = 740;
652
- }
653
- return minQteGrassOrder;
654
- };
655
- exports.getMinGrassQte = getMinGrassQte;
656
- var getMinQteInstall = function (_isPro) {
657
- return 740;
658
- };
659
- exports.getMinQteInstall = getMinQteInstall;
660
- var resetAllFeesIfAccessoriesOnly = function (currentItems) {
661
- var slugsToDelete = [
662
- 'livraison-gazon',
663
- 'minimum-facturable-commande',
664
- 'surcharge-jour-meme-gazon',
665
- 'livraison-beton-accessoires',
666
- 'frais-preparation-general-beton',
667
- 'frais-commande-beton-pas-en-ligne',
668
- 'frais-preparation',
669
- 'surcharges-installation-gazon',
670
- 'surcharges-commandes-gazon',
671
- 'surcharges-commandes-gazon-debut-fin-saison',
672
- 'surcharge-gazon-ramassage-hors-ferme',
673
- 'frais-commande-gazon-pas-en-ligne'
674
- ];
675
- var itemsToDelete = [];
676
- for (var _i = 0, currentItems_1 = currentItems; _i < currentItems_1.length; _i++) {
677
- var i = currentItems_1[_i];
678
- if (!!i.parent_slug && !!slugsToDelete.includes(i.parent_slug))
679
- itemsToDelete.push(i.sku);
680
- }
681
- return itemsToDelete;
682
- };
683
- var checkIfShouldApplySameDayGrassFee = function (firstDayForExpedition, expeditionMethod, selectedExpeditionDate, testDate) {
684
- var dateToCheck = expeditionMethod === 'pickup' ? firstDayForExpedition.min_pickup : firstDayForExpedition.min_delivery;
685
- var dateSelectedIsBeforeFirstCalculatedDay = !!dateToCheck && (0, moment_1.default)((0, data_3.formatDate)(selectedExpeditionDate)).isBefore((0, moment_1.default)(dateToCheck), 'date');
686
- var isHoliday = (0, data_1.getHolidays)().some(function (h) { return (0, moment_1.default)(h).isSame(testDate ? (0, moment_1.default)(testDate) : (0, moment_1.default)(), 'date'); });
687
- var isAfter4PM = (!!testDate ? (0, moment_1.default)(testDate) : (0, moment_1.default)()).hour() >= 16;
688
- var dateSelectedForExpeditionIsTomorrowOrToday = (0, moment_1.default)(selectedExpeditionDate).isSameOrBefore((0, moment_1.default)().add(1, 'day'), 'date');
689
- return (!!dateSelectedIsBeforeFirstCalculatedDay ||
690
- ((!!isHoliday || !!isAfter4PM) && !!dateSelectedForExpeditionIsTomorrowOrToday));
691
- };
692
- exports.checkIfShouldApplySameDayGrassFee = checkIfShouldApplySameDayGrassFee;
693
- var checkForSameGrassDayFee = function (isPOS, isPro, totalPallet, grassProduct, selectedExepeditionDate, isReserved) {
694
- if (!!isReserved)
695
- return false;
696
- return !!selectedExepeditionDate && !!grassProduct && totalPallet >= 4 && (!!isPOS || !!isPro);
697
- };
698
- exports.checkForSameGrassDayFee = checkForSameGrassDayFee;
699
- exports.expeditionFeePalletTier = 24;
700
- exports.installationFeePalletTier = 48;
701
- var applyFeesToCart = function (fetchProduct, getIfAddressIsInsideZones, getDistanceFromAddress, cart, expeditionMethod, grassProduct, concreteOrder, cartContainsInstallation, cartContainsVrac, availableVracStoreIDs, isPro, addOnePalletToPickup, cartContainsSample, saveToShippingPayload, deliveryAddress, locale, expeditionDate, equipmentPickupOnSite, cartContainsOnlyAccessories, pickupStore, allStores, customPriceList, useFeeArray) { return __awaiter(void 0, void 0, void 0, function () {
702
- var itemsToAdd, itemsToDelete, itemsToUpdate, newShippingPayload, minQteGrassOrder, isPOS, isMixed, totalPalletOther, totalPalletGrass, concreteItemsToCheck, grassItemsToCheck, totalPallet, totalPalletMinQte, minQteInstall, cartType, shouldAddPaletFees, qtyOfSkuNeeded, productToAdd, palletFeeDecli_1, parentProduct_1, product3_1, product4_15_1, product16_1, add_1, addRestQty, qty4AndMore, rest, parentProduct_2, product1To5_1, product6To11_1, product12AndMore_1, add_2, addRestQty, qty4AndMore, rest, isSpecialityGrass, qtyToAdd, product, decli_1, price, isKentucky, minGrassQteItem, minimumBillable, sameDayGrassFee, decli, firstDayForExpedition, shouldApplySameDayFee, removeShippingFee, productToAdd, e_1, sampleDeliveryFee, cartAccessoriesDeliveryFee, productToAdd, shouldApplyFees, feesToAdd_1, orderDate_1, pickupStoreId, shipping_address_1, pickupStore_1, surchargesCommandesGazon, surchargesCommandesGazonDebutFinSaison, surchargesInstallationGazon, surchargesInstallationGazonDebutFinSaison, surchargesGazonPickupHorsFerme, fraisSiCommandePasEnLigne, e_2, e_3, e_4, e_5, e_6, _a, e_7, addSku_1, allOrderFees, allInstallationFees, cd, summer, shouldAddGrassSeasonFee, shouldAddInstallSeasonFee, fraisPreparationGeneralBeton, onlyConcretePalQty, decli_2, getFeeAmount, feeProd, skuToAdd, concreteItems, numberOfIncompletePallets, _i, concreteItems_1, item, saleUnit, palUnit, calculatedPal, rest, surchargesCommandesBeton, decli_3, prepItem, isOutOfArea, insideZones, e_8, productInstallToAdd, _b, productToAdd, mtl, mtlInstall, ontario, ontarioInstall, ileOrleans, deliveryTruckProduct, storeIDToCheck, storeAddress, distance, _1, degelFeeSku, degelFeeProd, degelFeeDecli;
703
- return __generator(this, function (_c) {
704
- switch (_c.label) {
705
- case 0:
706
- itemsToAdd = [];
707
- itemsToDelete = [];
708
- itemsToUpdate = [];
709
- newShippingPayload = cart.shipping_payload || {};
710
- minQteGrassOrder = 0;
711
- if (!!grassProduct) {
712
- minQteGrassOrder = (0, exports.getMinGrassQte)(grassProduct, expeditionMethod, isPro);
713
- }
714
- isPOS = [Cart_1.CartTypeEnum.POS, Cart_1.CartTypeEnum.POS_TRANSACTIONNAL].includes(cart.cart_type);
715
- isMixed = cart.cart_content_type === Cart_1.CartContentTypeEnum.MIXED;
716
- totalPalletOther = 0;
717
- totalPalletGrass = 0;
718
- if (!!concreteOrder) {
719
- concreteItemsToCheck = !!isMixed
720
- ? cart.items.filter(function (i) { return !!!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); })
721
- : cart.items;
722
- totalPalletOther = (0, exports.getPalletQty)(concreteItemsToCheck, 'concrete');
723
- }
724
- if (!!grassProduct) {
725
- grassItemsToCheck = !!isMixed && !!concreteOrder ? cart.items.filter(function (i) { return !!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); }) : cart.items;
726
- totalPalletGrass = (0, exports.getPalletQty)(grassItemsToCheck, 'grass');
727
- }
728
- totalPallet = totalPalletGrass + totalPalletOther;
729
- totalPalletMinQte = (0, exports.getPalletQty)(cart.items, !!concreteOrder ? 'concrete' : !!grassProduct ? 'grass' : undefined, minQteGrassOrder);
730
- minQteInstall = (0, exports.getMinQteInstall)(!!isPro);
731
- cartType = !!isPOS ? 'in_store' : !!cart.clerk_id ? 'with_clerk' : 'online';
732
- shouldAddPaletFees = !!!cartContainsInstallation && !!!cartContainsSample && !!!cartContainsVrac;
733
- if (!((!!isMixed || !!shouldAddPaletFees) && (!!isPro || !!!grassProduct) && !!!cartContainsOnlyAccessories)) return [3, 2];
734
- qtyOfSkuNeeded = (0, exports.getPalletQtyPalletFee)(cart.items, expeditionMethod, !!(0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.GRASS, cart), isMixed);
735
- if (!!addOnePalletToPickup && expeditionMethod === 'pickup') {
736
- qtyOfSkuNeeded += 1;
737
- }
738
- if (!!addOnePalletToPickup && !!!useFeeArray && !!saveToShippingPayload) {
739
- newShippingPayload = __assign(__assign({}, newShippingPayload), { addOnePalletToPickup: true });
740
- }
741
- return [4, fetchProduct('frais-palette', locale, !!useFeeArray, true)];
742
- case 1:
743
- productToAdd = _c.sent();
744
- if (!!productToAdd && !!productToAdd.declinations) {
745
- palletFeeDecli_1 = productToAdd.declinations[0];
746
- if (!!qtyOfSkuNeeded) {
747
- itemsToAdd.push(__assign(__assign({}, productToAdd.declinations[0]), { qte: qtyOfSkuNeeded, parent_slug: productToAdd.slug, is_upsell_of_sku: 'summary', categories: productToAdd.categories }));
748
- }
749
- else if (cart.items.some(function (i) { return i.sku === palletFeeDecli_1.sku; })) {
750
- itemsToDelete.push(palletFeeDecli_1.sku);
751
- }
752
- }
753
- _c.label = 2;
754
- case 2:
755
- if (!!!grassProduct) return [3, 5];
756
- if (!(expeditionMethod === 'delivery')) return [3, 4];
757
- return [4, fetchProduct('livraison-gazon', locale, !!useFeeArray, true)];
758
- case 3:
759
- parentProduct_1 = _c.sent();
760
- product3_1 = parentProduct_1
761
- ? parentProduct_1.declinations.find(function (decli) { return ['17000000T'].includes(decli.sku); })
762
- : undefined;
763
- product4_15_1 = parentProduct_1
764
- ? parentProduct_1.declinations.find(function (decli) { return decli.sku === '170000000'; })
765
- : undefined;
766
- product16_1 = parentProduct_1
767
- ? parentProduct_1.declinations.find(function (decli) { return decli.sku === '170000160'; })
768
- : undefined;
769
- add_1 = function (product, qty) {
770
- if (!!product) {
771
- var alreadyToAdd = (0, findIndex_1.default)(itemsToAdd, function (i) { return i.sku === product.sku; });
772
- if (alreadyToAdd === -1) {
773
- itemsToAdd.push(__assign(__assign({}, product), { is_upsell_of_sku: 'summary', qte: qty, parent_slug: 'livraison-gazon' }));
774
- }
775
- else {
776
- itemsToAdd[alreadyToAdd] = __assign(__assign(__assign({}, itemsToAdd[alreadyToAdd]), { is_upsell_of_sku: 'summary', qte: itemsToAdd[alreadyToAdd].qte + qty, parent_slug: 'livraison-gazon' }), (!!parentProduct_1 ? { categories: parentProduct_1.categories } : {}));
777
- }
778
- }
779
- };
780
- addRestQty = function (pallets) {
781
- if (pallets > 0 && pallets < 4) {
782
- add_1(product3_1, 1);
783
- }
784
- if (pallets >= 4 && pallets < 16) {
785
- add_1(product4_15_1, 1);
786
- }
787
- if (pallets >= 16) {
788
- add_1(product16_1, 1);
789
- }
790
- };
791
- if (totalPalletMinQte <= exports.expeditionFeePalletTier) {
792
- addRestQty(totalPalletMinQte);
793
- }
794
- else {
795
- qty4AndMore = (0, floor_1.default)(totalPalletMinQte / exports.expeditionFeePalletTier);
796
- rest = (0, ceil_1.default)(totalPalletMinQte % exports.expeditionFeePalletTier);
797
- add_1(product16_1, qty4AndMore);
798
- addRestQty(rest);
799
- }
800
- _c.label = 4;
801
- case 4:
802
- cart.items
803
- .filter(function (i) { return i.parent_slug === 'livraison-gazon'; })
804
- .map(function (item) {
805
- if (!itemsToAdd.map(function (i) { return i.sku; }).includes(item.sku) || expeditionMethod === 'pickup') {
806
- itemsToDelete.push(item.sku);
807
- }
808
- return;
809
- });
810
- _c.label = 5;
811
- case 5:
812
- if (!(!!!cartContainsVrac && !!!cartContainsSample && !!!grassProduct && !!!cartContainsOnlyAccessories)) return [3, 8];
813
- if (!(expeditionMethod === 'delivery')) return [3, 7];
814
- return [4, fetchProduct('livraison-beton-accessoires', locale, !!useFeeArray, true)];
815
- case 6:
816
- parentProduct_2 = _c.sent();
817
- product1To5_1 = parentProduct_2
818
- ? parentProduct_2.declinations.find(function (decli) { return decli.sku === '170060450'; })
819
- : undefined;
820
- product6To11_1 = parentProduct_2
821
- ? parentProduct_2.declinations.find(function (decli) { return decli.sku === '170060650'; })
822
- : undefined;
823
- product12AndMore_1 = parentProduct_2
824
- ? parentProduct_2.declinations.find(function (decli) { return decli.sku === '170060000'; })
825
- : undefined;
826
- add_2 = function (product, qty) {
827
- if (!!product) {
828
- var alreadyToAdd = (0, findIndex_1.default)(itemsToAdd, function (i) { return i.sku === product.sku; });
829
- if (alreadyToAdd === -1) {
830
- itemsToAdd.push(__assign(__assign({}, product), { is_upsell_of_sku: 'summary', parent_slug: 'livraison-beton-accessoires', qte: qty }));
831
- }
832
- else {
833
- itemsToAdd[alreadyToAdd] = __assign(__assign(__assign({}, itemsToAdd[alreadyToAdd]), { is_upsell_of_sku: 'summary', qte: itemsToAdd[alreadyToAdd].qte + qty, parent_slug: 'livraison-beton-accessoires' }), (!!parentProduct_2 ? { categories: parentProduct_2.categories } : {}));
834
- }
835
- }
836
- };
837
- addRestQty = function (pallets) {
838
- switch (true) {
839
- case pallets > 0 && pallets <= 5:
840
- add_2(product1To5_1, 1);
841
- return;
842
- case pallets > 5 && pallets < 12:
843
- add_2(product6To11_1, 1);
844
- return;
845
- case pallets >= 12:
846
- add_2(product12AndMore_1, 1);
847
- return;
848
- }
849
- };
850
- if (totalPalletOther <= exports.expeditionFeePalletTier) {
851
- addRestQty(totalPalletOther);
852
- }
853
- else {
854
- qty4AndMore = (0, floor_1.default)(totalPalletMinQte / exports.expeditionFeePalletTier);
855
- rest = (0, ceil_1.default)(totalPalletOther) % exports.expeditionFeePalletTier;
856
- add_2(product12AndMore_1, qty4AndMore);
857
- addRestQty(rest);
858
- }
859
- _c.label = 7;
860
- case 7:
861
- cart.items
862
- .filter(function (i) { return i.parent_slug === 'livraison-beton-accessoires'; })
863
- .map(function (item) {
864
- if (!itemsToAdd.map(function (i) { return i.sku; }).includes(item.sku) || expeditionMethod === 'pickup') {
865
- itemsToDelete.push(item.sku);
866
- }
867
- return;
868
- });
869
- _c.label = 8;
870
- case 8:
871
- if (!!!grassProduct) return [3, 11];
872
- isSpecialityGrass = !!grassProduct && !!![products_4.kentucky].includes(grassProduct.sku);
873
- qtyToAdd = minQteGrassOrder - grassProduct.qte;
874
- if (!(qtyToAdd > 0)) return [3, 10];
875
- return [4, fetchProduct('minimum-facturable-commande', locale, !!useFeeArray, true)];
876
- case 9:
877
- product = _c.sent();
878
- if (!!product) {
879
- decli_1 = product.declinations.find(function (d) { return d.sku === '010010000-M'; });
880
- if (!!decli_1) {
881
- price = grassProduct.price;
882
- if (!!isSpecialityGrass) {
883
- isKentucky = cart.items.find(function (i) { return i.sku === products_4.kentucky; });
884
- price = isKentucky ? price + (0, products_3.getLowestPrice)(isKentucky).price.amount : price;
885
- }
886
- minGrassQteItem = __assign(__assign({}, decli_1), { regular_price: __assign(__assign({}, decli_1.regular_price), { amount: price }) });
887
- if (!!isPro && !!customPriceList) {
888
- minGrassQteItem = (0, g2_1.checkForCustomPriceEquivalent)(__assign(__assign({}, minGrassQteItem), { price_override: true }), customPriceList);
889
- }
890
- itemsToAdd.push(__assign(__assign({}, minGrassQteItem), { is_upsell_of_sku: 'summary', parent_slug: product.slug, price_override: true, qte: qtyToAdd, categories: product.categories }));
891
- }
892
- }
893
- _c.label = 10;
894
- case 10:
895
- minimumBillable = cart.items.find(function (i) { return i.parent_slug === 'minimum-facturable-commande'; });
896
- if (qtyToAdd <= 0 && !!minimumBillable) {
897
- itemsToDelete.push(minimumBillable.sku);
898
- }
899
- _c.label = 11;
900
- case 11: return [4, fetchProduct('surcharge-jour-meme-gazon', locale, !!useFeeArray, true)];
901
- case 12:
902
- sameDayGrassFee = _c.sent();
903
- if (!!sameDayGrassFee) {
904
- decli = sameDayGrassFee.declinations.find(function (d) { return d.sku === '000010990'; });
905
- }
906
- if (!!(0, exports.checkForSameGrassDayFee)(isPOS, isPro, totalPalletGrass, grassProduct, expeditionDate, (0, object_1.recursiveCheckObject)(cart.shipping_payload, 'is_reserved'))) {
907
- firstDayForExpedition = (0, exports.getMinDatePicker)(cart, grassProduct, undefined, expeditionMethod || 'delivery', !!isPro, !!cart.created_by ? (0, data_3.formatDate)(cart.created_by.date) : undefined, undefined, undefined, isPOS);
908
- shouldApplySameDayFee = (0, exports.checkIfShouldApplySameDayGrassFee)(firstDayForExpedition, expeditionMethod, expeditionDate);
909
- if (!!sameDayGrassFee && !!decli) {
910
- if (!!shouldApplySameDayFee) {
911
- itemsToAdd.push(__assign(__assign({}, decli), { is_upsell_of_sku: 'summary', parent_slug: sameDayGrassFee.slug, price_override: true, qte: !!grassProduct ? grassProduct.qte : 1, categories: sameDayGrassFee.categories }));
912
- }
913
- }
914
- }
915
- if (!!sameDayGrassFee && !!decli) {
916
- if (!!cart.items.some(function (i) { return i.sku === decli.sku; })) {
917
- itemsToDelete.push(decli.sku);
918
- }
919
- }
920
- if (!!!cartContainsSample) return [3, 19];
921
- removeShippingFee = false;
922
- if (!(expeditionMethod === 'delivery')) return [3, 18];
923
- return [4, fetchProduct('livraison-echantillons', locale, !!useFeeArray, true)];
924
- case 13:
925
- productToAdd = _c.sent();
926
- _c.label = 14;
927
- case 14:
928
- _c.trys.push([14, 16, , 17]);
929
- return [4, (0, exports.checkIfShouldRemoveSampleShippingFee)(fetchProduct, cart, locale, !!useFeeArray)];
930
- case 15:
931
- removeShippingFee = _c.sent();
932
- return [3, 17];
933
- case 16:
934
- e_1 = _c.sent();
935
- console.log('error on checking if should remove sample shipping fee: ', e_1.toString());
936
- return [3, 17];
937
- case 17:
938
- if (!!removeShippingFee) {
939
- productToAdd = undefined;
940
- }
941
- if (!!productToAdd && !!productToAdd.declinations) {
942
- itemsToAdd.push(__assign(__assign({}, productToAdd.declinations[0]), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: productToAdd.slug, categories: productToAdd.categories }));
943
- }
944
- _c.label = 18;
945
- case 18:
946
- sampleDeliveryFee = cart.items.find(function (i) { return i.parent_slug === 'livraison-echantillons'; });
947
- if ((expeditionMethod === 'pickup' || !!removeShippingFee) && !!sampleDeliveryFee) {
948
- itemsToDelete.push(sampleDeliveryFee.sku);
949
- }
950
- _c.label = 19;
951
- case 19:
952
- cartAccessoriesDeliveryFee = cart.items.find(function (i) { return i.parent_slug === 'livraison-accessoires'; });
953
- if (!!!cartContainsOnlyAccessories) return [3, 22];
954
- itemsToDelete = resetAllFeesIfAccessoriesOnly(cart.items);
955
- if (!(expeditionMethod === 'delivery')) return [3, 21];
956
- return [4, fetchProduct('livraison-accessoires', locale, !!useFeeArray, true)];
957
- case 20:
958
- productToAdd = _c.sent();
959
- if (!!productToAdd && !!productToAdd.declinations) {
960
- itemsToAdd.push(__assign(__assign({}, productToAdd.declinations[0]), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: productToAdd.slug, categories: productToAdd.categories }));
961
- }
962
- _c.label = 21;
963
- case 21:
964
- if (expeditionMethod === 'pickup' && !!cartAccessoriesDeliveryFee) {
965
- itemsToDelete.push(cartAccessoriesDeliveryFee.sku);
966
- }
967
- return [3, 23];
968
- case 22:
969
- if (!!cartAccessoriesDeliveryFee) {
970
- itemsToDelete.push(cartAccessoriesDeliveryFee.sku);
971
- }
972
- _c.label = 23;
973
- case 23:
974
- shouldApplyFees = !!isPro || totalPalletGrass >= 1;
975
- if (!!!grassProduct) return [3, 45];
976
- feesToAdd_1 = [];
977
- orderDate_1 = expeditionDate;
978
- pickupStoreId = '';
979
- if (!!pickupStore && !!pickupStore.id) {
980
- pickupStoreId = pickupStore.id;
981
- }
982
- else {
983
- shipping_address_1 = cart.shipping_address;
984
- if (!!shipping_address_1) {
985
- pickupStore_1 = allStores.find(function (store) { return store.address.postal_code === shipping_address_1.address.postal_code; });
986
- if (!!pickupStore_1 && !!pickupStore_1.id) {
987
- pickupStoreId = pickupStore_1.id;
988
- }
989
- }
990
- }
991
- surchargesCommandesGazon = undefined;
992
- surchargesCommandesGazonDebutFinSaison = undefined;
993
- surchargesInstallationGazon = undefined;
994
- surchargesInstallationGazonDebutFinSaison = undefined;
995
- surchargesGazonPickupHorsFerme = undefined;
996
- fraisSiCommandePasEnLigne = undefined;
997
- _c.label = 24;
998
- case 24:
999
- _c.trys.push([24, 26, , 27]);
1000
- return [4, fetchProduct('surcharges-commandes-gazon', locale, !!useFeeArray, true)];
1001
- case 25:
1002
- surchargesCommandesGazon = _c.sent();
1003
- return [3, 27];
1004
- case 26:
1005
- e_2 = _c.sent();
1006
- console.log('error on fetching product: ', e_2.toString());
1007
- return [3, 27];
1008
- case 27:
1009
- _c.trys.push([27, 29, , 30]);
1010
- return [4, fetchProduct('surcharges-commandes-gazon-debut-fin-saison', locale, !!useFeeArray, true)];
1011
- case 28:
1012
- surchargesCommandesGazonDebutFinSaison = _c.sent();
1013
- return [3, 30];
1014
- case 29:
1015
- e_3 = _c.sent();
1016
- console.log('error on fetching product: ', e_3.toString());
1017
- return [3, 30];
1018
- case 30:
1019
- _c.trys.push([30, 32, , 33]);
1020
- return [4, fetchProduct('surcharges-installation-gazon', locale, !!useFeeArray, true)];
1021
- case 31:
1022
- surchargesInstallationGazon = _c.sent();
1023
- return [3, 33];
1024
- case 32:
1025
- e_4 = _c.sent();
1026
- console.log('error on fetching product: ', e_4.toString());
1027
- return [3, 33];
1028
- case 33:
1029
- _c.trys.push([33, 35, , 36]);
1030
- return [4, fetchProduct('surcharges-installation-gazon-debut-fin-saison', locale, useFeeArray, true)];
1031
- case 34:
1032
- surchargesInstallationGazonDebutFinSaison = _c.sent();
1033
- return [3, 36];
1034
- case 35:
1035
- e_5 = _c.sent();
1036
- console.log('error on fetching product: ', e_5.toString());
1037
- return [3, 36];
1038
- case 36:
1039
- _c.trys.push([36, 38, , 39]);
1040
- return [4, fetchProduct('surcharge-gazon-ramassage-hors-ferme', locale, !!useFeeArray, true)];
1041
- case 37:
1042
- surchargesGazonPickupHorsFerme = _c.sent();
1043
- return [3, 39];
1044
- case 38:
1045
- e_6 = _c.sent();
1046
- console.log('error on fetching product: ', e_6.toString());
1047
- return [3, 39];
1048
- case 39:
1049
- _c.trys.push([39, 43, , 44]);
1050
- if (!(cartType === 'online' || expeditionMethod === 'pickup')) return [3, 40];
1051
- _a = undefined;
1052
- return [3, 42];
1053
- case 40: return [4, fetchProduct('frais-commande-gazon-pas-en-ligne', locale, !!useFeeArray, true)];
1054
- case 41:
1055
- _a = _c.sent();
1056
- _c.label = 42;
1057
- case 42:
1058
- fraisSiCommandePasEnLigne = _a;
1059
- return [3, 44];
1060
- case 43:
1061
- e_7 = _c.sent();
1062
- console.log('error on fetching product: ', e_7.toString());
1063
- return [3, 44];
1064
- case 44:
1065
- if (!!orderDate_1) {
1066
- addSku_1 = function (sku, product) {
1067
- var decli = product.declinations.find(function (i) { return i.sku === sku; });
1068
- if (!!decli) {
1069
- feesToAdd_1.push(__assign(__assign({}, decli), { qte: !!product.slug.includes('installation') && grassProduct.qte < minQteInstall
1070
- ? minQteInstall
1071
- : (!!product.slug.includes('commandes-gazon') ||
1072
- ['frais-commande-gazon-pas-en-ligne', 'surcharge-gazon-ramassage-hors-ferme'].includes(product.slug)) &&
1073
- grassProduct.qte < minQteGrassOrder
1074
- ? minQteGrassOrder
1075
- : grassProduct.qte, is_upsell_of_sku: 'summary', parent_slug: product.slug, other_units: decli.other_units }));
1076
- }
1077
- };
1078
- allOrderFees = [];
1079
- allInstallationFees = [];
1080
- if (!!shouldApplyFees) {
1081
- if (!!surchargesCommandesGazon) {
1082
- if (orderDate_1.getDay() === 6) {
1083
- if (expeditionMethod === 'delivery') {
1084
- allOrderFees.push(['000010400', surchargesCommandesGazon]);
1085
- }
1086
- else {
1087
- if (!!!data_2.grassFarmStores.includes(pickupStoreId)) {
1088
- allOrderFees.push(['000010400', surchargesCommandesGazon]);
1089
- }
1090
- }
1091
- }
1092
- if ((0, moment_1.default)(orderDate_1).day() === 0 ||
1093
- (0, data_1.getHolidays)().some(function (date) { return (0, moment_1.default)(date).isSame((0, moment_1.default)(orderDate_1), 'day'); })) {
1094
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010850', surchargesCommandesGazon]], false);
1095
- }
1096
- cd = (0, data_1.getContructionHolidays)();
1097
- if ((0, moment_1.default)(orderDate_1).isBetween((0, moment_1.default)(cd[0]), (0, moment_1.default)(cd[1]), 'day', '[]')) {
1098
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010860', surchargesCommandesGazon]], false);
1099
- }
1100
- summer = (0, data_1.getSummerDate)();
1101
- if ((0, moment_1.default)(orderDate_1).isBetween((0, moment_1.default)(summer[0]), (0, moment_1.default)(summer[1]), 'day', '[]')) {
1102
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010300', surchargesCommandesGazon]], false);
1103
- }
1104
- }
1105
- shouldAddGrassSeasonFee = !!surchargesCommandesGazonDebutFinSaison;
1106
- shouldAddInstallSeasonFee = !!cartContainsInstallation && !!isPro && !!surchargesInstallationGazonDebutFinSaison;
1107
- if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-03-01"), "".concat((0, moment_1.default)().format('YYYY'), "-04-30"), 'day', '[]')) {
1108
- if (shouldAddGrassSeasonFee)
1109
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010100', surchargesCommandesGazonDebutFinSaison]], false);
1110
- if (shouldAddInstallSeasonFee)
1111
- allInstallationFees.push(['000010600', surchargesInstallationGazonDebutFinSaison]);
1112
- }
1113
- if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-10-15"), "".concat((0, moment_1.default)().format('YYYY'), "-10-31"), 'day', '[]')) {
1114
- if (shouldAddGrassSeasonFee)
1115
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010840', surchargesCommandesGazonDebutFinSaison]], false);
1116
- if (shouldAddInstallSeasonFee)
1117
- allInstallationFees.push(['000010940', surchargesInstallationGazonDebutFinSaison]);
1118
- }
1119
- if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-11-01"), "".concat((0, moment_1.default)().format('YYYY'), "-11-14"), 'day', '[]')) {
1120
- if (shouldAddGrassSeasonFee)
1121
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010700', surchargesCommandesGazonDebutFinSaison]], false);
1122
- if (shouldAddInstallSeasonFee)
1123
- allInstallationFees.push(['000010800', surchargesInstallationGazonDebutFinSaison]);
1124
- }
1125
- if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-11-15"), "".concat((0, moment_1.default)().format('YYYY'), "-12-31"), 'day', '[]')) {
1126
- if (shouldAddGrassSeasonFee)
1127
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010900', surchargesCommandesGazonDebutFinSaison]], false);
1128
- if (shouldAddInstallSeasonFee)
1129
- allInstallationFees.push(['000010950', surchargesInstallationGazonDebutFinSaison]);
1130
- }
1131
- if (expeditionMethod === 'pickup' && !!surchargesGazonPickupHorsFerme) {
1132
- if (!!!data_2.grassFarmStores.includes(pickupStoreId)) {
1133
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000012500', surchargesGazonPickupHorsFerme]], false);
1134
- }
1135
- }
1136
- }
1137
- if (!!surchargesInstallationGazon &&
1138
- !!cartContainsInstallation &&
1139
- ((0, moment_1.default)(orderDate_1).day() === 0 ||
1140
- (0, data_1.getHolidays)().some(function (date) { return (0, moment_1.default)(date).isSame((0, moment_1.default)(orderDate_1), 'day'); }))) {
1141
- allInstallationFees.push(['000010750', surchargesInstallationGazon]);
1142
- }
1143
- if (!!fraisSiCommandePasEnLigne && !!!cartContainsInstallation && !!isPro) {
1144
- allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['FRSGAZON', fraisSiCommandePasEnLigne]], false);
1145
- }
1146
- allOrderFees.map(function (fee) {
1147
- addSku_1(fee[0], fee[1]);
1148
- });
1149
- allInstallationFees.map(function (fee) {
1150
- addSku_1(fee[0], fee[1]);
1151
- });
1152
- }
1153
- itemsToAdd = __spreadArray(__spreadArray([], itemsToAdd, true), feesToAdd_1, true);
1154
- _c.label = 45;
1155
- case 45:
1156
- if (!!grassProduct || !!isMixed) {
1157
- cart.items.forEach(function (i) {
1158
- if (!!i.parent_slug &&
1159
- [
1160
- 'surcharges-commandes-gazon',
1161
- 'surcharges-commandes-gazon-debut-fin-saison',
1162
- 'surcharges-installation-gazon',
1163
- 'surcharges-installation-gazon-debut-fin-saison',
1164
- 'surcharge-gazon-ramassage-hors-ferme',
1165
- 'frais-commande-gazon-pas-en-ligne'
1166
- ].includes(i.parent_slug)) {
1167
- itemsToDelete.push(i.sku);
1168
- }
1169
- });
1170
- }
1171
- if (!(!!concreteOrder && !!!cartContainsSample && !!!cartContainsOnlyAccessories)) return [3, 53];
1172
- return [4, fetchProduct('frais-preparation-general-beton', locale, !!useFeeArray, true)];
1173
- case 46:
1174
- fraisPreparationGeneralBeton = _c.sent();
1175
- onlyConcretePalQty = (0, exports.getPalletQty)(cart.items.filter(function (i) { return (0, products_2.checkIfProductIsOfType)(i, 'beton', true); }));
1176
- if (!!fraisPreparationGeneralBeton && onlyConcretePalQty >= 1) {
1177
- decli_2 = fraisPreparationGeneralBeton.declinations.find(function (i) { return i.sku === 'FP-1'; });
1178
- if (!!decli_2) {
1179
- itemsToAdd.push(__assign(__assign({}, decli_2), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: fraisPreparationGeneralBeton.slug, categories: fraisPreparationGeneralBeton.categories }));
1180
- }
1181
- }
1182
- if (!(expeditionMethod !== 'pickup' && cartType !== 'online' && !!isPro)) return [3, 48];
1183
- getFeeAmount = function (decli) {
1184
- var percent = (0, toNumber_1.default)(decli.regular_price.amount);
1185
- var amount = 0;
1186
- for (var _i = 0, _a = cart.items; _i < _a.length; _i++) {
1187
- var item = _a[_i];
1188
- if (!!item.is_service)
1189
- continue;
1190
- if (!!customPriceList) {
1191
- item = (0, g2_1.checkForCustomPriceEquivalent)(item, customPriceList);
1192
- }
1193
- var itemPrice = (0, products_3.getLowestPrice)(item).price.amount;
1194
- amount += itemPrice * item.qte * percent;
1195
- }
1196
- return (0, round_1.default)(amount, 3);
1197
- };
1198
- return [4, fetchProduct('frais-commande-beton-pas-en-ligne', locale, !!useFeeArray, true)];
1199
- case 47:
1200
- feeProd = _c.sent();
1201
- if (!!feeProd) {
1202
- skuToAdd = (feeProd.declinations || []).find(function (d) { return d.sku === 'FRSBETON'; });
1203
- if (!!skuToAdd) {
1204
- itemsToAdd.push(__assign(__assign({}, skuToAdd), { qte: 1, parent_slug: feeProd.slug, is_upsell_of_sku: 'summary', regular_price: __assign(__assign({}, skuToAdd.regular_price), { amount: getFeeAmount(skuToAdd), price_type: (0, round_1.default)((0, toNumber_1.default)(skuToAdd.regular_price.amount) * 100, 2).toString() }), price_override: true, categories: feeProd.categories }));
1205
- }
1206
- }
1207
- return [3, 49];
1208
- case 48:
1209
- if (cart.items.some(function (item) { return item.sku === 'FRSBETON'; })) {
1210
- itemsToDelete.push('FRSBETON');
1211
- }
1212
- _c.label = 49;
1213
- case 49:
1214
- concreteItems = cart.items.filter(function (i) { return i.attributes[data_4.AttributesIdEnumGR.TYPE] && i.attributes[data_4.AttributesIdEnumGR.TYPE].includes('beton'); });
1215
- numberOfIncompletePallets = 0;
1216
- for (_i = 0, concreteItems_1 = concreteItems; _i < concreteItems_1.length; _i++) {
1217
- item = concreteItems_1[_i];
1218
- if (!!!item.other_units)
1219
- continue;
1220
- saleUnit = item.other_units.find(function (unit) { return unit.is_sale_unit; });
1221
- palUnit = item.other_units.find(function (unit) { return unit.unit_slug === 'pal'; });
1222
- if (!!!saleUnit || !!!saleUnit.fitting_unit || !!!palUnit || !!!palUnit.fitting_unit)
1223
- continue;
1224
- calculatedPal = saleUnit.fitting_unit * item.qte;
1225
- rest = (0, round_1.default)(calculatedPal, 3) % (0, round_1.default)(palUnit.fitting_unit, 3);
1226
- if (!!rest) {
1227
- numberOfIncompletePallets++;
1228
- }
1229
- }
1230
- if (!(numberOfIncompletePallets >= 4)) return [3, 51];
1231
- return [4, fetchProduct('frais-preparation', locale, !!useFeeArray, true)];
1232
- case 50:
1233
- surchargesCommandesBeton = _c.sent();
1234
- if (!!surchargesCommandesBeton) {
1235
- decli_3 = surchargesCommandesBeton.declinations.find(function (i) { return i.sku === 'FP4'; });
1236
- if (!!decli_3) {
1237
- itemsToAdd.push(__assign(__assign({}, decli_3), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: surchargesCommandesBeton.slug, categories: surchargesCommandesBeton.categories }));
1238
- }
1239
- }
1240
- return [3, 52];
1241
- case 51:
1242
- prepItem = cart.items.find(function (item) { return item.parent_slug === 'frais-preparation'; });
1243
- if (!!prepItem) {
1244
- itemsToDelete.push(prepItem.sku);
1245
- }
1246
- _c.label = 52;
1247
- case 52: return [3, 54];
1248
- case 53:
1249
- if (cart.items.some(function (item) { return item.sku === 'FP-1'; })) {
1250
- itemsToDelete.push('FP-1');
1251
- }
1252
- if (cart.items.some(function (item) { return item.sku === 'FRSBETON'; })) {
1253
- itemsToDelete.push('FRSBETON');
1254
- }
1255
- _c.label = 54;
1256
- case 54:
1257
- isOutOfArea = false;
1258
- if (!(expeditionMethod === 'delivery' && !!deliveryAddress)) return [3, 74];
1259
- insideZones = undefined;
1260
- _c.label = 55;
1261
- case 55:
1262
- _c.trys.push([55, 57, , 58]);
1263
- return [4, getIfAddressIsInsideZones(deliveryAddress)];
1264
- case 56:
1265
- insideZones = _c.sent();
1266
- return [3, 58];
1267
- case 57:
1268
- e_8 = _c.sent();
1269
- console.log('error on fetching zones for address: ', e_8.toString());
1270
- return [3, 58];
1271
- case 58:
1272
- if (!(!!insideZones && !!Array.isArray(insideZones))) return [3, 74];
1273
- if (!(!!insideZones.length && insideZones.includes('zone-gr'))) return [3, 73];
1274
- productInstallToAdd = void 0;
1275
- if (!!!grassProduct) return [3, 62];
1276
- if (!!!cartContainsInstallation) return [3, 60];
1277
- return [4, fetchProduct('surcharges-installation-gazon', locale, !!useFeeArray, true)];
1278
- case 59:
1279
- _b = _c.sent();
1280
- return [3, 61];
1281
- case 60:
1282
- _b = undefined;
1283
- _c.label = 61;
1284
- case 61:
1285
- productInstallToAdd = _b;
1286
- _c.label = 62;
1287
- case 62: return [4, fetchProduct('surcharges-commandes-gazon', locale, !!useFeeArray, true)];
1288
- case 63:
1289
- productToAdd = _c.sent();
1290
- if (insideZones.includes('zone-mtl')) {
1291
- if (!!productToAdd) {
1292
- mtl = productToAdd.declinations.find(function (i) { return i.sku === '170050000'; });
1293
- if (!!mtl) {
1294
- itemsToAdd.push(__assign(__assign({}, mtl), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1295
- }
1296
- }
1297
- if (!!grassProduct && !!productInstallToAdd) {
1298
- mtlInstall = productInstallToAdd.declinations.find(function (i) { return i.sku === '170055500'; });
1299
- if (!!mtlInstall) {
1300
- itemsToAdd.push(__assign(__assign({}, mtlInstall), { qte: (0, ceil_1.default)(totalPalletGrass / exports.installationFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-installation-gazon', categories: productInstallToAdd.categories }));
1301
- }
1302
- }
1303
- }
1304
- if (insideZones.includes('zone-ontario')) {
1305
- if (!!productToAdd) {
1306
- ontario = productToAdd.declinations.find(function (i) { return i.sku === '170000ONT'; });
1307
- if (!!ontario) {
1308
- itemsToAdd.push(__assign(__assign({}, ontario), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1309
- }
1310
- }
1311
- if (!!grassProduct && !!productInstallToAdd) {
1312
- ontarioInstall = productInstallToAdd.declinations.find(function (i) { return i.sku === '170033ONT'; });
1313
- if (!!ontarioInstall) {
1314
- itemsToAdd.push(__assign(__assign({}, ontarioInstall), { qte: (0, ceil_1.default)(totalPalletGrass / exports.installationFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-installation-gazon', categories: productInstallToAdd.categories }));
1315
- }
1316
- }
1317
- }
1318
- if (insideZones.includes('zone-ile-orleans')) {
1319
- if (!!productToAdd) {
1320
- ileOrleans = productToAdd.declinations.find(function (i) { return i.sku === '170000418'; });
1321
- if (!!ileOrleans) {
1322
- itemsToAdd.push(__assign(__assign({}, ileOrleans), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1323
- }
1324
- }
1325
- }
1326
- if (!!!cartContainsVrac) return [3, 72];
1327
- if (!(insideZones.includes('zone-vrac') || insideZones.includes('zone-vrac-les-coteaux'))) return [3, 71];
1328
- return [4, fetchProduct('frais-de-livraison-vrac', locale, !!useFeeArray, true)];
1329
- case 64:
1330
- deliveryTruckProduct = _c.sent();
1331
- storeIDToCheck = insideZones.includes('zone-vrac') ? 'sainte-julie-nobel' : 'default';
1332
- storeAddress = getStoreAddressByID(allStores, storeIDToCheck);
1333
- if (!(!!availableVracStoreIDs && !availableVracStoreIDs.includes(storeIDToCheck))) return [3, 65];
1334
- isOutOfArea = true;
1335
- return [3, 70];
1336
- case 65:
1337
- if (!(!!deliveryTruckProduct && !!storeAddress)) return [3, 70];
1338
- distance = null;
1339
- _c.label = 66;
1340
- case 66:
1341
- _c.trys.push([66, 68, , 69]);
1342
- return [4, getDistanceFromAddress(storeAddress, deliveryAddress)];
1343
- case 67:
1344
- distance = _c.sent();
1345
- return [3, 69];
1346
- case 68:
1347
- _1 = _c.sent();
1348
- console.log(_1);
1349
- return [3, 69];
1350
- case 69:
1351
- if (distance === null) {
1352
- isOutOfArea = true;
1353
- }
1354
- else {
1355
- itemsToAdd = __spreadArray(__spreadArray([], itemsToAdd, true), (0, exports.calculateShippingForVrac)(distance, cart.items, deliveryTruckProduct, itemsToAdd, expeditionDate), true);
1356
- }
1357
- _c.label = 70;
1358
- case 70: return [3, 72];
1359
- case 71:
1360
- isOutOfArea = true;
1361
- _c.label = 72;
1362
- case 72: return [3, 74];
1363
- case 73:
1364
- isOutOfArea = true;
1365
- _c.label = 74;
1366
- case 74:
1367
- cart.items.forEach(function (i) {
1368
- if (!!i.parent_slug && ['frais-de-livraison-vrac', 'surcharges-commandes-gazon'].includes(i.parent_slug)) {
1369
- itemsToDelete.push(i.sku);
1370
- }
1371
- });
1372
- if (!!equipmentPickupOnSite) {
1373
- }
1374
- degelFeeSku = '170000018';
1375
- if (!(!!isPro &&
1376
- expeditionMethod === 'delivery' &&
1377
- !!!cartContainsSample &&
1378
- !!!cartContainsVrac &&
1379
- !!expeditionDate &&
1380
- !!isDegel(expeditionDate))) return [3, 76];
1381
- return [4, fetchProduct('frais-livraison-periode-degel', locale, !!useFeeArray, true)];
1382
- case 75:
1383
- degelFeeProd = _c.sent();
1384
- if (!!degelFeeProd) {
1385
- degelFeeDecli = degelFeeProd.declinations.find(function (d) { return d.sku === degelFeeSku; });
1386
- if (!!degelFeeDecli) {
1387
- itemsToAdd.push(__assign(__assign({}, degelFeeDecli), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: degelFeeProd.slug, categories: degelFeeProd.categories }));
1388
- }
1389
- }
1390
- return [3, 77];
1391
- case 76:
1392
- if (!!cart.items.some(function (i) { return i.sku === degelFeeSku; })) {
1393
- itemsToDelete.push(degelFeeSku);
1394
- }
1395
- _c.label = 77;
1396
- case 77:
1397
- itemsToDelete = itemsToDelete.filter(function (i) { return !itemsToAdd.map(function (add) { return add.sku; }).includes(i); });
1398
- itemsToAdd = itemsToAdd
1399
- .map(function (item) {
1400
- var cartItem = cart.items.find(function (i) { return i.sku === item.sku; });
1401
- if (!!cartItem) {
1402
- if (cartItem.qte !== item.qte) {
1403
- itemsToUpdate.push({ sku: item.sku, qte: item.qte });
1404
- return;
1405
- }
1406
- else {
1407
- return;
1408
- }
1409
- }
1410
- else {
1411
- if (!!item.parent_slug &&
1412
- (0, products_2.shouldHideItemIfRegPriceIs0)(item, item.parent_slug, !!item.is_upsell_of_sku && item.parent_slug.includes('installation'))) {
1413
- return;
1414
- }
1415
- }
1416
- return __assign({}, item);
1417
- })
1418
- .filter(function (i) { return !!i; });
1419
- return [2, {
1420
- newCart: __assign(__assign({}, cart), { shipping_payload: newShippingPayload }),
1421
- itemsToDelete: itemsToDelete,
1422
- itemsToUpdate: itemsToUpdate,
1423
- itemsToAdd: itemsToAdd,
1424
- totalPallet: totalPallet,
1425
- isOutOfArea: isOutOfArea
1426
- }];
1427
- }
1428
- });
1429
- }); };
1430
- exports.applyFeesToCart = applyFeesToCart;
1431
- var checkIfShouldRemoveSampleShippingFee = function (fetchProduct, cart, locale, useFeeArray) { return __awaiter(void 0, void 0, void 0, function () {
1432
- var currentItems, currentItemsChecked, _i, currentItems_2, item, parentProd, brand, isTena, excludedGrass, hasGrassType, isExcludedGrass, isGrass, valuesToCheck, allIncludedBrandsNoTena, allGrass, added;
1433
- return __generator(this, function (_a) {
1434
- switch (_a.label) {
1435
- case 0:
1436
- if (!!!cart.items)
1437
- return [2, false];
1438
- currentItems = cart.items.filter(function (i) { return i.is_sample; });
1439
- currentItemsChecked = [];
1440
- _i = 0, currentItems_2 = currentItems;
1441
- _a.label = 1;
1442
- case 1:
1443
- if (!(_i < currentItems_2.length)) return [3, 4];
1444
- item = currentItems_2[_i];
1445
- if (!!!item.parent_slug)
1446
- return [3, 3];
1447
- return [4, fetchProduct(item.parent_slug, locale, !!useFeeArray, true)];
1448
- case 2:
1449
- parentProd = _a.sent();
1450
- if (!!!parentProd)
1451
- return [3, 3];
1452
- brand = parentProd.brand;
1453
- isTena = !!item.attributes &&
1454
- !!item.attributes[data_4.AttributesIdEnumGR.FAMILY] &&
1455
- !!item.attributes[data_4.AttributesIdEnumGR.FAMILY].includes('tena');
1456
- excludedGrass = ["".concat(products_4.kentucky, "-e"), "".concat(products_4.prestige, "-e")];
1457
- hasGrassType = (0, products_2.checkIfProductIsOfType)(item, 'gazon');
1458
- isExcludedGrass = excludedGrass.includes(item.sku);
1459
- isGrass = !!hasGrassType && !!!isExcludedGrass;
1460
- valuesToCheck = {
1461
- brand: !!brand ? brand : '',
1462
- isTena: isTena,
1463
- isGrass: isGrass
1464
- };
1465
- currentItemsChecked.push(valuesToCheck);
1466
- _a.label = 3;
1467
- case 3:
1468
- _i++;
1469
- return [3, 1];
1470
- case 4:
1471
- if (!!currentItemsChecked.length) {
1472
- allIncludedBrandsNoTena = currentItemsChecked.filter(function (item) { return !!item.brand && !!data_2.includedFreeShippingBrands.includes(item.brand) && !!!item.isTena; });
1473
- allGrass = currentItemsChecked.filter(function (item) { return !!item.isGrass; });
1474
- if (currentItems.length === allIncludedBrandsNoTena.length || currentItems.length === allGrass.length) {
1475
- return [2, true];
1476
- }
1477
- else {
1478
- added = allIncludedBrandsNoTena.length + allGrass.length;
1479
- if (added === currentItems.length) {
1480
- return [2, true];
1481
- }
1482
- }
1483
- }
1484
- return [2, false];
1485
- }
1486
- });
1487
- }); };
1488
- exports.checkIfShouldRemoveSampleShippingFee = checkIfShouldRemoveSampleShippingFee;
1489
- var calculateShippingForVrac = function (distance, cartItems, deliveryTruckProduct, currentItemsToAdd, deliveryDate) {
1490
- if (distance === void 0) { distance = 0; }
1491
- var itemsToAdd = __spreadArray([], currentItemsToAdd, true);
1492
- var allVracItems = cartItems.filter(function (i) { return (0, products_2.checkIfProductIsOfType)(i, 'vrac'); });
1493
- var _loop_1 = function (vracItem) {
1494
- var totalTons = vracItem.qte;
1495
- var isInDegelPeriod = !!isDegel(deliveryDate);
1496
- var volumeTons = [
1497
- {
1498
- min: 1,
1499
- max: 4
1500
- },
1501
- {
1502
- min: 4,
1503
- max: isInDegelPeriod ? 11 : 15
1504
- },
1505
- {
1506
- min: isInDegelPeriod ? 11 : 15,
1507
- max: isInDegelPeriod ? 16 : 20
1508
- },
1509
- {
1510
- min: isInDegelPeriod ? 16 : 20,
1511
- max: isInDegelPeriod ? 19 : 24
1512
- },
1513
- {
1514
- min: isInDegelPeriod ? 19 : 24,
1515
- max: isInDegelPeriod ? 24 : 30
1516
- }
1517
- ];
1518
- var checkTons = function (tons) {
1519
- var skuToAdd = '';
1520
- switch (true) {
1521
- case tons <= volumeTons[0].max:
1522
- switch (true) {
1523
- case distance >= 0 && distance < 15:
1524
- skuToAdd = '170000615';
1525
- break;
1526
- case distance >= 15 && distance < 30:
1527
- skuToAdd = '170000630';
1528
- break;
1529
- case distance >= 30:
1530
- skuToAdd = '170000660';
1531
- break;
1532
- }
1533
- tons = -1;
1534
- break;
1535
- case tons > volumeTons[1].min && tons <= volumeTons[1].max:
1536
- switch (true) {
1537
- case distance >= 0 && distance < 15:
1538
- skuToAdd = '170001015';
1539
- break;
1540
- case distance >= 15 && distance < 30:
1541
- skuToAdd = '170001030';
1542
- break;
1543
- case distance >= 30:
1544
- skuToAdd = '170001060';
1545
- break;
1546
- }
1547
- tons = -1;
1548
- break;
1549
- case tons > volumeTons[2].min && tons <= volumeTons[2].max:
1550
- switch (true) {
1551
- case distance >= 0 && distance < 15:
1552
- skuToAdd = '170001215';
1553
- break;
1554
- case distance >= 15 && distance < 30:
1555
- skuToAdd = '170001230';
1556
- break;
1557
- case distance >= 30:
1558
- skuToAdd = '170001260';
1559
- break;
1560
- }
1561
- tons = -1;
1562
- break;
1563
- case tons > volumeTons[3].min && tons <= volumeTons[3].max:
1564
- switch (true) {
1565
- case distance >= 0 && distance < 15:
1566
- skuToAdd = '170002015';
1567
- break;
1568
- case distance >= 15 && distance < 30:
1569
- skuToAdd = '170002030';
1570
- break;
1571
- case distance >= 30:
1572
- skuToAdd = '170002060';
1573
- break;
1574
- }
1575
- tons = -1;
1576
- break;
1577
- case tons > volumeTons[4].min:
1578
- switch (true) {
1579
- case distance >= 0 && distance < 15:
1580
- skuToAdd = '170003015';
1581
- break;
1582
- case distance >= 15 && distance < 30:
1583
- skuToAdd = '170003030';
1584
- break;
1585
- case distance >= 30:
1586
- skuToAdd = '170003060';
1587
- break;
1588
- }
1589
- tons = tons - volumeTons[4].max;
1590
- break;
1591
- default:
1592
- tons = -1;
1593
- }
1594
- var decliToAdd = deliveryTruckProduct.declinations.find(function (d) { return d.sku === skuToAdd; });
1595
- if (!!decliToAdd) {
1596
- if (!!itemsToAdd.find(function (item) { return item.sku === decliToAdd.sku; })) {
1597
- var index = itemsToAdd.findIndex(function (item) { return item.sku === decliToAdd.sku; });
1598
- itemsToAdd[index] = __assign(__assign({}, itemsToAdd[index]), { qte: itemsToAdd[index].qte + 1 });
1599
- }
1600
- else {
1601
- itemsToAdd.push(__assign(__assign({}, decliToAdd), { parent_slug: 'frais-de-livraison-vrac', qte: 1, is_upsell_of_sku: 'summary', categories: deliveryTruckProduct.categories }));
1602
- }
1603
- }
1604
- if (tons > 0) {
1605
- checkTons(tons);
1606
- }
1607
- };
1608
- checkTons(totalTons);
1609
- };
1610
- for (var _i = 0, allVracItems_1 = allVracItems; _i < allVracItems_1.length; _i++) {
1611
- var vracItem = allVracItems_1[_i];
1612
- _loop_1(vracItem);
1613
- }
1614
- return itemsToAdd;
1615
- };
1616
- exports.calculateShippingForVrac = calculateShippingForVrac;
1617
- var getStoresForVracProdShipping = function (inventoryItem) {
1618
- var availability = {};
1619
- var _loop_2 = function (vracStore) {
1620
- var sameInInventory = inventoryItem.inventories.find(function (i) { return i.store_id == vracStore; });
1621
- availability[vracStore] = !!sameInInventory && !!!sameInInventory.unavailable_in_store;
1622
- };
1623
- for (var _i = 0, vracShippingStores_1 = data_2.vracShippingStores; _i < vracShippingStores_1.length; _i++) {
1624
- var vracStore = vracShippingStores_1[_i];
1625
- _loop_2(vracStore);
1626
- }
1627
- return availability;
1628
- };
1629
- exports.getStoresForVracProdShipping = getStoresForVracProdShipping;
1630
- var getStoreAddressByID = function (allStores, storeID) {
1631
- var sameStore = allStores.find(function (s) { return s.id == storeID; });
1632
- return !!sameStore ? sameStore.address : undefined;
1633
- };
1634
- var checkIfCartExpired = function (cartData, grassProduct, concreteOrder, isPro, blocked_shipping_dates, vracType, chosenPaymentType) {
1635
- var isPOS = Cart_1.CartTypeEnum.WEB != cartData.cart_type;
1636
- var isSample = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.SAMPLE, cartData);
1637
- var isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
1638
- var selected_date = !!cartData.shipping_payload && !!cartData.shipping_payload.delivery_or_pickup_date
1639
- ? (0, data_3.formatDate)(cartData.shipping_payload.delivery_or_pickup_date)
1640
- : undefined;
1641
- var noDeliveryDateIsNormal = (0, exports.checkIfNoDeliveryDateIsNormal)(cartData, concreteOrder) ||
1642
- (!!chosenPaymentType && ['depot'].includes(chosenPaymentType));
1643
- if (!!noDeliveryDateIsNormal) {
1644
- return false;
1645
- }
1646
- else if (!!!selected_date) {
1647
- return true;
1648
- }
1649
- var now = (0, moment_1.default)().toDate();
1650
- var updated_last = !!cartData.shipping_payload && !!cartData.shipping_payload.updated_at
1651
- ? (0, data_3.formatDate)(cartData.shipping_payload.updated_at)
1652
- : (0, moment_1.default)().toDate();
1653
- var time = !!cartData.shipping_payload && !!cartData.shipping_payload.delivery_period
1654
- ? cartData.shipping_payload.delivery_period
1655
- : 'PM';
1656
- var minDates = (0, exports.getMinDatePicker)(cartData, grassProduct, concreteOrder, !!cartData.is_pickup ? 'pickup' : 'delivery', !!isPro, updated_last, blocked_shipping_dates, vracType, isPOS);
1657
- var currentMinDate = !!cartData.is_pickup ? minDates.min_pickup : minDates.min_delivery;
1658
- var ok_hours = (0, exports.getAvailableHours)(currentMinDate, selected_date, grassProduct, concreteOrder, (!!cartData.is_pickup ? 'pickup' : 'delivery'), time, isPro, isSample, isAccessoriesOnly, updated_last);
1659
- return (!!updated_last &&
1660
- (((0, moment_1.default)(selected_date).isSameOrBefore(now, 'day') && !!!(0, moment_1.default)(currentMinDate).isSame(now, 'day')) ||
1661
- (0, moment_1.default)(now).isAfter(updated_last, 'day') ||
1662
- (0, moment_1.default)(currentMinDate).isAfter(selected_date, 'day') ||
1663
- (updated_last.getHours() < 10 &&
1664
- now.getHours() >= 10 &&
1665
- time === 'AM' &&
1666
- !!ok_hours.deliveryTimes.every(function (d) { return d.value == 'PM'; }))));
1667
- };
1668
- exports.checkIfCartExpired = checkIfCartExpired;
1669
- var checkIfNoDeliveryDateIsNormal = function (cartData, concreteOrder, checkForInputShown) {
1670
- var isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
1671
- var isSample = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.SAMPLE, cartData);
1672
- return ((!!!checkForInputShown && !!cartData.shipping_payload && !!cartData.shipping_payload.isOutOfArea) ||
1673
- (!!concreteOrder && concreteOrder.type !== 'green') ||
1674
- ((!!isAccessoriesOnly || !!isSample) && !!!cartData.is_pickup));
1675
- };
1676
- exports.checkIfNoDeliveryDateIsNormal = checkIfNoDeliveryDateIsNormal;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.checkIfNoDeliveryDateIsNormal = exports.checkIfCartExpired = exports.getStoresForVracProdShipping = exports.calculateShippingForVrac = exports.checkIfShouldRemoveSampleShippingFee = exports.applyFeesToCart = exports.installationFeePalletTier = exports.expeditionFeePalletTier = exports.checkForSameGrassDayFee = exports.checkIfShouldApplySameDayGrassFee = exports.getMinQteInstall = exports.getMinGrassQte = exports.calculatePalFeeForOtherThanGrass = exports.getPalletQtyPalletFee = exports.getGrassRoundedPickupPalletFees = exports.getPalletQty = exports.slugsToCheckFromExpeditionFees = exports.checkIfCartTypeHasBlockedDates = exports.dateIsClosedInSchedule = exports.shouldDisableDate = exports.getMinDateOffset = exports.getMinDatePicker = exports.getAvailableHours = exports.getDefaultTimeValues = void 0;
63
+ var moment_1 = __importDefault(require("moment"));
64
+ var ceil_1 = __importDefault(require("lodash/ceil"));
65
+ var findIndex_1 = __importDefault(require("lodash/findIndex"));
66
+ var floor_1 = __importDefault(require("lodash/floor"));
67
+ var round_1 = __importDefault(require("lodash/round"));
68
+ var sumBy_1 = __importDefault(require("lodash/sumBy"));
69
+ var toNumber_1 = __importDefault(require("lodash/toNumber"));
70
+ var products_1 = require("../interfaces/products");
71
+ var data_1 = require("./data");
72
+ var products_2 = require("./products");
73
+ var cart_1 = require("./cart");
74
+ var g2_1 = require("./g2");
75
+ var data_2 = require("../constants/data");
76
+ var Cart_1 = require("../../../Interfaces/Cart");
77
+ var data_3 = require("../../../utils/data");
78
+ var products_3 = require("../../../utils/products");
79
+ var cart_2 = require("../interfaces/cart");
80
+ var data_4 = require("../interfaces/data");
81
+ var products_4 = require("../constants/products");
82
+ var object_1 = require("../../../utils/object");
83
+ var getDefaultTimeValues = function () {
84
+ var values = ['AM', 'PM'];
85
+ return values.map(function (v) { return ({ label: v, value: v }); });
86
+ };
87
+ exports.getDefaultTimeValues = getDefaultTimeValues;
88
+ var getAvailableHours = function (minDeliveryDate, selectedDate, grassProduct, concreteOrder, expeditionMethod, selectedDeliveryTime, isPro, isSample, isAccessoriesOnly, testDate, keepHours) {
89
+ if (!!!minDeliveryDate)
90
+ return { deliveryTimes: (0, exports.getDefaultTimeValues)() };
91
+ var deliveryTimes = (0, exports.getDefaultTimeValues)().map(function (t) { return t.value; });
92
+ var today = !!testDate
93
+ ? !!keepHours
94
+ ? (0, moment_1.default)(testDate).toDate()
95
+ : (0, moment_1.default)(testDate).set('hours', (0, moment_1.default)().hours()).toDate()
96
+ : (0, moment_1.default)().toDate();
97
+ if (!!concreteOrder && !!concreteOrder.inStock && expeditionMethod === 'pickup') {
98
+ var isPM = today.getHours() >= 12;
99
+ if (!!isPM) {
100
+ deliveryTimes = ['PM'];
101
+ }
102
+ return {
103
+ deliveryTimes: deliveryTimes.map(function (t) { return ({ label: t, value: t }); }),
104
+ newSelectedDeliveryTime: !!isPM ? { label: 'PM', value: 'PM' } : undefined
105
+ };
106
+ }
107
+ var resetHours = function (d) {
108
+ d.setHours(0);
109
+ d.setMinutes(0);
110
+ d.setSeconds(0);
111
+ d.setMilliseconds(0);
112
+ };
113
+ if (!!selectedDate)
114
+ resetHours(selectedDate);
115
+ resetHours(minDeliveryDate);
116
+ var newSelectedDeliveryTime = undefined;
117
+ var targetDateDay = minDeliveryDate.getDay();
118
+ var selectedDateDay = !!selectedDate ? selectedDate.getDay() : targetDateDay;
119
+ var isSelectedSameAsTarget = (0, moment_1.default)(minDeliveryDate).isSame(selectedDate) || !!!selectedDate;
120
+ var todayDay = today.getDay();
121
+ var isNonSpecialityGrass = !!grassProduct && !![products_4.kentucky, products_4.prestige].includes(grassProduct.sku);
122
+ var onlyPm = function () {
123
+ if (!!selectedDeliveryTime && selectedDeliveryTime === 'AM') {
124
+ newSelectedDeliveryTime = { label: 'PM', value: 'PM' };
125
+ }
126
+ deliveryTimes = ['PM'];
127
+ };
128
+ if (selectedDateDay === 0 || (selectedDateDay === 6 && !!!isPro && expeditionMethod === 'pickup')) {
129
+ deliveryTimes = [];
130
+ newSelectedDeliveryTime = undefined;
131
+ }
132
+ else {
133
+ if (isSelectedSameAsTarget) {
134
+ if (!!grassProduct || (!!concreteOrder && concreteOrder.type === 'green')) {
135
+ var todayReset = !!testDate ? (0, moment_1.default)(testDate).toDate() : (0, moment_1.default)().toDate();
136
+ resetHours(todayReset);
137
+ if (!![6, 0].includes(todayReset.getDay())) {
138
+ if ((![2].includes(targetDateDay) &&
139
+ (!!isNonSpecialityGrass ||
140
+ (!!concreteOrder && !concreteOrder.inStock && expeditionMethod === 'pickup'))) ||
141
+ (![3, 4].includes(targetDateDay) && !!!isNonSpecialityGrass)) {
142
+ if (targetDateDay === 6 && !!!isPro && expeditionMethod === 'pickup') {
143
+ newSelectedDeliveryTime = undefined;
144
+ deliveryTimes = [];
145
+ }
146
+ else {
147
+ var amTimeToCheck = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
148
+ if (today.getHours() >= amTimeToCheck) {
149
+ onlyPm();
150
+ }
151
+ }
152
+ }
153
+ }
154
+ else {
155
+ var targetHour = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
156
+ if (todayDay == 5 &&
157
+ (!!grassProduct || (!!concreteOrder && concreteOrder.type == 'green' && expeditionMethod == 'pickup'))) {
158
+ targetHour = 16;
159
+ }
160
+ if (today.getHours() >= targetHour) {
161
+ onlyPm();
162
+ }
163
+ }
164
+ }
165
+ if ((!!!grassProduct && !!!concreteOrder) || !!isSample || !!isAccessoriesOnly) {
166
+ if (today.getHours() > 10) {
167
+ onlyPm();
168
+ }
169
+ }
170
+ }
171
+ }
172
+ return {
173
+ deliveryTimes: deliveryTimes.map(function (t) { return ({ label: t, value: t }); }),
174
+ newSelectedDeliveryTime: newSelectedDeliveryTime ? newSelectedDeliveryTime : undefined
175
+ };
176
+ };
177
+ exports.getAvailableHours = getAvailableHours;
178
+ var isDegel = function (dateToCheck) {
179
+ var date = !!dateToCheck ? (0, moment_1.default)(dateToCheck) : (0, moment_1.default)();
180
+ return date.isBetween('2024-03-04 00:00:01', '2024-04-15 23:59:59', undefined, '[]');
181
+ };
182
+ var getMinDatePicker = function (cartData, grassProduct, concreteOrder, expeditionMethod, isPro, testDate, blockedShippingDates, vracType, isPOS, spaceSchedule) {
183
+ var cartContainsInstallation = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.INSTALLATION, cartData);
184
+ var cartContainsVrac = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.VRAC, cartData);
185
+ var isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
186
+ var minDates = {};
187
+ if (!!testDate && !isPOS) {
188
+ testDate.setHours((0, moment_1.default)().hours());
189
+ }
190
+ var now = testDate || (0, moment_1.default)().toDate();
191
+ var min_date = testDate || (0, moment_1.default)().toDate();
192
+ var nbDaysOffset = (0, exports.getMinDateOffset)(now, cartContainsInstallation, cartContainsVrac, cartData, grassProduct, concreteOrder, isAccessoriesOnly, expeditionMethod, vracType);
193
+ var typeToCheck = !!concreteOrder
194
+ ? 'beton'
195
+ : !!grassProduct
196
+ ? 'gazon'
197
+ : !!cartContainsVrac || (!!!isPro && !!vracType)
198
+ ? 'vrac'
199
+ : undefined;
200
+ var dateToCheck = new Date(min_date);
201
+ dateToCheck.setDate(min_date.getDate() + nbDaysOffset);
202
+ var pickupDateSameAsNewDate = false;
203
+ var blockedDays = {
204
+ vrac: [0],
205
+ beton: [0],
206
+ gazon: [0]
207
+ };
208
+ var getNextAvailableDay = function (type) {
209
+ var dayToCheck = dateToCheck.getDay();
210
+ if (!!blockedDays[type]) {
211
+ if (blockedDays[type].includes(dayToCheck)) {
212
+ dateToCheck.setDate(dateToCheck.getDate() + 1);
213
+ return getNextAvailableDay(type);
214
+ }
215
+ }
216
+ if (!!spaceSchedule && expeditionMethod === 'pickup') {
217
+ var storeId = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.pickup_store.id');
218
+ if (!!storeId && !!(0, exports.dateIsClosedInSchedule)(storeId, dateToCheck, spaceSchedule)) {
219
+ dateToCheck.setDate(dateToCheck.getDate() + 1);
220
+ return getNextAvailableDay(type);
221
+ }
222
+ }
223
+ min_date = dateToCheck;
224
+ min_date.setHours(0);
225
+ min_date.setMinutes(0);
226
+ min_date.setSeconds(0);
227
+ };
228
+ if (!!typeToCheck) {
229
+ getNextAvailableDay(typeToCheck);
230
+ if (typeToCheck === 'vrac') {
231
+ pickupDateSameAsNewDate = true;
232
+ }
233
+ }
234
+ if (!!blockedShippingDates && blockedShippingDates.length && !!typeToCheck && expeditionMethod === 'delivery') {
235
+ var blockedDatesToCheck = blockedShippingDates.find(function (blockedDate) { return blockedDate.cart_type === typeToCheck; });
236
+ if (!!blockedDatesToCheck && !!blockedDatesToCheck.dates && !!blockedDatesToCheck.dates.length) {
237
+ var isInBlockedPeriod = blockedDatesToCheck.dates.find(function (blocked) {
238
+ return (!!blocked.start_date &&
239
+ !!blocked.end_date &&
240
+ (0, moment_1.default)(dateToCheck).isBetween((0, moment_1.default)((0, data_3.formatDate)(blocked.start_date)), (0, moment_1.default)((0, data_3.formatDate)(blocked.end_date)), 'date', '[]'));
241
+ });
242
+ if (!!isInBlockedPeriod) {
243
+ dateToCheck = (0, moment_1.default)((0, data_3.formatDate)(isInBlockedPeriod.end_date)).add(1, 'days').toDate();
244
+ getNextAvailableDay(typeToCheck);
245
+ var pickup_date = !!pickupDateSameAsNewDate ? dateToCheck : (0, moment_1.default)(min_date).toDate();
246
+ return {
247
+ min_delivery: min_date,
248
+ min_pickup: pickup_date
249
+ };
250
+ }
251
+ }
252
+ }
253
+ if (!!!concreteOrder || concreteOrder.type !== 'yellow') {
254
+ min_date.setDate(dateToCheck.getDate());
255
+ min_date.setHours(0);
256
+ min_date.setMinutes(0);
257
+ min_date.setSeconds(0);
258
+ var pickup_date = (0, moment_1.default)(min_date).toDate();
259
+ minDates = {
260
+ min_delivery: min_date,
261
+ min_pickup: pickup_date
262
+ };
263
+ }
264
+ return minDates;
265
+ };
266
+ exports.getMinDatePicker = getMinDatePicker;
267
+ var getMinDateOffset = function (now, cartContainsInstallation, cartContainsVrac, cartData, grassProduct, concreteOrder, isAccessoriesOnly, expeditionMethod, vracType) {
268
+ var current_hour = now.getHours();
269
+ var current_day = now.getDay();
270
+ var nb_days_offset = 1;
271
+ var allGrassDelaysSameAsNonSpecialityGrasses = true;
272
+ if (!!cartContainsInstallation) {
273
+ switch (current_day) {
274
+ case 5:
275
+ nb_days_offset = 3;
276
+ break;
277
+ default:
278
+ nb_days_offset = 2;
279
+ break;
280
+ }
281
+ }
282
+ else if (cartData.items.find(function (item) { return item.is_sample; }) || !!isAccessoriesOnly) {
283
+ if (expeditionMethod === 'delivery') {
284
+ nb_days_offset = 7;
285
+ }
286
+ else {
287
+ switch (current_day) {
288
+ case 4:
289
+ nb_days_offset = 4;
290
+ break;
291
+ case 5:
292
+ nb_days_offset = current_hour < 10 ? 3 : 4;
293
+ break;
294
+ case 6:
295
+ nb_days_offset = 4;
296
+ break;
297
+ case 0:
298
+ nb_days_offset = 3;
299
+ break;
300
+ default:
301
+ nb_days_offset = 2;
302
+ }
303
+ }
304
+ }
305
+ else if (expeditionMethod === 'delivery' &&
306
+ !!cartContainsVrac &&
307
+ !!(0, object_1.recursiveCheckObject)(vracType, 'vrac_type') &&
308
+ [products_1.VracTypeEnum.AUTRE_TONNE, products_1.VracTypeEnum.NOBEL_TONNE].includes(vracType.vrac_type)) {
309
+ nb_days_offset = 1;
310
+ }
311
+ else if ((!!grassProduct &&
312
+ ([products_4.kentucky, products_4.prestige].includes(grassProduct.sku) || !!allGrassDelaysSameAsNonSpecialityGrasses)) ||
313
+ (!!concreteOrder && concreteOrder.type === 'green' && !concreteOrder.inStock && expeditionMethod === 'pickup')) {
314
+ var amTimeToCheck = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
315
+ switch (current_day) {
316
+ case 5:
317
+ nb_days_offset = current_hour < amTimeToCheck ? 1 : current_hour < 16 ? 3 : 3;
318
+ break;
319
+ case 6:
320
+ nb_days_offset = 3;
321
+ break;
322
+ case 0:
323
+ nb_days_offset = 2;
324
+ break;
325
+ default:
326
+ nb_days_offset = 1;
327
+ }
328
+ }
329
+ else if (!!concreteOrder &&
330
+ concreteOrder.type === 'green' &&
331
+ concreteOrder.inStock &&
332
+ expeditionMethod === 'pickup') {
333
+ nb_days_offset = 0;
334
+ }
335
+ else if (!!grassProduct && !!![products_4.kentucky, products_4.prestige].includes(grassProduct.sku)) {
336
+ switch (current_day) {
337
+ case 5:
338
+ case 6:
339
+ case 0:
340
+ nb_days_offset = 4;
341
+ break;
342
+ default:
343
+ nb_days_offset = 2;
344
+ }
345
+ }
346
+ else if (!!concreteOrder && concreteOrder.type === 'green' && expeditionMethod === 'delivery') {
347
+ switch (current_day) {
348
+ case 0:
349
+ nb_days_offset = 3;
350
+ break;
351
+ case 1:
352
+ case 2:
353
+ case 3:
354
+ nb_days_offset = current_hour < 10 ? 2 : 3;
355
+ break;
356
+ case 4:
357
+ nb_days_offset = current_hour < 10 ? 2 : current_hour < 16 ? 4 : 5;
358
+ break;
359
+ case 5:
360
+ nb_days_offset = current_hour < 16 ? 4 : 5;
361
+ break;
362
+ case 6:
363
+ nb_days_offset = 4;
364
+ break;
365
+ default:
366
+ break;
367
+ }
368
+ }
369
+ else if (expeditionMethod === 'delivery') {
370
+ switch (current_day) {
371
+ case 0:
372
+ nb_days_offset = 4;
373
+ break;
374
+ case 1:
375
+ case 2:
376
+ nb_days_offset = current_hour < 10 ? 3 : 4;
377
+ break;
378
+ case 3:
379
+ nb_days_offset = current_hour < 10 ? 3 : 6;
380
+ break;
381
+ case 4:
382
+ case 5:
383
+ nb_days_offset = current_hour < 10 ? 5 : 6;
384
+ break;
385
+ case 6:
386
+ nb_days_offset = 5;
387
+ break;
388
+ default:
389
+ break;
390
+ }
391
+ }
392
+ return nb_days_offset;
393
+ };
394
+ exports.getMinDateOffset = getMinDateOffset;
395
+ var shouldDisableDate = function (date, blockedDates, expeditionMethod, cartData, schedule, selectedStore) {
396
+ if (!!!cartData)
397
+ return false;
398
+ var typeToCheck = (0, cart_1.getCartType)(cartData);
399
+ var blockedDays = {
400
+ vrac: [0],
401
+ beton: [0],
402
+ gazon: [0],
403
+ only_accessories: [0],
404
+ sample: [0]
405
+ };
406
+ if (!!!typeToCheck || (!!blockedDays[typeToCheck] && !!blockedDays[typeToCheck].includes(date.getDay()))) {
407
+ return true;
408
+ }
409
+ if (expeditionMethod !== 'pickup' && !!typeToCheck && !!blockedDates) {
410
+ var sameType = blockedDates.find(function (blocked) { return blocked.cart_type === typeToCheck; });
411
+ if (!!sameType && !!sameType.dates) {
412
+ for (var _i = 0, _a = sameType.dates; _i < _a.length; _i++) {
413
+ var dates = _a[_i];
414
+ if (!!dates.start_date &&
415
+ !!dates.end_date &&
416
+ (0, moment_1.default)(date).isBetween((0, moment_1.default)((0, data_3.formatDate)(dates.start_date)), (0, moment_1.default)((0, data_3.formatDate)(dates.end_date)), 'date', '[]'))
417
+ return true;
418
+ }
419
+ }
420
+ }
421
+ var storeId = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.pickup_store.id');
422
+ if ((!!storeId || !!selectedStore) && expeditionMethod === 'pickup' && !!schedule) {
423
+ return !!(0, exports.dateIsClosedInSchedule)(!!storeId ? storeId : selectedStore, date, schedule);
424
+ }
425
+ return false;
426
+ };
427
+ exports.shouldDisableDate = shouldDisableDate;
428
+ var dateIsClosedInSchedule = function (storeId, dateToCheck, spaceSchedule) {
429
+ var _a;
430
+ var weekdayIndex = dateToCheck.getDay();
431
+ var storeSchedules = spaceSchedule.store_schedules[storeId];
432
+ if (!!storeSchedules) {
433
+ var selectedDaySchedule = void 0;
434
+ if (!!spaceSchedule.space_periods_active) {
435
+ var year = dateToCheck.getFullYear().toString();
436
+ var periods = (_a = spaceSchedule.year_periods[year]) !== null && _a !== void 0 ? _a : [];
437
+ var matchingPeriod = periods.find(function (p) { return new Date(p.starts_at) <= dateToCheck && dateToCheck <= new Date(p.ends_at); });
438
+ if (!!matchingPeriod) {
439
+ var periodSchedule = storeSchedules[matchingPeriod.id];
440
+ if (!!periodSchedule) {
441
+ var daySchedule = periodSchedule.weekly_schedule[weekdayIndex];
442
+ if (!!daySchedule) {
443
+ selectedDaySchedule = daySchedule;
444
+ }
445
+ }
446
+ }
447
+ }
448
+ if (!!!selectedDaySchedule) {
449
+ var generalSchedule = storeSchedules['general'];
450
+ if (!!generalSchedule) {
451
+ selectedDaySchedule = generalSchedule.weekly_schedule[weekdayIndex];
452
+ }
453
+ }
454
+ if (!!selectedDaySchedule && selectedDaySchedule.open === false) {
455
+ return true;
456
+ }
457
+ }
458
+ var isClosed = spaceSchedule.common_closed_days.some(function (c) {
459
+ var start = new Date(c.start_date);
460
+ var end = c.end_date ? new Date(c.end_date) : start;
461
+ start.setFullYear(dateToCheck.getFullYear());
462
+ start.setHours(0, 0, 0, 0);
463
+ end.setFullYear(dateToCheck.getFullYear());
464
+ end.setHours(0, 0, 0, 0);
465
+ dateToCheck.setHours(0, 0, 0, 0);
466
+ return c.open === false && dateToCheck >= start && dateToCheck <= end && !!c.associated_stores.includes(storeId);
467
+ });
468
+ return isClosed;
469
+ };
470
+ exports.dateIsClosedInSchedule = dateIsClosedInSchedule;
471
+ var checkIfCartTypeHasBlockedDates = function (cartData, blockedDates) {
472
+ if (!!!cartData || !!!blockedDates || !!!blockedDates.length)
473
+ return false;
474
+ var cartType = (0, cart_1.getCartType)(cartData);
475
+ var sameType = blockedDates.find(function (blocked) { return blocked.cart_type === cartType; });
476
+ if (!!!sameType)
477
+ return false;
478
+ return !!sameType.dates && !!sameType.dates.length;
479
+ };
480
+ exports.checkIfCartTypeHasBlockedDates = checkIfCartTypeHasBlockedDates;
481
+ exports.slugsToCheckFromExpeditionFees = {
482
+ pickup: ['frais-preparation-general-beton', 'frais-palette', 'minimum-facturable-commande'],
483
+ shipping: [
484
+ 'livraison-echantillons',
485
+ 'livraison-accessoires',
486
+ 'livraison-beton-accessoires',
487
+ 'livraison-gazon',
488
+ 'frais-de-livraison-vrac',
489
+ 'minimum-facturable-commande'
490
+ ]
491
+ };
492
+ var getPalletQty = function (items, orderType, minQteGrassOrder) {
493
+ if (minQteGrassOrder === void 0) { minQteGrassOrder = 0; }
494
+ var total = (0, sumBy_1.default)(items.map(function (item) {
495
+ if (!!!item.other_units ||
496
+ !!item.is_service ||
497
+ !!item.is_sample ||
498
+ (!!orderType && !!['grass'].includes(orderType) && item.sku === products_4.kentucky && !!item.is_upsell_of_sku)) {
499
+ return 0;
500
+ }
501
+ var paletteUnit = item.other_units.find(function (u) { return u.unit_slug === 'pal'; });
502
+ var sellUnitCheck = item.other_units.find(function (u) { return !!u.is_sale_unit; });
503
+ var sellUnit = 1;
504
+ if (!!sellUnitCheck) {
505
+ sellUnit = !!sellUnitCheck.fitting_unit ? sellUnitCheck.fitting_unit : 1;
506
+ }
507
+ if (!!!paletteUnit || !!!paletteUnit.fitting_unit) {
508
+ return 0;
509
+ }
510
+ var typeAttr = item.attributes[data_4.AttributesIdEnumGR.TYPE];
511
+ if (!!!typeAttr || !!!typeAttr.length) {
512
+ return 0;
513
+ }
514
+ if (!!typeAttr && !typeAttr.includes('gazon') && !typeAttr.includes('beton')) {
515
+ return (0, floor_1.default)((item.qte * sellUnit) / paletteUnit.fitting_unit);
516
+ }
517
+ if (!!typeAttr.includes('gazon') && !!minQteGrassOrder && item.qte < minQteGrassOrder) {
518
+ return minQteGrassOrder / paletteUnit.fitting_unit;
519
+ }
520
+ return (item.qte * sellUnit) / paletteUnit.fitting_unit;
521
+ }));
522
+ if (orderType === 'concrete') {
523
+ return (0, ceil_1.default)(total);
524
+ }
525
+ return total;
526
+ };
527
+ exports.getPalletQty = getPalletQty;
528
+ var getGrassRoundedPickupPalletFees = function (realPalletNumber) {
529
+ var ratio = (0, round_1.default)(400 / 740, 3);
530
+ var fraction = (0, round_1.default)(realPalletNumber % 1, 3);
531
+ if (fraction >= ratio)
532
+ return (0, ceil_1.default)(realPalletNumber);
533
+ return (0, floor_1.default)(realPalletNumber);
534
+ };
535
+ exports.getGrassRoundedPickupPalletFees = getGrassRoundedPickupPalletFees;
536
+ var getPalletQtyPalletFee = function (items, expeditionMethod, isGrass, isMixed) {
537
+ var totalPalletGrass = 0;
538
+ var totalPalletOther = 0;
539
+ items = items.filter(function (i) { return !(0, products_2.checkIfProductIsOfType)(i, 'accessoire'); });
540
+ if (!!isGrass) {
541
+ var grassItemsToCheck = !!isMixed ? items.filter(function (i) { return !!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); }) : items;
542
+ var calculatedPalletsGrass = (0, exports.getPalletQty)(grassItemsToCheck, 'grass');
543
+ totalPalletGrass =
544
+ expeditionMethod === 'pickup'
545
+ ? (0, exports.getGrassRoundedPickupPalletFees)(calculatedPalletsGrass)
546
+ : (0, ceil_1.default)(calculatedPalletsGrass);
547
+ }
548
+ if (!!!isGrass || !!isMixed) {
549
+ var otherItemsToCheck = !!isMixed ? items.filter(function (i) { return !!!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); }) : items;
550
+ totalPalletOther = (0, exports.calculatePalFeeForOtherThanGrass)(otherItemsToCheck);
551
+ }
552
+ var totalPallet = totalPalletGrass + totalPalletOther;
553
+ return totalPallet;
554
+ };
555
+ exports.getPalletQtyPalletFee = getPalletQtyPalletFee;
556
+ var calculatePalFeeForOtherThanGrass = function (items) {
557
+ var total = (0, sumBy_1.default)(items.map(function (item) {
558
+ if (!!!item.other_units || !!item.is_service || !!item.is_sample) {
559
+ return 0;
560
+ }
561
+ var exceptions = [
562
+ 'muret-supra-citadin-180',
563
+ 'muret-m-100-serie-moderne-double-face',
564
+ 'muret-ora-double-face',
565
+ 'pas-japonais-grand',
566
+ 'marche-nueva',
567
+ 'marche-aria',
568
+ 'marche-t-200',
569
+ 'marche-solino',
570
+ 'marche-caralina',
571
+ 'marche-rio-15',
572
+ 'marche-appalaches',
573
+ 'marche-citadin',
574
+ 'marche-laurentien',
575
+ 'marche-m-100-serie-moderne',
576
+ 'marche-citadin-180',
577
+ 'marche-ora',
578
+ 'marche-t-100-serie-traditionnelle',
579
+ 'marche-prestige-180'
580
+ ];
581
+ var itemIsException = item.parent_slug && exceptions.includes(item.parent_slug);
582
+ var palUnit = item.other_units.find(function (u) { return u.unit_slug === 'pal'; });
583
+ var rgUnit = item.other_units.find(function (u) { return u.unit_slug === 'rg'; });
584
+ var unitUnit = item.other_units.find(function (u) { return !!u.fitting_unit && u.fitting_unit === 1; });
585
+ var sellUnitCheck = item.other_units.find(function (u) { return !!u.is_sale_unit; });
586
+ var sellUnit = 1;
587
+ if (!!sellUnitCheck) {
588
+ sellUnit = !!sellUnitCheck.fitting_unit ? sellUnitCheck.fitting_unit : 1;
589
+ }
590
+ var typeAttr = item.attributes[data_4.AttributesIdEnumGR.TYPE];
591
+ if (!!!palUnit || !!!palUnit.fitting_unit || !!!typeAttr || !!!typeAttr.length) {
592
+ if (!!itemIsException)
593
+ return 1;
594
+ if (!!!rgUnit || !!!rgUnit.fitting_unit) {
595
+ return 0;
596
+ }
597
+ else {
598
+ var nbRang = (item.qte * sellUnit) / rgUnit.fitting_unit;
599
+ if (nbRang > 0 && nbRang <= 1) {
600
+ return 0;
601
+ }
602
+ else {
603
+ return 1;
604
+ }
605
+ }
606
+ }
607
+ if (!!typeAttr && !typeAttr.includes('gazon') && !typeAttr.includes('beton')) {
608
+ return (0, floor_1.default)((item.qte * sellUnit) / palUnit.fitting_unit);
609
+ }
610
+ var palQty = (item.qte * sellUnit) / (palUnit.fitting_unit || 1);
611
+ var rgQty = !!rgUnit ? (item.qte * sellUnit) / (rgUnit.fitting_unit || 1) : 0;
612
+ var unitQty = !!unitUnit ? (item.qte * sellUnit) / (unitUnit.fitting_unit || 1) : !!sellUnit ? item.qte : 0;
613
+ var totalPal = (0, floor_1.default)(palQty);
614
+ var unitsInRg = !!rgUnit ? rgUnit.fitting_unit || 0 : 0;
615
+ var unitsInPal = palUnit.fitting_unit || 0;
616
+ if (item.qte / unitsInPal === totalPal)
617
+ return totalPal;
618
+ if (!!rgQty && !!rgUnit) {
619
+ var rgInPal = (palUnit.fitting_unit || 1) / (rgUnit.fitting_unit || 1);
620
+ if (palQty >= 1 && (0, ceil_1.default)(rgQty % rgInPal) >= 2) {
621
+ totalPal += 1;
622
+ }
623
+ else {
624
+ if (palQty < 1) {
625
+ if (!!unitQty) {
626
+ if (!!itemIsException && unitQty % unitsInPal !== 0) {
627
+ totalPal += 1;
628
+ }
629
+ else if (!!unitsInRg && unitQty > unitsInRg && unitQty / unitsInRg > 1) {
630
+ totalPal += 1;
631
+ }
632
+ }
633
+ }
634
+ }
635
+ }
636
+ else {
637
+ if (!!unitQty && !!itemIsException) {
638
+ if (unitQty % unitsInPal !== 0) {
639
+ totalPal += 1;
640
+ }
641
+ }
642
+ }
643
+ return totalPal;
644
+ }));
645
+ return total;
646
+ };
647
+ exports.calculatePalFeeForOtherThanGrass = calculatePalFeeForOtherThanGrass;
648
+ var getMinGrassQte = function (_grassProduct, expeditionMethod, _isPro) {
649
+ var minQteGrassOrder = 0;
650
+ if (expeditionMethod != 'pickup') {
651
+ minQteGrassOrder = 740;
652
+ }
653
+ return minQteGrassOrder;
654
+ };
655
+ exports.getMinGrassQte = getMinGrassQte;
656
+ var getMinQteInstall = function (_isPro) {
657
+ return 740;
658
+ };
659
+ exports.getMinQteInstall = getMinQteInstall;
660
+ var resetAllFeesIfAccessoriesOnly = function (currentItems) {
661
+ var slugsToDelete = [
662
+ 'livraison-gazon',
663
+ 'minimum-facturable-commande',
664
+ 'surcharge-jour-meme-gazon',
665
+ 'livraison-beton-accessoires',
666
+ 'frais-preparation-general-beton',
667
+ 'frais-commande-beton-pas-en-ligne',
668
+ 'frais-preparation',
669
+ 'surcharges-installation-gazon',
670
+ 'surcharges-commandes-gazon',
671
+ 'surcharges-commandes-gazon-debut-fin-saison',
672
+ 'surcharge-gazon-ramassage-hors-ferme',
673
+ 'frais-commande-gazon-pas-en-ligne'
674
+ ];
675
+ var itemsToDelete = [];
676
+ for (var _i = 0, currentItems_1 = currentItems; _i < currentItems_1.length; _i++) {
677
+ var i = currentItems_1[_i];
678
+ if (!!i.parent_slug && !!slugsToDelete.includes(i.parent_slug))
679
+ itemsToDelete.push(i.sku);
680
+ }
681
+ return itemsToDelete;
682
+ };
683
+ var checkIfShouldApplySameDayGrassFee = function (firstDayForExpedition, expeditionMethod, selectedExpeditionDate, testDate) {
684
+ var dateToCheck = expeditionMethod === 'pickup' ? firstDayForExpedition.min_pickup : firstDayForExpedition.min_delivery;
685
+ var dateSelectedIsBeforeFirstCalculatedDay = !!dateToCheck && (0, moment_1.default)((0, data_3.formatDate)(selectedExpeditionDate)).isBefore((0, moment_1.default)(dateToCheck), 'date');
686
+ var isHoliday = (0, data_1.getHolidays)().some(function (h) { return (0, moment_1.default)(h).isSame(testDate ? (0, moment_1.default)(testDate) : (0, moment_1.default)(), 'date'); });
687
+ var isAfter4PM = (!!testDate ? (0, moment_1.default)(testDate) : (0, moment_1.default)()).hour() >= 16;
688
+ var dateSelectedForExpeditionIsTomorrowOrToday = (0, moment_1.default)(selectedExpeditionDate).isSameOrBefore((0, moment_1.default)().add(1, 'day'), 'date');
689
+ return (!!dateSelectedIsBeforeFirstCalculatedDay ||
690
+ ((!!isHoliday || !!isAfter4PM) && !!dateSelectedForExpeditionIsTomorrowOrToday));
691
+ };
692
+ exports.checkIfShouldApplySameDayGrassFee = checkIfShouldApplySameDayGrassFee;
693
+ var checkForSameGrassDayFee = function (isPOS, isPro, totalPallet, grassProduct, selectedExepeditionDate, isReserved) {
694
+ if (!!isReserved)
695
+ return false;
696
+ return !!selectedExepeditionDate && !!grassProduct && totalPallet >= 4 && (!!isPOS || !!isPro);
697
+ };
698
+ exports.checkForSameGrassDayFee = checkForSameGrassDayFee;
699
+ exports.expeditionFeePalletTier = 24;
700
+ exports.installationFeePalletTier = 48;
701
+ var applyFeesToCart = function (fetchProduct, getIfAddressIsInsideZones, getDistanceFromAddress, cart, expeditionMethod, grassProduct, concreteOrder, cartContainsInstallation, cartContainsVrac, availableVracStoreIDs, isPro, addOnePalletToPickup, cartContainsSample, saveToShippingPayload, deliveryAddress, locale, expeditionDate, equipmentPickupOnSite, cartContainsOnlyAccessories, pickupStore, allStores, customPriceList, useFeeArray) { return __awaiter(void 0, void 0, void 0, function () {
702
+ var itemsToAdd, itemsToDelete, itemsToUpdate, newShippingPayload, minQteGrassOrder, isPOS, isMixed, totalPalletOther, totalPalletGrass, concreteItemsToCheck, grassItemsToCheck, totalPallet, totalPalletMinQte, minQteInstall, cartType, shouldAddPaletFees, qtyOfSkuNeeded, productToAdd, palletFeeDecli_1, parentProduct_1, product3_1, product4_15_1, product16_1, add_1, addRestQty, qty4AndMore, rest, parentProduct_2, product1To5_1, product6To11_1, product12AndMore_1, add_2, addRestQty, qty4AndMore, rest, isSpecialityGrass, qtyToAdd, product, decli_1, price, isKentucky, minGrassQteItem, minimumBillable, sameDayGrassFee, decli, firstDayForExpedition, shouldApplySameDayFee, removeShippingFee, productToAdd, e_1, sampleDeliveryFee, cartAccessoriesDeliveryFee, productToAdd, shouldApplyFees, feesToAdd_1, orderDate_1, pickupStoreId, shipping_address_1, pickupStore_1, surchargesCommandesGazon, surchargesCommandesGazonDebutFinSaison, surchargesInstallationGazon, surchargesInstallationGazonDebutFinSaison, surchargesGazonPickupHorsFerme, fraisSiCommandePasEnLigne, e_2, e_3, e_4, e_5, e_6, _a, e_7, addSku_1, allOrderFees, allInstallationFees, cd, summer, shouldAddGrassSeasonFee, shouldAddInstallSeasonFee, fraisPreparationGeneralBeton, onlyConcretePalQty, decli_2, getFeeAmount, feeProd, skuToAdd, concreteItems, numberOfIncompletePallets, _i, concreteItems_1, item, saleUnit, palUnit, calculatedPal, rest, surchargesCommandesBeton, decli_3, prepItem, isOutOfArea, insideZones, e_8, productInstallToAdd, _b, productToAdd, mtl, mtlInstall, ontario, ontarioInstall, ileOrleans, deliveryTruckProduct, storeIDToCheck, storeAddress, distance, _1, degelFeeSku, degelFeeProd, degelFeeDecli;
703
+ return __generator(this, function (_c) {
704
+ switch (_c.label) {
705
+ case 0:
706
+ itemsToAdd = [];
707
+ itemsToDelete = [];
708
+ itemsToUpdate = [];
709
+ newShippingPayload = cart.shipping_payload || {};
710
+ minQteGrassOrder = 0;
711
+ if (!!grassProduct) {
712
+ minQteGrassOrder = (0, exports.getMinGrassQte)(grassProduct, expeditionMethod, isPro);
713
+ }
714
+ isPOS = [Cart_1.CartTypeEnum.POS, Cart_1.CartTypeEnum.POS_TRANSACTIONNAL].includes(cart.cart_type);
715
+ isMixed = cart.cart_content_type === Cart_1.CartContentTypeEnum.MIXED;
716
+ totalPalletOther = 0;
717
+ totalPalletGrass = 0;
718
+ if (!!concreteOrder) {
719
+ concreteItemsToCheck = !!isMixed
720
+ ? cart.items.filter(function (i) { return !!!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); })
721
+ : cart.items;
722
+ totalPalletOther = (0, exports.getPalletQty)(concreteItemsToCheck, 'concrete');
723
+ }
724
+ if (!!grassProduct) {
725
+ grassItemsToCheck = !!isMixed && !!concreteOrder ? cart.items.filter(function (i) { return !!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true); }) : cart.items;
726
+ totalPalletGrass = (0, exports.getPalletQty)(grassItemsToCheck, 'grass');
727
+ }
728
+ totalPallet = totalPalletGrass + totalPalletOther;
729
+ totalPalletMinQte = (0, exports.getPalletQty)(cart.items, !!concreteOrder ? 'concrete' : !!grassProduct ? 'grass' : undefined, minQteGrassOrder);
730
+ minQteInstall = (0, exports.getMinQteInstall)(!!isPro);
731
+ cartType = !!isPOS ? 'in_store' : !!cart.clerk_id ? 'with_clerk' : 'online';
732
+ shouldAddPaletFees = !!!cartContainsInstallation && !!!cartContainsSample && !!!cartContainsVrac;
733
+ if (!((!!isMixed || !!shouldAddPaletFees) && (!!isPro || !!!grassProduct) && !!!cartContainsOnlyAccessories)) return [3, 2];
734
+ qtyOfSkuNeeded = (0, exports.getPalletQtyPalletFee)(cart.items, expeditionMethod, !!(0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.GRASS, cart), isMixed);
735
+ if (!!addOnePalletToPickup && expeditionMethod === 'pickup') {
736
+ qtyOfSkuNeeded += 1;
737
+ }
738
+ if (!!addOnePalletToPickup && !!!useFeeArray && !!saveToShippingPayload) {
739
+ newShippingPayload = __assign(__assign({}, newShippingPayload), { addOnePalletToPickup: true });
740
+ }
741
+ return [4, fetchProduct('frais-palette', locale, !!useFeeArray, true)];
742
+ case 1:
743
+ productToAdd = _c.sent();
744
+ if (!!productToAdd && !!productToAdd.declinations) {
745
+ palletFeeDecli_1 = productToAdd.declinations[0];
746
+ if (!!qtyOfSkuNeeded) {
747
+ itemsToAdd.push(__assign(__assign({}, productToAdd.declinations[0]), { qte: qtyOfSkuNeeded, parent_slug: productToAdd.slug, is_upsell_of_sku: 'summary', categories: productToAdd.categories }));
748
+ }
749
+ else if (cart.items.some(function (i) { return i.sku === palletFeeDecli_1.sku; })) {
750
+ itemsToDelete.push(palletFeeDecli_1.sku);
751
+ }
752
+ }
753
+ _c.label = 2;
754
+ case 2:
755
+ if (!!!grassProduct) return [3, 5];
756
+ if (!(expeditionMethod === 'delivery')) return [3, 4];
757
+ return [4, fetchProduct('livraison-gazon', locale, !!useFeeArray, true)];
758
+ case 3:
759
+ parentProduct_1 = _c.sent();
760
+ product3_1 = parentProduct_1
761
+ ? parentProduct_1.declinations.find(function (decli) { return ['17000000T'].includes(decli.sku); })
762
+ : undefined;
763
+ product4_15_1 = parentProduct_1
764
+ ? parentProduct_1.declinations.find(function (decli) { return decli.sku === '170000000'; })
765
+ : undefined;
766
+ product16_1 = parentProduct_1
767
+ ? parentProduct_1.declinations.find(function (decli) { return decli.sku === '170000160'; })
768
+ : undefined;
769
+ add_1 = function (product, qty) {
770
+ if (!!product) {
771
+ var alreadyToAdd = (0, findIndex_1.default)(itemsToAdd, function (i) { return i.sku === product.sku; });
772
+ if (alreadyToAdd === -1) {
773
+ itemsToAdd.push(__assign(__assign({}, product), { is_upsell_of_sku: 'summary', qte: qty, parent_slug: 'livraison-gazon' }));
774
+ }
775
+ else {
776
+ itemsToAdd[alreadyToAdd] = __assign(__assign(__assign({}, itemsToAdd[alreadyToAdd]), { is_upsell_of_sku: 'summary', qte: itemsToAdd[alreadyToAdd].qte + qty, parent_slug: 'livraison-gazon' }), (!!parentProduct_1 ? { categories: parentProduct_1.categories } : {}));
777
+ }
778
+ }
779
+ };
780
+ addRestQty = function (pallets) {
781
+ if (pallets > 0 && pallets < 4) {
782
+ add_1(product3_1, 1);
783
+ }
784
+ if (pallets >= 4 && pallets < 16) {
785
+ add_1(product4_15_1, 1);
786
+ }
787
+ if (pallets >= 16) {
788
+ add_1(product16_1, 1);
789
+ }
790
+ };
791
+ if (totalPalletMinQte <= exports.expeditionFeePalletTier) {
792
+ addRestQty(totalPalletMinQte);
793
+ }
794
+ else {
795
+ qty4AndMore = (0, floor_1.default)(totalPalletMinQte / exports.expeditionFeePalletTier);
796
+ rest = (0, ceil_1.default)(totalPalletMinQte % exports.expeditionFeePalletTier);
797
+ add_1(product16_1, qty4AndMore);
798
+ addRestQty(rest);
799
+ }
800
+ _c.label = 4;
801
+ case 4:
802
+ cart.items
803
+ .filter(function (i) { return i.parent_slug === 'livraison-gazon'; })
804
+ .map(function (item) {
805
+ if (!itemsToAdd.map(function (i) { return i.sku; }).includes(item.sku) || expeditionMethod === 'pickup') {
806
+ itemsToDelete.push(item.sku);
807
+ }
808
+ return;
809
+ });
810
+ _c.label = 5;
811
+ case 5:
812
+ if (!(!!!cartContainsVrac && !!!cartContainsSample && !!!grassProduct && !!!cartContainsOnlyAccessories)) return [3, 8];
813
+ if (!(expeditionMethod === 'delivery')) return [3, 7];
814
+ return [4, fetchProduct('livraison-beton-accessoires', locale, !!useFeeArray, true)];
815
+ case 6:
816
+ parentProduct_2 = _c.sent();
817
+ product1To5_1 = parentProduct_2
818
+ ? parentProduct_2.declinations.find(function (decli) { return decli.sku === '170060450'; })
819
+ : undefined;
820
+ product6To11_1 = parentProduct_2
821
+ ? parentProduct_2.declinations.find(function (decli) { return decli.sku === '170060650'; })
822
+ : undefined;
823
+ product12AndMore_1 = parentProduct_2
824
+ ? parentProduct_2.declinations.find(function (decli) { return decli.sku === '170060000'; })
825
+ : undefined;
826
+ add_2 = function (product, qty) {
827
+ if (!!product) {
828
+ var alreadyToAdd = (0, findIndex_1.default)(itemsToAdd, function (i) { return i.sku === product.sku; });
829
+ if (alreadyToAdd === -1) {
830
+ itemsToAdd.push(__assign(__assign({}, product), { is_upsell_of_sku: 'summary', parent_slug: 'livraison-beton-accessoires', qte: qty }));
831
+ }
832
+ else {
833
+ itemsToAdd[alreadyToAdd] = __assign(__assign(__assign({}, itemsToAdd[alreadyToAdd]), { is_upsell_of_sku: 'summary', qte: itemsToAdd[alreadyToAdd].qte + qty, parent_slug: 'livraison-beton-accessoires' }), (!!parentProduct_2 ? { categories: parentProduct_2.categories } : {}));
834
+ }
835
+ }
836
+ };
837
+ addRestQty = function (pallets) {
838
+ switch (true) {
839
+ case pallets > 0 && pallets <= 5:
840
+ add_2(product1To5_1, 1);
841
+ return;
842
+ case pallets > 5 && pallets < 12:
843
+ add_2(product6To11_1, 1);
844
+ return;
845
+ case pallets >= 12:
846
+ add_2(product12AndMore_1, 1);
847
+ return;
848
+ }
849
+ };
850
+ if (totalPalletOther <= exports.expeditionFeePalletTier) {
851
+ addRestQty(totalPalletOther);
852
+ }
853
+ else {
854
+ qty4AndMore = (0, floor_1.default)(totalPalletMinQte / exports.expeditionFeePalletTier);
855
+ rest = (0, ceil_1.default)(totalPalletOther) % exports.expeditionFeePalletTier;
856
+ add_2(product12AndMore_1, qty4AndMore);
857
+ addRestQty(rest);
858
+ }
859
+ _c.label = 7;
860
+ case 7:
861
+ cart.items
862
+ .filter(function (i) { return i.parent_slug === 'livraison-beton-accessoires'; })
863
+ .map(function (item) {
864
+ if (!itemsToAdd.map(function (i) { return i.sku; }).includes(item.sku) || expeditionMethod === 'pickup') {
865
+ itemsToDelete.push(item.sku);
866
+ }
867
+ return;
868
+ });
869
+ _c.label = 8;
870
+ case 8:
871
+ if (!!!grassProduct) return [3, 11];
872
+ isSpecialityGrass = !!grassProduct && !!![products_4.kentucky].includes(grassProduct.sku);
873
+ qtyToAdd = minQteGrassOrder - grassProduct.qte;
874
+ if (!(qtyToAdd > 0)) return [3, 10];
875
+ return [4, fetchProduct('minimum-facturable-commande', locale, !!useFeeArray, true)];
876
+ case 9:
877
+ product = _c.sent();
878
+ if (!!product) {
879
+ decli_1 = product.declinations.find(function (d) { return d.sku === '010010000-M'; });
880
+ if (!!decli_1) {
881
+ price = grassProduct.price;
882
+ if (!!isSpecialityGrass) {
883
+ isKentucky = cart.items.find(function (i) { return i.sku === products_4.kentucky; });
884
+ price = isKentucky ? price + (0, products_3.getLowestPrice)(isKentucky).price.amount : price;
885
+ }
886
+ minGrassQteItem = __assign(__assign({}, decli_1), { regular_price: __assign(__assign({}, decli_1.regular_price), { amount: price }) });
887
+ if (!!isPro && !!customPriceList) {
888
+ minGrassQteItem = (0, g2_1.checkForCustomPriceEquivalent)(__assign(__assign({}, minGrassQteItem), { price_override: true }), customPriceList);
889
+ }
890
+ itemsToAdd.push(__assign(__assign({}, minGrassQteItem), { is_upsell_of_sku: 'summary', parent_slug: product.slug, price_override: true, qte: qtyToAdd, categories: product.categories }));
891
+ }
892
+ }
893
+ _c.label = 10;
894
+ case 10:
895
+ minimumBillable = cart.items.find(function (i) { return i.parent_slug === 'minimum-facturable-commande'; });
896
+ if (qtyToAdd <= 0 && !!minimumBillable) {
897
+ itemsToDelete.push(minimumBillable.sku);
898
+ }
899
+ _c.label = 11;
900
+ case 11: return [4, fetchProduct('surcharge-jour-meme-gazon', locale, !!useFeeArray, true)];
901
+ case 12:
902
+ sameDayGrassFee = _c.sent();
903
+ if (!!sameDayGrassFee) {
904
+ decli = sameDayGrassFee.declinations.find(function (d) { return d.sku === '000010990'; });
905
+ }
906
+ if (!!(0, exports.checkForSameGrassDayFee)(isPOS, isPro, totalPalletGrass, grassProduct, expeditionDate, (0, object_1.recursiveCheckObject)(cart.shipping_payload, 'is_reserved'))) {
907
+ firstDayForExpedition = (0, exports.getMinDatePicker)(cart, grassProduct, undefined, expeditionMethod || 'delivery', !!isPro, !!cart.created_by ? (0, data_3.formatDate)(cart.created_by.date) : undefined, undefined, undefined, isPOS);
908
+ shouldApplySameDayFee = (0, exports.checkIfShouldApplySameDayGrassFee)(firstDayForExpedition, expeditionMethod, expeditionDate);
909
+ if (!!sameDayGrassFee && !!decli) {
910
+ if (!!shouldApplySameDayFee) {
911
+ itemsToAdd.push(__assign(__assign({}, decli), { is_upsell_of_sku: 'summary', parent_slug: sameDayGrassFee.slug, price_override: true, qte: !!grassProduct ? grassProduct.qte : 1, categories: sameDayGrassFee.categories }));
912
+ }
913
+ }
914
+ }
915
+ if (!!sameDayGrassFee && !!decli) {
916
+ if (!!cart.items.some(function (i) { return i.sku === decli.sku; })) {
917
+ itemsToDelete.push(decli.sku);
918
+ }
919
+ }
920
+ if (!!!cartContainsSample) return [3, 19];
921
+ removeShippingFee = false;
922
+ if (!(expeditionMethod === 'delivery')) return [3, 18];
923
+ return [4, fetchProduct('livraison-echantillons', locale, !!useFeeArray, true)];
924
+ case 13:
925
+ productToAdd = _c.sent();
926
+ _c.label = 14;
927
+ case 14:
928
+ _c.trys.push([14, 16, , 17]);
929
+ return [4, (0, exports.checkIfShouldRemoveSampleShippingFee)(fetchProduct, cart, locale, !!useFeeArray)];
930
+ case 15:
931
+ removeShippingFee = _c.sent();
932
+ return [3, 17];
933
+ case 16:
934
+ e_1 = _c.sent();
935
+ console.log('error on checking if should remove sample shipping fee: ', e_1.toString());
936
+ return [3, 17];
937
+ case 17:
938
+ if (!!removeShippingFee) {
939
+ productToAdd = undefined;
940
+ }
941
+ if (!!productToAdd && !!productToAdd.declinations) {
942
+ itemsToAdd.push(__assign(__assign({}, productToAdd.declinations[0]), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: productToAdd.slug, categories: productToAdd.categories }));
943
+ }
944
+ _c.label = 18;
945
+ case 18:
946
+ sampleDeliveryFee = cart.items.find(function (i) { return i.parent_slug === 'livraison-echantillons'; });
947
+ if ((expeditionMethod === 'pickup' || !!removeShippingFee) && !!sampleDeliveryFee) {
948
+ itemsToDelete.push(sampleDeliveryFee.sku);
949
+ }
950
+ _c.label = 19;
951
+ case 19:
952
+ cartAccessoriesDeliveryFee = cart.items.find(function (i) { return i.parent_slug === 'livraison-accessoires'; });
953
+ if (!!!cartContainsOnlyAccessories) return [3, 22];
954
+ itemsToDelete = resetAllFeesIfAccessoriesOnly(cart.items);
955
+ if (!(expeditionMethod === 'delivery')) return [3, 21];
956
+ return [4, fetchProduct('livraison-accessoires', locale, !!useFeeArray, true)];
957
+ case 20:
958
+ productToAdd = _c.sent();
959
+ if (!!productToAdd && !!productToAdd.declinations) {
960
+ itemsToAdd.push(__assign(__assign({}, productToAdd.declinations[0]), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: productToAdd.slug, categories: productToAdd.categories }));
961
+ }
962
+ _c.label = 21;
963
+ case 21:
964
+ if (expeditionMethod === 'pickup' && !!cartAccessoriesDeliveryFee) {
965
+ itemsToDelete.push(cartAccessoriesDeliveryFee.sku);
966
+ }
967
+ return [3, 23];
968
+ case 22:
969
+ if (!!cartAccessoriesDeliveryFee) {
970
+ itemsToDelete.push(cartAccessoriesDeliveryFee.sku);
971
+ }
972
+ _c.label = 23;
973
+ case 23:
974
+ shouldApplyFees = !!isPro || totalPalletGrass >= 1;
975
+ if (!!!grassProduct) return [3, 45];
976
+ feesToAdd_1 = [];
977
+ orderDate_1 = expeditionDate;
978
+ pickupStoreId = '';
979
+ if (!!pickupStore && !!pickupStore.id) {
980
+ pickupStoreId = pickupStore.id;
981
+ }
982
+ else {
983
+ shipping_address_1 = cart.shipping_address;
984
+ if (!!shipping_address_1) {
985
+ pickupStore_1 = allStores.find(function (store) { return store.address.postal_code === shipping_address_1.address.postal_code; });
986
+ if (!!pickupStore_1 && !!pickupStore_1.id) {
987
+ pickupStoreId = pickupStore_1.id;
988
+ }
989
+ }
990
+ }
991
+ surchargesCommandesGazon = undefined;
992
+ surchargesCommandesGazonDebutFinSaison = undefined;
993
+ surchargesInstallationGazon = undefined;
994
+ surchargesInstallationGazonDebutFinSaison = undefined;
995
+ surchargesGazonPickupHorsFerme = undefined;
996
+ fraisSiCommandePasEnLigne = undefined;
997
+ _c.label = 24;
998
+ case 24:
999
+ _c.trys.push([24, 26, , 27]);
1000
+ return [4, fetchProduct('surcharges-commandes-gazon', locale, !!useFeeArray, true)];
1001
+ case 25:
1002
+ surchargesCommandesGazon = _c.sent();
1003
+ return [3, 27];
1004
+ case 26:
1005
+ e_2 = _c.sent();
1006
+ console.log('error on fetching product: ', e_2.toString());
1007
+ return [3, 27];
1008
+ case 27:
1009
+ _c.trys.push([27, 29, , 30]);
1010
+ return [4, fetchProduct('surcharges-commandes-gazon-debut-fin-saison', locale, !!useFeeArray, true)];
1011
+ case 28:
1012
+ surchargesCommandesGazonDebutFinSaison = _c.sent();
1013
+ return [3, 30];
1014
+ case 29:
1015
+ e_3 = _c.sent();
1016
+ console.log('error on fetching product: ', e_3.toString());
1017
+ return [3, 30];
1018
+ case 30:
1019
+ _c.trys.push([30, 32, , 33]);
1020
+ return [4, fetchProduct('surcharges-installation-gazon', locale, !!useFeeArray, true)];
1021
+ case 31:
1022
+ surchargesInstallationGazon = _c.sent();
1023
+ return [3, 33];
1024
+ case 32:
1025
+ e_4 = _c.sent();
1026
+ console.log('error on fetching product: ', e_4.toString());
1027
+ return [3, 33];
1028
+ case 33:
1029
+ _c.trys.push([33, 35, , 36]);
1030
+ return [4, fetchProduct('surcharges-installation-gazon-debut-fin-saison', locale, useFeeArray, true)];
1031
+ case 34:
1032
+ surchargesInstallationGazonDebutFinSaison = _c.sent();
1033
+ return [3, 36];
1034
+ case 35:
1035
+ e_5 = _c.sent();
1036
+ console.log('error on fetching product: ', e_5.toString());
1037
+ return [3, 36];
1038
+ case 36:
1039
+ _c.trys.push([36, 38, , 39]);
1040
+ return [4, fetchProduct('surcharge-gazon-ramassage-hors-ferme', locale, !!useFeeArray, true)];
1041
+ case 37:
1042
+ surchargesGazonPickupHorsFerme = _c.sent();
1043
+ return [3, 39];
1044
+ case 38:
1045
+ e_6 = _c.sent();
1046
+ console.log('error on fetching product: ', e_6.toString());
1047
+ return [3, 39];
1048
+ case 39:
1049
+ _c.trys.push([39, 43, , 44]);
1050
+ if (!(cartType === 'online' || expeditionMethod === 'pickup')) return [3, 40];
1051
+ _a = undefined;
1052
+ return [3, 42];
1053
+ case 40: return [4, fetchProduct('frais-commande-gazon-pas-en-ligne', locale, !!useFeeArray, true)];
1054
+ case 41:
1055
+ _a = _c.sent();
1056
+ _c.label = 42;
1057
+ case 42:
1058
+ fraisSiCommandePasEnLigne = _a;
1059
+ return [3, 44];
1060
+ case 43:
1061
+ e_7 = _c.sent();
1062
+ console.log('error on fetching product: ', e_7.toString());
1063
+ return [3, 44];
1064
+ case 44:
1065
+ if (!!orderDate_1) {
1066
+ addSku_1 = function (sku, product) {
1067
+ var decli = product.declinations.find(function (i) { return i.sku === sku; });
1068
+ if (!!decli) {
1069
+ feesToAdd_1.push(__assign(__assign({}, decli), { qte: !!product.slug.includes('installation') && grassProduct.qte < minQteInstall
1070
+ ? minQteInstall
1071
+ : (!!product.slug.includes('commandes-gazon') ||
1072
+ ['frais-commande-gazon-pas-en-ligne', 'surcharge-gazon-ramassage-hors-ferme'].includes(product.slug)) &&
1073
+ grassProduct.qte < minQteGrassOrder
1074
+ ? minQteGrassOrder
1075
+ : grassProduct.qte, is_upsell_of_sku: 'summary', parent_slug: product.slug, other_units: decli.other_units }));
1076
+ }
1077
+ };
1078
+ allOrderFees = [];
1079
+ allInstallationFees = [];
1080
+ if (!!shouldApplyFees) {
1081
+ if (!!surchargesCommandesGazon) {
1082
+ if (orderDate_1.getDay() === 6) {
1083
+ if (expeditionMethod === 'delivery') {
1084
+ allOrderFees.push(['000010400', surchargesCommandesGazon]);
1085
+ }
1086
+ else {
1087
+ if (!!!data_2.grassFarmStores.includes(pickupStoreId)) {
1088
+ allOrderFees.push(['000010400', surchargesCommandesGazon]);
1089
+ }
1090
+ }
1091
+ }
1092
+ if ((0, moment_1.default)(orderDate_1).day() === 0 ||
1093
+ (0, data_1.getHolidays)().some(function (date) { return (0, moment_1.default)(date).isSame((0, moment_1.default)(orderDate_1), 'day'); })) {
1094
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010850', surchargesCommandesGazon]], false);
1095
+ }
1096
+ cd = (0, data_1.getContructionHolidays)();
1097
+ if ((0, moment_1.default)(orderDate_1).isBetween((0, moment_1.default)(cd[0]), (0, moment_1.default)(cd[1]), 'day', '[]')) {
1098
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010860', surchargesCommandesGazon]], false);
1099
+ }
1100
+ summer = (0, data_1.getSummerDate)();
1101
+ if ((0, moment_1.default)(orderDate_1).isBetween((0, moment_1.default)(summer[0]), (0, moment_1.default)(summer[1]), 'day', '[]')) {
1102
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010300', surchargesCommandesGazon]], false);
1103
+ }
1104
+ }
1105
+ shouldAddGrassSeasonFee = !!surchargesCommandesGazonDebutFinSaison;
1106
+ shouldAddInstallSeasonFee = !!cartContainsInstallation && !!isPro && !!surchargesInstallationGazonDebutFinSaison;
1107
+ if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-03-01"), "".concat((0, moment_1.default)().format('YYYY'), "-04-30"), 'day', '[]')) {
1108
+ if (shouldAddGrassSeasonFee)
1109
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010100', surchargesCommandesGazonDebutFinSaison]], false);
1110
+ if (shouldAddInstallSeasonFee)
1111
+ allInstallationFees.push(['000010600', surchargesInstallationGazonDebutFinSaison]);
1112
+ }
1113
+ if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-10-15"), "".concat((0, moment_1.default)().format('YYYY'), "-10-31"), 'day', '[]')) {
1114
+ if (shouldAddGrassSeasonFee)
1115
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010840', surchargesCommandesGazonDebutFinSaison]], false);
1116
+ if (shouldAddInstallSeasonFee)
1117
+ allInstallationFees.push(['000010940', surchargesInstallationGazonDebutFinSaison]);
1118
+ }
1119
+ if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-11-01"), "".concat((0, moment_1.default)().format('YYYY'), "-11-14"), 'day', '[]')) {
1120
+ if (shouldAddGrassSeasonFee)
1121
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010700', surchargesCommandesGazonDebutFinSaison]], false);
1122
+ if (shouldAddInstallSeasonFee)
1123
+ allInstallationFees.push(['000010800', surchargesInstallationGazonDebutFinSaison]);
1124
+ }
1125
+ if ((0, moment_1.default)(orderDate_1).isBetween("".concat((0, moment_1.default)().format('YYYY'), "-11-15"), "".concat((0, moment_1.default)().format('YYYY'), "-12-31"), 'day', '[]')) {
1126
+ if (shouldAddGrassSeasonFee)
1127
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000010900', surchargesCommandesGazonDebutFinSaison]], false);
1128
+ if (shouldAddInstallSeasonFee)
1129
+ allInstallationFees.push(['000010950', surchargesInstallationGazonDebutFinSaison]);
1130
+ }
1131
+ if (expeditionMethod === 'pickup' && !!surchargesGazonPickupHorsFerme) {
1132
+ if (!!!data_2.grassFarmStores.includes(pickupStoreId)) {
1133
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['000012500', surchargesGazonPickupHorsFerme]], false);
1134
+ }
1135
+ }
1136
+ }
1137
+ if (!!surchargesInstallationGazon &&
1138
+ !!cartContainsInstallation &&
1139
+ ((0, moment_1.default)(orderDate_1).day() === 0 ||
1140
+ (0, data_1.getHolidays)().some(function (date) { return (0, moment_1.default)(date).isSame((0, moment_1.default)(orderDate_1), 'day'); }))) {
1141
+ allInstallationFees.push(['000010750', surchargesInstallationGazon]);
1142
+ }
1143
+ if (!!fraisSiCommandePasEnLigne && !!!cartContainsInstallation && !!isPro) {
1144
+ allOrderFees = __spreadArray(__spreadArray([], allOrderFees, true), [['FRSGAZON', fraisSiCommandePasEnLigne]], false);
1145
+ }
1146
+ allOrderFees.map(function (fee) {
1147
+ addSku_1(fee[0], fee[1]);
1148
+ });
1149
+ allInstallationFees.map(function (fee) {
1150
+ addSku_1(fee[0], fee[1]);
1151
+ });
1152
+ }
1153
+ itemsToAdd = __spreadArray(__spreadArray([], itemsToAdd, true), feesToAdd_1, true);
1154
+ _c.label = 45;
1155
+ case 45:
1156
+ if (!!grassProduct || !!isMixed) {
1157
+ cart.items.forEach(function (i) {
1158
+ if (!!i.parent_slug &&
1159
+ [
1160
+ 'surcharges-commandes-gazon',
1161
+ 'surcharges-commandes-gazon-debut-fin-saison',
1162
+ 'surcharges-installation-gazon',
1163
+ 'surcharges-installation-gazon-debut-fin-saison',
1164
+ 'surcharge-gazon-ramassage-hors-ferme',
1165
+ 'frais-commande-gazon-pas-en-ligne'
1166
+ ].includes(i.parent_slug)) {
1167
+ itemsToDelete.push(i.sku);
1168
+ }
1169
+ });
1170
+ }
1171
+ if (!(!!concreteOrder && !!!cartContainsSample && !!!cartContainsOnlyAccessories)) return [3, 53];
1172
+ return [4, fetchProduct('frais-preparation-general-beton', locale, !!useFeeArray, true)];
1173
+ case 46:
1174
+ fraisPreparationGeneralBeton = _c.sent();
1175
+ onlyConcretePalQty = (0, exports.getPalletQty)(cart.items.filter(function (i) { return (0, products_2.checkIfProductIsOfType)(i, 'beton', true); }));
1176
+ if (!!fraisPreparationGeneralBeton && onlyConcretePalQty >= 1) {
1177
+ decli_2 = fraisPreparationGeneralBeton.declinations.find(function (i) { return i.sku === 'FP-1'; });
1178
+ if (!!decli_2) {
1179
+ itemsToAdd.push(__assign(__assign({}, decli_2), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: fraisPreparationGeneralBeton.slug, categories: fraisPreparationGeneralBeton.categories }));
1180
+ }
1181
+ }
1182
+ if (!(expeditionMethod !== 'pickup' && cartType !== 'online' && !!isPro)) return [3, 48];
1183
+ getFeeAmount = function (decli) {
1184
+ var percent = (0, toNumber_1.default)(decli.regular_price.amount);
1185
+ var amount = 0;
1186
+ for (var _i = 0, _a = cart.items; _i < _a.length; _i++) {
1187
+ var item = _a[_i];
1188
+ if (!!item.is_service)
1189
+ continue;
1190
+ if (!!customPriceList) {
1191
+ item = (0, g2_1.checkForCustomPriceEquivalent)(item, customPriceList);
1192
+ }
1193
+ var itemPrice = (0, products_3.getLowestPrice)(item).price.amount;
1194
+ amount += itemPrice * item.qte * percent;
1195
+ }
1196
+ return (0, round_1.default)(amount, 3);
1197
+ };
1198
+ return [4, fetchProduct('frais-commande-beton-pas-en-ligne', locale, !!useFeeArray, true)];
1199
+ case 47:
1200
+ feeProd = _c.sent();
1201
+ if (!!feeProd) {
1202
+ skuToAdd = (feeProd.declinations || []).find(function (d) { return d.sku === 'FRSBETON'; });
1203
+ if (!!skuToAdd) {
1204
+ itemsToAdd.push(__assign(__assign({}, skuToAdd), { qte: 1, parent_slug: feeProd.slug, is_upsell_of_sku: 'summary', regular_price: __assign(__assign({}, skuToAdd.regular_price), { amount: getFeeAmount(skuToAdd), price_type: (0, round_1.default)((0, toNumber_1.default)(skuToAdd.regular_price.amount) * 100, 2).toString() }), price_override: true, categories: feeProd.categories }));
1205
+ }
1206
+ }
1207
+ return [3, 49];
1208
+ case 48:
1209
+ if (cart.items.some(function (item) { return item.sku === 'FRSBETON'; })) {
1210
+ itemsToDelete.push('FRSBETON');
1211
+ }
1212
+ _c.label = 49;
1213
+ case 49:
1214
+ concreteItems = cart.items.filter(function (i) { return i.attributes[data_4.AttributesIdEnumGR.TYPE] && i.attributes[data_4.AttributesIdEnumGR.TYPE].includes('beton'); });
1215
+ numberOfIncompletePallets = 0;
1216
+ for (_i = 0, concreteItems_1 = concreteItems; _i < concreteItems_1.length; _i++) {
1217
+ item = concreteItems_1[_i];
1218
+ if (!!!item.other_units)
1219
+ continue;
1220
+ saleUnit = item.other_units.find(function (unit) { return unit.is_sale_unit; });
1221
+ palUnit = item.other_units.find(function (unit) { return unit.unit_slug === 'pal'; });
1222
+ if (!!!saleUnit || !!!saleUnit.fitting_unit || !!!palUnit || !!!palUnit.fitting_unit)
1223
+ continue;
1224
+ calculatedPal = saleUnit.fitting_unit * item.qte;
1225
+ rest = (0, round_1.default)(calculatedPal, 3) % (0, round_1.default)(palUnit.fitting_unit, 3);
1226
+ if (!!rest) {
1227
+ numberOfIncompletePallets++;
1228
+ }
1229
+ }
1230
+ if (!(numberOfIncompletePallets >= 4)) return [3, 51];
1231
+ return [4, fetchProduct('frais-preparation', locale, !!useFeeArray, true)];
1232
+ case 50:
1233
+ surchargesCommandesBeton = _c.sent();
1234
+ if (!!surchargesCommandesBeton) {
1235
+ decli_3 = surchargesCommandesBeton.declinations.find(function (i) { return i.sku === 'FP4'; });
1236
+ if (!!decli_3) {
1237
+ itemsToAdd.push(__assign(__assign({}, decli_3), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: surchargesCommandesBeton.slug, categories: surchargesCommandesBeton.categories }));
1238
+ }
1239
+ }
1240
+ return [3, 52];
1241
+ case 51:
1242
+ prepItem = cart.items.find(function (item) { return item.parent_slug === 'frais-preparation'; });
1243
+ if (!!prepItem) {
1244
+ itemsToDelete.push(prepItem.sku);
1245
+ }
1246
+ _c.label = 52;
1247
+ case 52: return [3, 54];
1248
+ case 53:
1249
+ if (cart.items.some(function (item) { return item.sku === 'FP-1'; })) {
1250
+ itemsToDelete.push('FP-1');
1251
+ }
1252
+ if (cart.items.some(function (item) { return item.sku === 'FRSBETON'; })) {
1253
+ itemsToDelete.push('FRSBETON');
1254
+ }
1255
+ _c.label = 54;
1256
+ case 54:
1257
+ isOutOfArea = false;
1258
+ if (!(expeditionMethod === 'delivery' && !!deliveryAddress)) return [3, 74];
1259
+ insideZones = undefined;
1260
+ _c.label = 55;
1261
+ case 55:
1262
+ _c.trys.push([55, 57, , 58]);
1263
+ return [4, getIfAddressIsInsideZones(deliveryAddress)];
1264
+ case 56:
1265
+ insideZones = _c.sent();
1266
+ return [3, 58];
1267
+ case 57:
1268
+ e_8 = _c.sent();
1269
+ console.log('error on fetching zones for address: ', e_8.toString());
1270
+ return [3, 58];
1271
+ case 58:
1272
+ if (!(!!insideZones && !!Array.isArray(insideZones))) return [3, 74];
1273
+ if (!(!!insideZones.length && insideZones.includes('zone-gr'))) return [3, 73];
1274
+ productInstallToAdd = void 0;
1275
+ if (!!!grassProduct) return [3, 62];
1276
+ if (!!!cartContainsInstallation) return [3, 60];
1277
+ return [4, fetchProduct('surcharges-installation-gazon', locale, !!useFeeArray, true)];
1278
+ case 59:
1279
+ _b = _c.sent();
1280
+ return [3, 61];
1281
+ case 60:
1282
+ _b = undefined;
1283
+ _c.label = 61;
1284
+ case 61:
1285
+ productInstallToAdd = _b;
1286
+ _c.label = 62;
1287
+ case 62: return [4, fetchProduct('surcharges-commandes-gazon', locale, !!useFeeArray, true)];
1288
+ case 63:
1289
+ productToAdd = _c.sent();
1290
+ if (insideZones.includes('zone-mtl')) {
1291
+ if (!!productToAdd) {
1292
+ mtl = productToAdd.declinations.find(function (i) { return i.sku === '170050000'; });
1293
+ if (!!mtl) {
1294
+ itemsToAdd.push(__assign(__assign({}, mtl), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1295
+ }
1296
+ }
1297
+ if (!!grassProduct && !!productInstallToAdd) {
1298
+ mtlInstall = productInstallToAdd.declinations.find(function (i) { return i.sku === '170055500'; });
1299
+ if (!!mtlInstall) {
1300
+ itemsToAdd.push(__assign(__assign({}, mtlInstall), { qte: (0, ceil_1.default)(totalPalletGrass / exports.installationFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-installation-gazon', categories: productInstallToAdd.categories }));
1301
+ }
1302
+ }
1303
+ }
1304
+ if (insideZones.includes('zone-ontario')) {
1305
+ if (!!productToAdd) {
1306
+ ontario = productToAdd.declinations.find(function (i) { return i.sku === '170000ONT'; });
1307
+ if (!!ontario) {
1308
+ itemsToAdd.push(__assign(__assign({}, ontario), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1309
+ }
1310
+ }
1311
+ if (!!grassProduct && !!productInstallToAdd) {
1312
+ ontarioInstall = productInstallToAdd.declinations.find(function (i) { return i.sku === '170033ONT'; });
1313
+ if (!!ontarioInstall) {
1314
+ itemsToAdd.push(__assign(__assign({}, ontarioInstall), { qte: (0, ceil_1.default)(totalPalletGrass / exports.installationFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-installation-gazon', categories: productInstallToAdd.categories }));
1315
+ }
1316
+ }
1317
+ }
1318
+ if (insideZones.includes('zone-ile-orleans')) {
1319
+ if (!!productToAdd) {
1320
+ ileOrleans = productToAdd.declinations.find(function (i) { return i.sku === '170000418'; });
1321
+ if (!!ileOrleans) {
1322
+ itemsToAdd.push(__assign(__assign({}, ileOrleans), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1323
+ }
1324
+ }
1325
+ }
1326
+ if (!!!cartContainsVrac) return [3, 72];
1327
+ if (!(insideZones.includes('zone-vrac') || insideZones.includes('zone-vrac-les-coteaux'))) return [3, 71];
1328
+ return [4, fetchProduct('frais-de-livraison-vrac', locale, !!useFeeArray, true)];
1329
+ case 64:
1330
+ deliveryTruckProduct = _c.sent();
1331
+ storeIDToCheck = insideZones.includes('zone-vrac') ? 'sainte-julie-nobel' : 'default';
1332
+ storeAddress = getStoreAddressByID(allStores, storeIDToCheck);
1333
+ if (!(!!availableVracStoreIDs && !availableVracStoreIDs.includes(storeIDToCheck))) return [3, 65];
1334
+ isOutOfArea = true;
1335
+ return [3, 70];
1336
+ case 65:
1337
+ if (!(!!deliveryTruckProduct && !!storeAddress)) return [3, 70];
1338
+ distance = null;
1339
+ _c.label = 66;
1340
+ case 66:
1341
+ _c.trys.push([66, 68, , 69]);
1342
+ return [4, getDistanceFromAddress(storeAddress, deliveryAddress)];
1343
+ case 67:
1344
+ distance = _c.sent();
1345
+ return [3, 69];
1346
+ case 68:
1347
+ _1 = _c.sent();
1348
+ console.log(_1);
1349
+ return [3, 69];
1350
+ case 69:
1351
+ if (distance === null) {
1352
+ isOutOfArea = true;
1353
+ }
1354
+ else {
1355
+ itemsToAdd = __spreadArray(__spreadArray([], itemsToAdd, true), (0, exports.calculateShippingForVrac)(distance, cart.items, deliveryTruckProduct, itemsToAdd, expeditionDate), true);
1356
+ }
1357
+ _c.label = 70;
1358
+ case 70: return [3, 72];
1359
+ case 71:
1360
+ isOutOfArea = true;
1361
+ _c.label = 72;
1362
+ case 72: return [3, 74];
1363
+ case 73:
1364
+ isOutOfArea = true;
1365
+ _c.label = 74;
1366
+ case 74:
1367
+ cart.items.forEach(function (i) {
1368
+ if (!!i.parent_slug && ['frais-de-livraison-vrac', 'surcharges-commandes-gazon'].includes(i.parent_slug)) {
1369
+ itemsToDelete.push(i.sku);
1370
+ }
1371
+ });
1372
+ if (!!equipmentPickupOnSite) {
1373
+ }
1374
+ degelFeeSku = '170000018';
1375
+ if (!(!!isPro &&
1376
+ expeditionMethod === 'delivery' &&
1377
+ !!!cartContainsSample &&
1378
+ !!!cartContainsVrac &&
1379
+ !!expeditionDate &&
1380
+ !!isDegel(expeditionDate))) return [3, 76];
1381
+ return [4, fetchProduct('frais-livraison-periode-degel', locale, !!useFeeArray, true)];
1382
+ case 75:
1383
+ degelFeeProd = _c.sent();
1384
+ if (!!degelFeeProd) {
1385
+ degelFeeDecli = degelFeeProd.declinations.find(function (d) { return d.sku === degelFeeSku; });
1386
+ if (!!degelFeeDecli) {
1387
+ itemsToAdd.push(__assign(__assign({}, degelFeeDecli), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: degelFeeProd.slug, categories: degelFeeProd.categories }));
1388
+ }
1389
+ }
1390
+ return [3, 77];
1391
+ case 76:
1392
+ if (!!cart.items.some(function (i) { return i.sku === degelFeeSku; })) {
1393
+ itemsToDelete.push(degelFeeSku);
1394
+ }
1395
+ _c.label = 77;
1396
+ case 77:
1397
+ itemsToDelete = itemsToDelete.filter(function (i) { return !itemsToAdd.map(function (add) { return add.sku; }).includes(i); });
1398
+ itemsToAdd = itemsToAdd
1399
+ .map(function (item) {
1400
+ var cartItem = cart.items.find(function (i) { return i.sku === item.sku; });
1401
+ if (!!cartItem) {
1402
+ if (cartItem.qte !== item.qte) {
1403
+ itemsToUpdate.push({ sku: item.sku, qte: item.qte });
1404
+ return;
1405
+ }
1406
+ else {
1407
+ return;
1408
+ }
1409
+ }
1410
+ else {
1411
+ if (!!item.parent_slug &&
1412
+ (0, products_2.shouldHideItemIfRegPriceIs0)(item, item.parent_slug, !!item.is_upsell_of_sku && item.parent_slug.includes('installation'))) {
1413
+ return;
1414
+ }
1415
+ }
1416
+ return __assign({}, item);
1417
+ })
1418
+ .filter(function (i) { return !!i; });
1419
+ return [2, {
1420
+ newCart: __assign(__assign({}, cart), { shipping_payload: newShippingPayload }),
1421
+ itemsToDelete: itemsToDelete,
1422
+ itemsToUpdate: itemsToUpdate,
1423
+ itemsToAdd: itemsToAdd,
1424
+ totalPallet: totalPallet,
1425
+ isOutOfArea: isOutOfArea
1426
+ }];
1427
+ }
1428
+ });
1429
+ }); };
1430
+ exports.applyFeesToCart = applyFeesToCart;
1431
+ var checkIfShouldRemoveSampleShippingFee = function (fetchProduct, cart, locale, useFeeArray) { return __awaiter(void 0, void 0, void 0, function () {
1432
+ var currentItems, currentItemsChecked, _i, currentItems_2, item, parentProd, brand, isTena, excludedGrass, hasGrassType, isExcludedGrass, isGrass, valuesToCheck, allIncludedBrandsNoTena, allGrass, added;
1433
+ return __generator(this, function (_a) {
1434
+ switch (_a.label) {
1435
+ case 0:
1436
+ if (!!!cart.items)
1437
+ return [2, false];
1438
+ currentItems = cart.items.filter(function (i) { return i.is_sample; });
1439
+ currentItemsChecked = [];
1440
+ _i = 0, currentItems_2 = currentItems;
1441
+ _a.label = 1;
1442
+ case 1:
1443
+ if (!(_i < currentItems_2.length)) return [3, 4];
1444
+ item = currentItems_2[_i];
1445
+ if (!!!item.parent_slug)
1446
+ return [3, 3];
1447
+ return [4, fetchProduct(item.parent_slug, locale, !!useFeeArray, true)];
1448
+ case 2:
1449
+ parentProd = _a.sent();
1450
+ if (!!!parentProd)
1451
+ return [3, 3];
1452
+ brand = parentProd.brand;
1453
+ isTena = !!item.attributes &&
1454
+ !!item.attributes[data_4.AttributesIdEnumGR.FAMILY] &&
1455
+ !!item.attributes[data_4.AttributesIdEnumGR.FAMILY].includes('tena');
1456
+ excludedGrass = ["".concat(products_4.kentucky, "-e"), "".concat(products_4.prestige, "-e")];
1457
+ hasGrassType = (0, products_2.checkIfProductIsOfType)(item, 'gazon');
1458
+ isExcludedGrass = excludedGrass.includes(item.sku);
1459
+ isGrass = !!hasGrassType && !!!isExcludedGrass;
1460
+ valuesToCheck = {
1461
+ brand: !!brand ? brand : '',
1462
+ isTena: isTena,
1463
+ isGrass: isGrass
1464
+ };
1465
+ currentItemsChecked.push(valuesToCheck);
1466
+ _a.label = 3;
1467
+ case 3:
1468
+ _i++;
1469
+ return [3, 1];
1470
+ case 4:
1471
+ if (!!currentItemsChecked.length) {
1472
+ allIncludedBrandsNoTena = currentItemsChecked.filter(function (item) { return !!item.brand && !!data_2.includedFreeShippingBrands.includes(item.brand) && !!!item.isTena; });
1473
+ allGrass = currentItemsChecked.filter(function (item) { return !!item.isGrass; });
1474
+ if (currentItems.length === allIncludedBrandsNoTena.length || currentItems.length === allGrass.length) {
1475
+ return [2, true];
1476
+ }
1477
+ else {
1478
+ added = allIncludedBrandsNoTena.length + allGrass.length;
1479
+ if (added === currentItems.length) {
1480
+ return [2, true];
1481
+ }
1482
+ }
1483
+ }
1484
+ return [2, false];
1485
+ }
1486
+ });
1487
+ }); };
1488
+ exports.checkIfShouldRemoveSampleShippingFee = checkIfShouldRemoveSampleShippingFee;
1489
+ var calculateShippingForVrac = function (distance, cartItems, deliveryTruckProduct, currentItemsToAdd, deliveryDate) {
1490
+ if (distance === void 0) { distance = 0; }
1491
+ var itemsToAdd = __spreadArray([], currentItemsToAdd, true);
1492
+ var allVracItems = cartItems.filter(function (i) { return (0, products_2.checkIfProductIsOfType)(i, 'vrac'); });
1493
+ var _loop_1 = function (vracItem) {
1494
+ var totalTons = vracItem.qte;
1495
+ var isInDegelPeriod = !!isDegel(deliveryDate);
1496
+ var volumeTons = [
1497
+ {
1498
+ min: 1,
1499
+ max: 4
1500
+ },
1501
+ {
1502
+ min: 4,
1503
+ max: isInDegelPeriod ? 11 : 15
1504
+ },
1505
+ {
1506
+ min: isInDegelPeriod ? 11 : 15,
1507
+ max: isInDegelPeriod ? 16 : 20
1508
+ },
1509
+ {
1510
+ min: isInDegelPeriod ? 16 : 20,
1511
+ max: isInDegelPeriod ? 19 : 24
1512
+ },
1513
+ {
1514
+ min: isInDegelPeriod ? 19 : 24,
1515
+ max: isInDegelPeriod ? 24 : 30
1516
+ }
1517
+ ];
1518
+ var checkTons = function (tons) {
1519
+ var skuToAdd = '';
1520
+ switch (true) {
1521
+ case tons <= volumeTons[0].max:
1522
+ switch (true) {
1523
+ case distance >= 0 && distance < 15:
1524
+ skuToAdd = '170000615';
1525
+ break;
1526
+ case distance >= 15 && distance < 30:
1527
+ skuToAdd = '170000630';
1528
+ break;
1529
+ case distance >= 30:
1530
+ skuToAdd = '170000660';
1531
+ break;
1532
+ }
1533
+ tons = -1;
1534
+ break;
1535
+ case tons > volumeTons[1].min && tons <= volumeTons[1].max:
1536
+ switch (true) {
1537
+ case distance >= 0 && distance < 15:
1538
+ skuToAdd = '170001015';
1539
+ break;
1540
+ case distance >= 15 && distance < 30:
1541
+ skuToAdd = '170001030';
1542
+ break;
1543
+ case distance >= 30:
1544
+ skuToAdd = '170001060';
1545
+ break;
1546
+ }
1547
+ tons = -1;
1548
+ break;
1549
+ case tons > volumeTons[2].min && tons <= volumeTons[2].max:
1550
+ switch (true) {
1551
+ case distance >= 0 && distance < 15:
1552
+ skuToAdd = '170001215';
1553
+ break;
1554
+ case distance >= 15 && distance < 30:
1555
+ skuToAdd = '170001230';
1556
+ break;
1557
+ case distance >= 30:
1558
+ skuToAdd = '170001260';
1559
+ break;
1560
+ }
1561
+ tons = -1;
1562
+ break;
1563
+ case tons > volumeTons[3].min && tons <= volumeTons[3].max:
1564
+ switch (true) {
1565
+ case distance >= 0 && distance < 15:
1566
+ skuToAdd = '170002015';
1567
+ break;
1568
+ case distance >= 15 && distance < 30:
1569
+ skuToAdd = '170002030';
1570
+ break;
1571
+ case distance >= 30:
1572
+ skuToAdd = '170002060';
1573
+ break;
1574
+ }
1575
+ tons = -1;
1576
+ break;
1577
+ case tons > volumeTons[4].min:
1578
+ switch (true) {
1579
+ case distance >= 0 && distance < 15:
1580
+ skuToAdd = '170003015';
1581
+ break;
1582
+ case distance >= 15 && distance < 30:
1583
+ skuToAdd = '170003030';
1584
+ break;
1585
+ case distance >= 30:
1586
+ skuToAdd = '170003060';
1587
+ break;
1588
+ }
1589
+ tons = tons - volumeTons[4].max;
1590
+ break;
1591
+ default:
1592
+ tons = -1;
1593
+ }
1594
+ var decliToAdd = deliveryTruckProduct.declinations.find(function (d) { return d.sku === skuToAdd; });
1595
+ if (!!decliToAdd) {
1596
+ if (!!itemsToAdd.find(function (item) { return item.sku === decliToAdd.sku; })) {
1597
+ var index = itemsToAdd.findIndex(function (item) { return item.sku === decliToAdd.sku; });
1598
+ itemsToAdd[index] = __assign(__assign({}, itemsToAdd[index]), { qte: itemsToAdd[index].qte + 1 });
1599
+ }
1600
+ else {
1601
+ itemsToAdd.push(__assign(__assign({}, decliToAdd), { parent_slug: 'frais-de-livraison-vrac', qte: 1, is_upsell_of_sku: 'summary', categories: deliveryTruckProduct.categories }));
1602
+ }
1603
+ }
1604
+ if (tons > 0) {
1605
+ checkTons(tons);
1606
+ }
1607
+ };
1608
+ checkTons(totalTons);
1609
+ };
1610
+ for (var _i = 0, allVracItems_1 = allVracItems; _i < allVracItems_1.length; _i++) {
1611
+ var vracItem = allVracItems_1[_i];
1612
+ _loop_1(vracItem);
1613
+ }
1614
+ return itemsToAdd;
1615
+ };
1616
+ exports.calculateShippingForVrac = calculateShippingForVrac;
1617
+ var getStoresForVracProdShipping = function (inventoryItem) {
1618
+ var availability = {};
1619
+ var _loop_2 = function (vracStore) {
1620
+ var sameInInventory = inventoryItem.inventories.find(function (i) { return i.store_id == vracStore; });
1621
+ availability[vracStore] = !!sameInInventory && !!!sameInInventory.unavailable_in_store;
1622
+ };
1623
+ for (var _i = 0, vracShippingStores_1 = data_2.vracShippingStores; _i < vracShippingStores_1.length; _i++) {
1624
+ var vracStore = vracShippingStores_1[_i];
1625
+ _loop_2(vracStore);
1626
+ }
1627
+ return availability;
1628
+ };
1629
+ exports.getStoresForVracProdShipping = getStoresForVracProdShipping;
1630
+ var getStoreAddressByID = function (allStores, storeID) {
1631
+ var sameStore = allStores.find(function (s) { return s.id == storeID; });
1632
+ return !!sameStore ? sameStore.address : undefined;
1633
+ };
1634
+ var checkIfCartExpired = function (cartData, grassProduct, concreteOrder, isPro, blocked_shipping_dates, vracType, chosenPaymentType) {
1635
+ var isPOS = Cart_1.CartTypeEnum.WEB != cartData.cart_type;
1636
+ var isSample = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.SAMPLE, cartData);
1637
+ var isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
1638
+ var selected_date = !!cartData.shipping_payload && !!cartData.shipping_payload.delivery_or_pickup_date
1639
+ ? (0, data_3.formatDate)(cartData.shipping_payload.delivery_or_pickup_date)
1640
+ : undefined;
1641
+ var noDeliveryDateIsNormal = (0, exports.checkIfNoDeliveryDateIsNormal)(cartData, concreteOrder) ||
1642
+ (!!chosenPaymentType && ['depot'].includes(chosenPaymentType));
1643
+ if (!!noDeliveryDateIsNormal) {
1644
+ return false;
1645
+ }
1646
+ else if (!!!selected_date) {
1647
+ return true;
1648
+ }
1649
+ var now = (0, moment_1.default)().toDate();
1650
+ var updated_last = !!cartData.shipping_payload && !!cartData.shipping_payload.updated_at
1651
+ ? (0, data_3.formatDate)(cartData.shipping_payload.updated_at)
1652
+ : (0, moment_1.default)().toDate();
1653
+ var time = !!cartData.shipping_payload && !!cartData.shipping_payload.delivery_period
1654
+ ? cartData.shipping_payload.delivery_period
1655
+ : 'PM';
1656
+ var minDates = (0, exports.getMinDatePicker)(cartData, grassProduct, concreteOrder, !!cartData.is_pickup ? 'pickup' : 'delivery', !!isPro, updated_last, blocked_shipping_dates, vracType, isPOS);
1657
+ var currentMinDate = !!cartData.is_pickup ? minDates.min_pickup : minDates.min_delivery;
1658
+ var ok_hours = (0, exports.getAvailableHours)(currentMinDate, selected_date, grassProduct, concreteOrder, (!!cartData.is_pickup ? 'pickup' : 'delivery'), time, isPro, isSample, isAccessoriesOnly, updated_last);
1659
+ return (!!updated_last &&
1660
+ (((0, moment_1.default)(selected_date).isSameOrBefore(now, 'day') && !!!(0, moment_1.default)(currentMinDate).isSame(now, 'day')) ||
1661
+ (0, moment_1.default)(now).isAfter(updated_last, 'day') ||
1662
+ (0, moment_1.default)(currentMinDate).isAfter(selected_date, 'day') ||
1663
+ (updated_last.getHours() < 10 &&
1664
+ now.getHours() >= 10 &&
1665
+ time === 'AM' &&
1666
+ !!ok_hours.deliveryTimes.every(function (d) { return d.value == 'PM'; }))));
1667
+ };
1668
+ exports.checkIfCartExpired = checkIfCartExpired;
1669
+ var checkIfNoDeliveryDateIsNormal = function (cartData, concreteOrder, checkForInputShown) {
1670
+ var isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
1671
+ var isSample = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.SAMPLE, cartData);
1672
+ return ((!!!checkForInputShown && !!cartData.shipping_payload && !!cartData.shipping_payload.isOutOfArea) ||
1673
+ (!!concreteOrder && concreteOrder.type !== 'green') ||
1674
+ ((!!isAccessoriesOnly || !!isSample) && !!!cartData.is_pickup));
1675
+ };
1676
+ exports.checkIfNoDeliveryDateIsNormal = checkIfNoDeliveryDateIsNormal;
1677
1677
  //# sourceMappingURL=expedition.js.map