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