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
package/dist/utils/discount.js
CHANGED
|
@@ -1,935 +1,935 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getPaymentIncentiveDiscount = exports.getPaymentIncentiveDiscountInfo = exports.getAfterTaxesPromoInCart = exports.getAfterTaxesPromosTotalAmount = exports.checkIfCouldApplyIncentivePromo = exports.getOnlyServicesAndFeesSubtotal = exports.getStandardCartPromoFromDiscount = exports.applyDiscountToCart = exports.getItemCategorySlugArray = exports.getResultAppliedDiscountSkus = exports.getSkuArrayForPromo = exports.applyDiscountToPrice = exports.applyDiscountRulesOnProduct = exports.getNewDiscountPriceFromTierPricing = exports.applyTierPricing = exports.getTierPricingToApply = exports.checkPromoCodeEligibility = exports.getCartPromoType = exports.checkAttributes = exports.getResultRuleDetail = exports.shouldApplyRuleToDeclination = exports.getAppliedAmountsForSubtotalPromosOnCart = exports.getCartPromosByAppliesTo = exports.getSubtotalWithoutProductPromos = exports.isPromoAPercentage = exports.shouldCheckPromoCode = exports.getCartPromo = void 0;
|
|
18
|
-
const IDiscountRule_1 = require("../Interfaces/Rules/IDiscountRule");
|
|
19
|
-
const Cart_1 = require("../Interfaces/Cart");
|
|
20
|
-
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
21
|
-
const round_1 = __importDefault(require("lodash/round"));
|
|
22
|
-
const sumBy_1 = __importDefault(require("lodash/sumBy"));
|
|
23
|
-
const toNumber_1 = __importDefault(require("lodash/toNumber"));
|
|
24
|
-
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
25
|
-
const locale_1 = require("./locale");
|
|
26
|
-
const currency_1 = require("./currency");
|
|
27
|
-
const moment_1 = __importDefault(require("moment"));
|
|
28
|
-
const data_1 = require("./data");
|
|
29
|
-
const products_1 = require("./products");
|
|
30
|
-
const cart_1 = require("../rules/GR/utils/cart");
|
|
31
|
-
const cart_2 = require("../rules/GR/interfaces/cart");
|
|
32
|
-
const object_1 = require("./object");
|
|
33
|
-
const data_2 = require("../rules/GR/constants/data");
|
|
34
|
-
const g2_1 = require("../rules/GR/utils/g2");
|
|
35
|
-
const getCartPromo = (cartData) => {
|
|
36
|
-
if (!!!cartData.cart_promo_applied && !!!cartData.cart_promos_applied)
|
|
37
|
-
return;
|
|
38
|
-
return !!cartData.cart_promo_applied
|
|
39
|
-
? [cartData.cart_promo_applied]
|
|
40
|
-
: !!cartData.cart_promos_applied
|
|
41
|
-
? cartData.cart_promos_applied
|
|
42
|
-
: [];
|
|
43
|
-
};
|
|
44
|
-
exports.getCartPromo = getCartPromo;
|
|
45
|
-
const shouldCheckPromoCode = (cartData) => {
|
|
46
|
-
return ((!!cartData.cart_promos_applied && !!cartData.cart_promos_applied.some((p) => p.promo_code)) ||
|
|
47
|
-
(!!cartData.cart_promo_applied && !!cartData.cart_promo_applied.promo_code));
|
|
48
|
-
};
|
|
49
|
-
exports.shouldCheckPromoCode = shouldCheckPromoCode;
|
|
50
|
-
const isPromoAPercentage = (promo, options = {}) => {
|
|
51
|
-
const promoPercentOptions = [
|
|
52
|
-
IDiscountRule_1.ResultActionEnum.PERCENT,
|
|
53
|
-
IDiscountRule_1.ResultActionEnum.PERCENT_CATEGORY,
|
|
54
|
-
IDiscountRule_1.ResultActionEnum.PERCENT_SKU
|
|
55
|
-
];
|
|
56
|
-
if (options.includePaymentIncentiveInCheck)
|
|
57
|
-
promoPercentOptions.push(IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES);
|
|
58
|
-
let propertyToCheck = (0, object_1.recursiveCheckObject)(promo, 'result.action') || (0, object_1.recursiveCheckObject)(promo, 'amount_unit');
|
|
59
|
-
if (!!!propertyToCheck && options.defaultToPercent)
|
|
60
|
-
propertyToCheck = IDiscountRule_1.ResultActionEnum.PERCENT;
|
|
61
|
-
return !!propertyToCheck && promoPercentOptions.includes(propertyToCheck);
|
|
62
|
-
};
|
|
63
|
-
exports.isPromoAPercentage = isPromoAPercentage;
|
|
64
|
-
const getSubtotalWithoutProductPromos = (cartData, itemPromos) => {
|
|
65
|
-
const currentSubtotal = cartData.subtotalWithoutPromotions || cartData.subtotal;
|
|
66
|
-
let allProductSubtotalAmounts = (0, sumBy_1.default)(itemPromos, (i) => !!(0, data_1.getPromoTotalAmount)(cartData.items, i, 'number')
|
|
67
|
-
? (0, data_1.getPromoTotalAmount)(cartData.items, i, 'number')
|
|
68
|
-
: 0);
|
|
69
|
-
return currentSubtotal - allProductSubtotalAmounts;
|
|
70
|
-
};
|
|
71
|
-
exports.getSubtotalWithoutProductPromos = getSubtotalWithoutProductPromos;
|
|
72
|
-
const getCartPromosByAppliesTo = (cartData) => {
|
|
73
|
-
const appliedPromos = (0, exports.getCartPromo)(cartData) || [];
|
|
74
|
-
let subtotalPromos = appliedPromos.filter((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.SUBTOTAL);
|
|
75
|
-
let itemPromos = appliedPromos.filter((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.PRODUCT);
|
|
76
|
-
let afterTaxesPromos = appliedPromos.filter((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
|
|
77
|
-
return {
|
|
78
|
-
subtotal: subtotalPromos,
|
|
79
|
-
items: itemPromos,
|
|
80
|
-
afterTaxes: afterTaxesPromos
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
exports.getCartPromosByAppliesTo = getCartPromosByAppliesTo;
|
|
84
|
-
const getAppliedAmountsForSubtotalPromosOnCart = (cartData) => {
|
|
85
|
-
const activePromos = (0, exports.getCartPromosByAppliesTo)(cartData);
|
|
86
|
-
let currentSubtotal = (0, exports.getSubtotalWithoutProductPromos)(cartData, activePromos.items);
|
|
87
|
-
let promoAmounts = {};
|
|
88
|
-
for (let promo of activePromos.subtotal.filter((p) => !!p.discount_id)) {
|
|
89
|
-
if (!!!promo.amount_removed)
|
|
90
|
-
continue;
|
|
91
|
-
let amountRemoved = promo.amount_removed;
|
|
92
|
-
const serviceAndFeesTotal = (0, exports.getOnlyServicesAndFeesSubtotal)(cartData, activePromos.items);
|
|
93
|
-
if ((0, exports.isPromoAPercentage)(promo, { defaultToPercent: true })) {
|
|
94
|
-
if (!!promo.exclude_services_and_fees) {
|
|
95
|
-
amountRemoved = (0, round_1.default)((promo.amount_removed / 100) * (currentSubtotal - serviceAndFeesTotal), 3);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
amountRemoved = (0, round_1.default)((promo.amount_removed / 100) * currentSubtotal, 3);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
promoAmounts[promo.discount_id] = amountRemoved;
|
|
102
|
-
currentSubtotal -= amountRemoved;
|
|
103
|
-
}
|
|
104
|
-
return promoAmounts;
|
|
105
|
-
};
|
|
106
|
-
exports.getAppliedAmountsForSubtotalPromosOnCart = getAppliedAmountsForSubtotalPromosOnCart;
|
|
107
|
-
const shouldApplyRuleToDeclination = (discount_rule, declination, parentSlug) => {
|
|
108
|
-
if (!!!discount_rule.rules || !!!discount_rule.rules.length)
|
|
109
|
-
return true;
|
|
110
|
-
const currentDiscountMap = discount_rule.rules.map((rule) => {
|
|
111
|
-
const todayDate = (0, moment_1.default)().format('YYYY-MM-DD');
|
|
112
|
-
switch (rule.field) {
|
|
113
|
-
case IDiscountRule_1.RuleFieldEnum.PRODUCT_PRICE:
|
|
114
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
115
|
-
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, declination.price.regular.amount)];
|
|
116
|
-
}));
|
|
117
|
-
case IDiscountRule_1.RuleFieldEnum.SKU:
|
|
118
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
119
|
-
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, declination.sku)];
|
|
120
|
-
}));
|
|
121
|
-
case IDiscountRule_1.RuleFieldEnum.DECLINATION:
|
|
122
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
123
|
-
return [rule.condition, declination.sku === ruleDetail.value[0]];
|
|
124
|
-
}));
|
|
125
|
-
case IDiscountRule_1.RuleFieldEnum.PRODUCT:
|
|
126
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
127
|
-
return [rule.condition, !!!parentSlug || (0, exports.getResultRuleDetail)(ruleDetail, parentSlug)];
|
|
128
|
-
}));
|
|
129
|
-
case IDiscountRule_1.RuleFieldEnum.DATE:
|
|
130
|
-
case IDiscountRule_1.RuleFieldEnum.WEEKDAY:
|
|
131
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
132
|
-
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, (0, moment_1.default)(todayDate).toDate())];
|
|
133
|
-
}));
|
|
134
|
-
case IDiscountRule_1.RuleFieldEnum.ATTRIBUTE:
|
|
135
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
136
|
-
return [rule.condition, (0, exports.checkAttributes)(ruleDetail, declination.attributes)];
|
|
137
|
-
}));
|
|
138
|
-
default:
|
|
139
|
-
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
return _checkRuleApplicationArray(currentDiscountMap);
|
|
143
|
-
};
|
|
144
|
-
exports.shouldApplyRuleToDeclination = shouldApplyRuleToDeclination;
|
|
145
|
-
const getResultRuleDetail = (ruleDetail, cartValue, log) => {
|
|
146
|
-
let ruleRespected = false;
|
|
147
|
-
let isDate = false;
|
|
148
|
-
try {
|
|
149
|
-
let amountValue;
|
|
150
|
-
let amountValue2;
|
|
151
|
-
switch (true) {
|
|
152
|
-
case typeof cartValue === 'number':
|
|
153
|
-
if (ruleDetail.operator === 'between') {
|
|
154
|
-
amountValue = Number(ruleDetail.value[0].toString().replace(',', '.')) || [];
|
|
155
|
-
amountValue2 = Number(ruleDetail.value[1].toString().replace(',', '.')) || [];
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
amountValue = ruleDetail.value.map((v) => Number(v.toString().replace(',', '.'))) || [];
|
|
159
|
-
amountValue2 = 0 || [];
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
case typeof cartValue === 'string' && !!!moment_1.default.isDate((0, data_1.formatDate)(cartValue)):
|
|
163
|
-
if (ruleDetail.operator === 'between') {
|
|
164
|
-
amountValue = ruleDetail.value[0] || [];
|
|
165
|
-
amountValue2 = ruleDetail.value[1] || [];
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
amountValue2 = [];
|
|
169
|
-
amountValue = ruleDetail.value || [];
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
default:
|
|
173
|
-
if (!!log)
|
|
174
|
-
console.log('HERE!');
|
|
175
|
-
cartValue = (0, data_1.formatDate)(cartValue);
|
|
176
|
-
if (typeof ruleDetail.value[0] === 'number') {
|
|
177
|
-
if ((0, moment_1.default)(cartValue).isValid())
|
|
178
|
-
cartValue = (0, moment_1.default)(cartValue).day();
|
|
179
|
-
amountValue = ruleDetail.value || [];
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
isDate = true;
|
|
183
|
-
amountValue = (0, moment_1.default)(ruleDetail.value[0]);
|
|
184
|
-
if (!!ruleDetail.value[1] && moment_1.default.isDate(ruleDetail.value[1])) {
|
|
185
|
-
amountValue2 = (0, moment_1.default)(ruleDetail.value[1]);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
amountValue2 = (0, moment_1.default)();
|
|
189
|
-
}
|
|
190
|
-
switch (ruleDetail.operator) {
|
|
191
|
-
case '==':
|
|
192
|
-
ruleRespected = amountValue.isSame((0, moment_1.default)(cartValue), 'date');
|
|
193
|
-
break;
|
|
194
|
-
case '!=':
|
|
195
|
-
ruleRespected = !!!amountValue.isSame((0, moment_1.default)(cartValue), 'date');
|
|
196
|
-
break;
|
|
197
|
-
case '<=':
|
|
198
|
-
ruleRespected = (0, moment_1.default)(cartValue).isSameOrBefore(amountValue, 'date');
|
|
199
|
-
break;
|
|
200
|
-
case '>=':
|
|
201
|
-
ruleRespected = (0, moment_1.default)(cartValue).isSameOrAfter(amountValue, 'date');
|
|
202
|
-
break;
|
|
203
|
-
case '<':
|
|
204
|
-
ruleRespected = (0, moment_1.default)(cartValue).isBefore(amountValue, 'date');
|
|
205
|
-
break;
|
|
206
|
-
case '>':
|
|
207
|
-
ruleRespected = (0, moment_1.default)(cartValue).isAfter(amountValue, 'date');
|
|
208
|
-
break;
|
|
209
|
-
case 'between':
|
|
210
|
-
ruleRespected = (0, moment_1.default)(cartValue).isBetween(amountValue, amountValue2, 'date', '[]');
|
|
211
|
-
break;
|
|
212
|
-
case 'contains':
|
|
213
|
-
default:
|
|
214
|
-
ruleRespected = false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (!!!isDate) {
|
|
219
|
-
if (!Array.isArray(amountValue) && ruleDetail.operator !== 'between') {
|
|
220
|
-
amountValue = [amountValue];
|
|
221
|
-
}
|
|
222
|
-
switch (ruleDetail.operator) {
|
|
223
|
-
case '==':
|
|
224
|
-
ruleRespected = !!amountValue.some((v) => v === cartValue);
|
|
225
|
-
break;
|
|
226
|
-
case '!=':
|
|
227
|
-
ruleRespected = !!amountValue.every((v) => v !== cartValue);
|
|
228
|
-
break;
|
|
229
|
-
case '<=':
|
|
230
|
-
ruleRespected = !!amountValue.some((v) => cartValue <= v);
|
|
231
|
-
break;
|
|
232
|
-
case '>=':
|
|
233
|
-
ruleRespected = !!amountValue.some((v) => cartValue >= v);
|
|
234
|
-
break;
|
|
235
|
-
case '<':
|
|
236
|
-
ruleRespected = !!amountValue.some((v) => cartValue < v);
|
|
237
|
-
break;
|
|
238
|
-
case '>':
|
|
239
|
-
ruleRespected = !!amountValue.some((v) => cartValue > v);
|
|
240
|
-
break;
|
|
241
|
-
case 'between':
|
|
242
|
-
ruleRespected = cartValue > amountValue && cartValue < amountValue2;
|
|
243
|
-
break;
|
|
244
|
-
case 'contains':
|
|
245
|
-
ruleRespected = !!amountValue.some((v) => cartValue.toString().indexOf(v.toString()) !== -1);
|
|
246
|
-
break;
|
|
247
|
-
case 'contains-not':
|
|
248
|
-
ruleRespected = !!!amountValue.some((v) => cartValue.toString().indexOf(v.toString()) !== -1);
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
console.log(error.toString());
|
|
255
|
-
}
|
|
256
|
-
return ruleRespected;
|
|
257
|
-
};
|
|
258
|
-
exports.getResultRuleDetail = getResultRuleDetail;
|
|
259
|
-
const checkAttributes = (attributeAndValues, arrDeclinationAttributes) => {
|
|
260
|
-
const parentAttributeID = attributeAndValues.value[0].parentAttribute;
|
|
261
|
-
const attributeValues = attributeAndValues.value[0].attributeOptions;
|
|
262
|
-
const operator = attributeAndValues.operator;
|
|
263
|
-
let matchingAttributes = false;
|
|
264
|
-
for (let declinationAttribute of arrDeclinationAttributes) {
|
|
265
|
-
if (!!matchingAttributes)
|
|
266
|
-
return true;
|
|
267
|
-
if (declinationAttribute.attribute_id !== parentAttributeID)
|
|
268
|
-
continue;
|
|
269
|
-
if (!!declinationAttribute.values) {
|
|
270
|
-
matchingAttributes =
|
|
271
|
-
operator === '=='
|
|
272
|
-
? attributeValues.some((attr) => declinationAttribute.values.some((value) => value.slug === attr))
|
|
273
|
-
: !!!attributeValues.some((attr) => declinationAttribute.values.some((value) => value.slug === attr));
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return matchingAttributes;
|
|
277
|
-
};
|
|
278
|
-
exports.checkAttributes = checkAttributes;
|
|
279
|
-
const getCartPromoType = (discount) => {
|
|
280
|
-
return !!discount.result.action
|
|
281
|
-
? discount.result.action === IDiscountRule_1.ResultActionEnum.GET
|
|
282
|
-
? Cart_1.CartPromoAppliesToEnum.ITEMS
|
|
283
|
-
: [IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, IDiscountRule_1.ResultActionEnum.FLATERATE_SHIPPING].includes(discount.result.action)
|
|
284
|
-
? Cart_1.CartPromoAppliesToEnum.SHIPPING
|
|
285
|
-
: [
|
|
286
|
-
IDiscountRule_1.ResultActionEnum.AMOUNT_SKU,
|
|
287
|
-
IDiscountRule_1.ResultActionEnum.PERCENT_SKU,
|
|
288
|
-
IDiscountRule_1.ResultActionEnum.AMOUNT_CATEGORY,
|
|
289
|
-
IDiscountRule_1.ResultActionEnum.PERCENT_CATEGORY
|
|
290
|
-
].includes(discount.result.action)
|
|
291
|
-
? Cart_1.CartPromoAppliesToEnum.PRODUCT
|
|
292
|
-
: [IDiscountRule_1.ResultActionEnum.AMOUNT_AFTER_TAXES, IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES].includes(discount.result.action)
|
|
293
|
-
? Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES
|
|
294
|
-
: Cart_1.CartPromoAppliesToEnum.SUBTOTAL
|
|
295
|
-
: Cart_1.CartPromoAppliesToEnum.SUBTOTAL;
|
|
296
|
-
};
|
|
297
|
-
exports.getCartPromoType = getCartPromoType;
|
|
298
|
-
const checkPromoCodeEligibility = (cart, promoCode) => {
|
|
299
|
-
var _a;
|
|
300
|
-
let currentDiscountMap = [];
|
|
301
|
-
const promoType = (0, exports.getCartPromoType)(promoCode);
|
|
302
|
-
const currentPromos = (_a = (0, exports.getCartPromo)(cart)) !== null && _a !== void 0 ? _a : [];
|
|
303
|
-
if (promoType == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES &&
|
|
304
|
-
currentPromos.some((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES)) {
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
if (promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING && (!!cart.is_pickup || !!!cart.shipping_selected)) {
|
|
308
|
-
return false;
|
|
309
|
-
}
|
|
310
|
-
if (promoType === Cart_1.CartPromoAppliesToEnum.PRODUCT &&
|
|
311
|
-
(!!promoCode.result.action_sku || !!promoCode.result.action_categories)) {
|
|
312
|
-
const itemsWherePromoApplicable = (0, exports.getResultAppliedDiscountSkus)(cart.items, promoCode);
|
|
313
|
-
if (!!!itemsWherePromoApplicable.length)
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
const rules = promoCode.rules;
|
|
317
|
-
if (!!promoCode.noExtraRules || !!!rules || !!!rules.length)
|
|
318
|
-
return true;
|
|
319
|
-
currentDiscountMap = rules.map((rule) => _checkIfRuleAppliesToCart(rule, promoCode.appliesTo, cart));
|
|
320
|
-
return _checkRuleApplicationArray(currentDiscountMap);
|
|
321
|
-
};
|
|
322
|
-
exports.checkPromoCodeEligibility = checkPromoCodeEligibility;
|
|
323
|
-
const getTierPricingToApply = (tierPricingToCheck, qte) => {
|
|
324
|
-
if (!!!tierPricingToCheck)
|
|
325
|
-
return;
|
|
326
|
-
return tierPricingToCheck.find((tp) => (0, toNumber_1.default)(tp.from) <= qte && (!!!tp.to || (0, toNumber_1.default)(tp.to) >= qte));
|
|
327
|
-
};
|
|
328
|
-
exports.getTierPricingToApply = getTierPricingToApply;
|
|
329
|
-
const applyTierPricing = (discountRule, price, space, decimals) => {
|
|
330
|
-
if (!!!discountRule.rules || !!!discountRule.rules.length)
|
|
331
|
-
return [];
|
|
332
|
-
if (!!discountRule.draft)
|
|
333
|
-
return [];
|
|
334
|
-
const rule = discountRule.rules.find((_rule) => _rule.field === IDiscountRule_1.RuleFieldEnum.QUANTITY && _rule.ruleDetails.find((detail) => detail.operator === 'between'));
|
|
335
|
-
if (!!!rule)
|
|
336
|
-
return [];
|
|
337
|
-
const details = rule.ruleDetails.find((detail) => detail.operator === 'between');
|
|
338
|
-
if (!!!details)
|
|
339
|
-
return [];
|
|
340
|
-
return [
|
|
341
|
-
{
|
|
342
|
-
from: !!!details.value[1] || !!!(0, toNumber_1.default)(details.value[1])
|
|
343
|
-
? details.value[0]
|
|
344
|
-
: (0, toNumber_1.default)(details.value[0]) < (0, toNumber_1.default)(details.value[1])
|
|
345
|
-
? details.value[0]
|
|
346
|
-
: details.value[1],
|
|
347
|
-
to: !!!details.value[1] || !!!(0, toNumber_1.default)(details.value[1])
|
|
348
|
-
? 0
|
|
349
|
-
: (0, toNumber_1.default)(details.value[0]) > (0, toNumber_1.default)(details.value[1])
|
|
350
|
-
? details.value[0]
|
|
351
|
-
: details.value[1],
|
|
352
|
-
price: (0, currency_1.calculateAmountByCurrencyAllDetails)(space, space.preferences.default.currency(), (0, round_1.default)((0, exports.applyDiscountToPrice)(Number(price), discountRule.result), !!decimals ? decimals : 2)),
|
|
353
|
-
check_attribute_value: !!discountRule.appliesTo.check_attribute_value
|
|
354
|
-
? discountRule.appliesTo.check_attribute_value
|
|
355
|
-
: '',
|
|
356
|
-
check_other_items_category: !!discountRule.appliesTo.check_other_items_category
|
|
357
|
-
? discountRule.appliesTo.check_other_items_category
|
|
358
|
-
: '',
|
|
359
|
-
name: discountRule.name
|
|
360
|
-
}
|
|
361
|
-
];
|
|
362
|
-
};
|
|
363
|
-
exports.applyTierPricing = applyTierPricing;
|
|
364
|
-
const getNewDiscountPriceFromTierPricing = (item, setOriginalPrice, originalDecli) => {
|
|
365
|
-
const tierPricingToApply = (0, exports.getTierPricingToApply)(item.tier_pricing, item.qte);
|
|
366
|
-
const currentDiscountPrice = item.discount_price;
|
|
367
|
-
const currentIsTierPricing = !!currentDiscountPrice && currentDiscountPrice.price_type === 'tierpricing';
|
|
368
|
-
const originalDiscountAmount = !!currentDiscountPrice ? currentDiscountPrice.original_amount : null;
|
|
369
|
-
let prevDiscountPrice = null;
|
|
370
|
-
if (!!currentIsTierPricing && typeof originalDiscountAmount === 'number') {
|
|
371
|
-
const { price_type, original_amount } = currentDiscountPrice, rest = __rest(currentDiscountPrice, ["price_type", "original_amount"]);
|
|
372
|
-
prevDiscountPrice = Object.assign(Object.assign({}, rest), { amount: original_amount });
|
|
373
|
-
}
|
|
374
|
-
if (!!!tierPricingToApply) {
|
|
375
|
-
if (!!setOriginalPrice && !!currentDiscountPrice) {
|
|
376
|
-
let amountToSet = item.regular_price.amount;
|
|
377
|
-
if (!!originalDecli) {
|
|
378
|
-
const calculatedPrice = (0, products_1.getLowestPrice)(Object.assign(Object.assign({}, originalDecli), { qte: item.qte }));
|
|
379
|
-
amountToSet = calculatedPrice.price.amount;
|
|
380
|
-
}
|
|
381
|
-
return Object.assign(Object.assign({}, currentDiscountPrice), { original_amount: !!originalDecli ? amountToSet : item.regular_price.amount });
|
|
382
|
-
}
|
|
383
|
-
return !!currentIsTierPricing ? prevDiscountPrice : currentDiscountPrice !== null && currentDiscountPrice !== void 0 ? currentDiscountPrice : null;
|
|
384
|
-
}
|
|
385
|
-
if (!!setOriginalPrice && !!currentDiscountPrice) {
|
|
386
|
-
return Object.assign(Object.assign({}, currentDiscountPrice), { original_amount: tierPricingToApply.price.amount });
|
|
387
|
-
}
|
|
388
|
-
return Object.assign(Object.assign(Object.assign({}, tierPricingToApply.price), { price_type: 'tierpricing' }), (!!currentDiscountPrice
|
|
389
|
-
? {
|
|
390
|
-
original_amount: typeof originalDiscountAmount === 'number' ? originalDiscountAmount : currentDiscountPrice.amount
|
|
391
|
-
}
|
|
392
|
-
: {}));
|
|
393
|
-
};
|
|
394
|
-
exports.getNewDiscountPriceFromTierPricing = getNewDiscountPriceFromTierPricing;
|
|
395
|
-
const applyDiscountRulesOnProduct = (discount_rules, amount, space) => {
|
|
396
|
-
if (!!!discount_rules || !!!discount_rules.length)
|
|
397
|
-
return undefined;
|
|
398
|
-
let discountIndex = 0;
|
|
399
|
-
let allPromo = discount_rules.filter((discount_rule) => discount_rule.discountRule_type !== 'tier-pricing');
|
|
400
|
-
let current_promo_price = Number(amount);
|
|
401
|
-
for (const discount of allPromo) {
|
|
402
|
-
if (discountIndex > 0 && !discount.is_stackable)
|
|
403
|
-
break;
|
|
404
|
-
let amountToRemove = (0, exports.isPromoAPercentage)(discount)
|
|
405
|
-
? (Number(discount.result.action_value) / 100) * current_promo_price
|
|
406
|
-
: Number(discount.result.action_value);
|
|
407
|
-
current_promo_price -= amountToRemove;
|
|
408
|
-
discountIndex++;
|
|
409
|
-
}
|
|
410
|
-
const spaceProductPrefs = space.preferences.products.get();
|
|
411
|
-
const allowNegativePrices = !!spaceProductPrefs && !!spaceProductPrefs.allow_negative_prices;
|
|
412
|
-
return current_promo_price === Number(amount)
|
|
413
|
-
? undefined
|
|
414
|
-
: current_promo_price < 0 && !!!allowNegativePrices
|
|
415
|
-
? 0
|
|
416
|
-
: current_promo_price;
|
|
417
|
-
};
|
|
418
|
-
exports.applyDiscountRulesOnProduct = applyDiscountRulesOnProduct;
|
|
419
|
-
const applyDiscountToPrice = (initial, discountResultObj) => {
|
|
420
|
-
return discountResultObj.action === 'amount'
|
|
421
|
-
? initial - Number(discountResultObj.action_value)
|
|
422
|
-
: initial * (1 - Number(discountResultObj.action_value) / 100);
|
|
423
|
-
};
|
|
424
|
-
exports.applyDiscountToPrice = applyDiscountToPrice;
|
|
425
|
-
const getSkuArrayForPromo = (valueToConvert) => {
|
|
426
|
-
if (!!Array.isArray(valueToConvert))
|
|
427
|
-
return valueToConvert;
|
|
428
|
-
return [valueToConvert];
|
|
429
|
-
};
|
|
430
|
-
exports.getSkuArrayForPromo = getSkuArrayForPromo;
|
|
431
|
-
const getResultAppliedDiscountSkus = (cartItems, promoToCheck) => {
|
|
432
|
-
var _a, _b, _c;
|
|
433
|
-
const action = (_a = promoToCheck.result.action) !== null && _a !== void 0 ? _a : '';
|
|
434
|
-
const skuArray = (0, exports.getSkuArrayForPromo)((_b = promoToCheck.result.action_sku) !== null && _b !== void 0 ? _b : []);
|
|
435
|
-
const categoryArray = (_c = promoToCheck.result.action_categories) !== null && _c !== void 0 ? _c : [];
|
|
436
|
-
const productsToApplyPromo = cartItems
|
|
437
|
-
.filter((item) => {
|
|
438
|
-
if (!!['amount_category', 'percent_category'].includes(action)) {
|
|
439
|
-
const categorySlugsToCheck = (0, exports.getItemCategorySlugArray)(item.categories);
|
|
440
|
-
return categoryArray.some((cat) => categorySlugsToCheck.includes(cat));
|
|
441
|
-
}
|
|
442
|
-
return skuArray.includes(item.sku);
|
|
443
|
-
})
|
|
444
|
-
.map((item) => item.sku);
|
|
445
|
-
return productsToApplyPromo;
|
|
446
|
-
};
|
|
447
|
-
exports.getResultAppliedDiscountSkus = getResultAppliedDiscountSkus;
|
|
448
|
-
const getItemCategorySlugArray = (itemCategories) => {
|
|
449
|
-
if (!!!itemCategories)
|
|
450
|
-
return [];
|
|
451
|
-
const orderedByLevel = (0, orderBy_1.default)(Object.entries(itemCategories), ([key, _value]) => key);
|
|
452
|
-
const lastLevelCategory = !!orderedByLevel.length ? orderedByLevel[orderedByLevel.length - 1][1] : '';
|
|
453
|
-
return lastLevelCategory.split(' > ');
|
|
454
|
-
};
|
|
455
|
-
exports.getItemCategorySlugArray = getItemCategorySlugArray;
|
|
456
|
-
const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPromos) => {
|
|
457
|
-
var _a;
|
|
458
|
-
const discountRules = !!forcedPromos
|
|
459
|
-
? ((_a = cart.discount_rules) !== null && _a !== void 0 ? _a : []).filter((d) => (!!d.created && (0, moment_1.default)((0, data_1.formatDate)(d.created)).isBefore((0, moment_1.default)((0, data_1.formatDate)(cart.paid_at)))) ||
|
|
460
|
-
(!!d.promo_code && !!d.promo_code.code) ||
|
|
461
|
-
!!!d.created)
|
|
462
|
-
: cart.discount_rules;
|
|
463
|
-
if (!!!discountRules || !!!discountRules.length) {
|
|
464
|
-
return Object.assign(Object.assign(Object.assign({}, cart), (!!cart.cart_promo_applied ? { cart_promo_applied: null } : {})), (!!cart.cart_promos_applied ? { cart_promos_applied: null } : {}));
|
|
465
|
-
}
|
|
466
|
-
let newCart = Object.assign(Object.assign(Object.assign({}, cart), (!!cart.cart_promo_applied &&
|
|
467
|
-
!!!discountRules.some((dr) => dr.id === cart.cart_promo_applied.discount_id)
|
|
468
|
-
? { cart_promo_applied: null }
|
|
469
|
-
: {})), (!!cart.cart_promos_applied
|
|
470
|
-
? {
|
|
471
|
-
cart_promos_applied: cart.cart_promos_applied.filter((promo) => discountRules.some((dr) => dr.id === promo.discount_id))
|
|
472
|
-
}
|
|
473
|
-
: {}));
|
|
474
|
-
const checkIfCanAddPromo = (promoToCheck) => {
|
|
475
|
-
const currentPromos = newCart.cart_promos_applied;
|
|
476
|
-
if (!!!currentPromos || !!!currentPromos.length)
|
|
477
|
-
return true;
|
|
478
|
-
const currentPromosHasPromo = !!currentPromos.some((e) => e.discount_id === promoToCheck.id);
|
|
479
|
-
if (!!currentPromosHasPromo)
|
|
480
|
-
return false;
|
|
481
|
-
if (!!isMultiPromo) {
|
|
482
|
-
return !!promoToCheck.is_stackable && !!currentPromos.every((x) => !!x.stackable);
|
|
483
|
-
}
|
|
484
|
-
return true;
|
|
485
|
-
};
|
|
486
|
-
const currentPromos = (0, exports.getCartPromo)(newCart);
|
|
487
|
-
if (!!currentPromos) {
|
|
488
|
-
let shouldRemovePromo = [];
|
|
489
|
-
let shouldUpdatePromo = [];
|
|
490
|
-
for (const appliedPromo of currentPromos) {
|
|
491
|
-
if (appliedPromo.applies_to === Cart_1.CartPromoAppliesToEnum.PRODUCT && !!appliedPromo.item_given) {
|
|
492
|
-
const sameInCartDiscounts = discountRules.find((d) => d.id == appliedPromo.discount_id);
|
|
493
|
-
if (!!sameInCartDiscounts) {
|
|
494
|
-
const itemsWherePromoApplicable = (0, exports.getResultAppliedDiscountSkus)(cart.items, sameInCartDiscounts);
|
|
495
|
-
if (!!!itemsWherePromoApplicable.length && !!appliedPromo.discount_id) {
|
|
496
|
-
shouldRemovePromo.push(appliedPromo.discount_id);
|
|
497
|
-
}
|
|
498
|
-
else if (itemsWherePromoApplicable.length !== appliedPromo.item_given.length) {
|
|
499
|
-
shouldUpdatePromo.push(Object.assign(Object.assign({}, appliedPromo), { item_given: itemsWherePromoApplicable }));
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
newCart = Object.assign(Object.assign({}, newCart), (!!newCart.cart_promos_applied
|
|
505
|
-
? {
|
|
506
|
-
cart_promos_applied: newCart.cart_promos_applied
|
|
507
|
-
.filter((promo) => !shouldRemovePromo.includes(promo.discount_id))
|
|
508
|
-
.map((promo) => {
|
|
509
|
-
if (!!!shouldUpdatePromo.length)
|
|
510
|
-
return promo;
|
|
511
|
-
const sameInUpdated = shouldUpdatePromo.find((p) => p.discount_id == promo.discount_id);
|
|
512
|
-
return sameInUpdated !== null && sameInUpdated !== void 0 ? sameInUpdated : promo;
|
|
513
|
-
})
|
|
514
|
-
}
|
|
515
|
-
: {}));
|
|
516
|
-
}
|
|
517
|
-
for (const discount of discountRules) {
|
|
518
|
-
if (!!discount.promo_code && !!discount.promo_code.code) {
|
|
519
|
-
const promoCodeInCart = (currentPromos || []).find((p) => p.discount_id == discount.id);
|
|
520
|
-
if (!!promoCodeInCart) {
|
|
521
|
-
const shouldStillApplyCode = (0, exports.checkPromoCodeEligibility)(newCart, discount);
|
|
522
|
-
if (!!!shouldStillApplyCode) {
|
|
523
|
-
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!newCart.cart_promo_applied && newCart.cart_promo_applied.discount_id === discount.id
|
|
524
|
-
? { cart_promo_applied: null }
|
|
525
|
-
: {})), (!!newCart.cart_promos_applied
|
|
526
|
-
? {
|
|
527
|
-
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
528
|
-
}
|
|
529
|
-
: {}));
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
continue;
|
|
533
|
-
}
|
|
534
|
-
const promoType = (0, exports.getCartPromoType)(discount);
|
|
535
|
-
let currentDiscountMap = [];
|
|
536
|
-
if (promoType == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES &&
|
|
537
|
-
((0, exports.getCartPromo)(newCart) || []).some((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES && p.discount_id != discount.id)) {
|
|
538
|
-
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, false]];
|
|
539
|
-
}
|
|
540
|
-
else if (promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING &&
|
|
541
|
-
(!!cart.is_pickup || !!!cart.shipping_selected) &&
|
|
542
|
-
!!!forceShipping) {
|
|
543
|
-
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, false]];
|
|
544
|
-
}
|
|
545
|
-
else if (!!!discount.rules || !!!discount.rules.length) {
|
|
546
|
-
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, true]];
|
|
547
|
-
}
|
|
548
|
-
else if (!!discount.draft) {
|
|
549
|
-
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, true]];
|
|
550
|
-
}
|
|
551
|
-
else {
|
|
552
|
-
currentDiscountMap = discount.rules.map((rule) => _checkIfRuleAppliesToCart(rule, discount.appliesTo, cart));
|
|
553
|
-
}
|
|
554
|
-
if (_checkRuleApplicationArray(currentDiscountMap)) {
|
|
555
|
-
if (discount.draft) {
|
|
556
|
-
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!newCart.cart_promo_applied && newCart.cart_promo_applied.discount_id === discount.id
|
|
557
|
-
? { cart_promo_applied: null }
|
|
558
|
-
: {})), (!!newCart.cart_promos_applied
|
|
559
|
-
? {
|
|
560
|
-
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
561
|
-
}
|
|
562
|
-
: {}));
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
if (promoType === Cart_1.CartPromoAppliesToEnum.PRODUCT &&
|
|
566
|
-
(!!discount.result.action_sku || !!discount.result.action_categories)) {
|
|
567
|
-
const productsToApplyPromo = (0, exports.getResultAppliedDiscountSkus)(cart.items, discount);
|
|
568
|
-
if (!!productsToApplyPromo.length) {
|
|
569
|
-
const newPromo = Object.assign({ promo_name: (0, locale_1.getLocaleOfDictionnary)(discount.name, cart.locale), applies_to: promoType, amount_removed: Number(discount.result.action_value), amount_unit: discount.result.action, item_given: productsToApplyPromo, item_given_amount: 0, free_shipping: discount.result.action === IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, flatrate_shipping: 0, stackable: discount.is_stackable, discount_id: discount.id, promo_code: !!discount.promo_code ? discount.promo_code.code : undefined }, (typeof discount.result.exclude_services_and_fees === 'boolean'
|
|
570
|
-
? {
|
|
571
|
-
exclude_services_and_fees: discount.result.exclude_services_and_fees
|
|
572
|
-
}
|
|
573
|
-
: {}));
|
|
574
|
-
if (!!checkIfCanAddPromo(discount)) {
|
|
575
|
-
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [...(newCart.cart_promos_applied || []), newPromo] });
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!newCart.cart_promo_applied && newCart.cart_promo_applied.discount_id === discount.id
|
|
580
|
-
? { cart_promo_applied: null }
|
|
581
|
-
: {})), (!!newCart.cart_promos_applied
|
|
582
|
-
? {
|
|
583
|
-
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
584
|
-
}
|
|
585
|
-
: {}));
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
const newPromo = Object.assign({ promo_name: (0, locale_1.getLocaleOfDictionnary)(discount.name, cart.locale), applies_to: promoType, amount_removed: promoType !== Cart_1.CartPromoAppliesToEnum.SHIPPING ? Number(discount.result.action_value) : 0, amount_unit: discount.result.action, item_given: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS ? discount.result.action_value.toString() : '', item_given_amount: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS && !!discount.result.action_qte
|
|
590
|
-
? Number(discount.result.action_qte)
|
|
591
|
-
: 0, stackable: discount.is_stackable, discount_id: discount.id, free_shipping: discount.result.action === IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, flatrate_shipping: promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING &&
|
|
592
|
-
discount.result.action === IDiscountRule_1.ResultActionEnum.FLATERATE_SHIPPING
|
|
593
|
-
? Number(discount.result.action_value)
|
|
594
|
-
: 0, promo_code: !!discount.promo_code ? discount.promo_code.code : undefined }, (typeof discount.result.exclude_services_and_fees === 'boolean'
|
|
595
|
-
? {
|
|
596
|
-
exclude_services_and_fees: discount.result.exclude_services_and_fees
|
|
597
|
-
}
|
|
598
|
-
: {}));
|
|
599
|
-
if (!!checkIfCanAddPromo(discount)) {
|
|
600
|
-
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [...(newCart.cart_promos_applied || []), newPromo] });
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
else {
|
|
606
|
-
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!cart.cart_promo_applied && cart.cart_promo_applied.discount_id === discount.id
|
|
607
|
-
? { cart_promo_applied: null }
|
|
608
|
-
: {})), (!!newCart.cart_promos_applied
|
|
609
|
-
? {
|
|
610
|
-
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
611
|
-
}
|
|
612
|
-
: {}));
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
if (!!newCart.cart_promos_applied && !!isMultiPromo) {
|
|
616
|
-
const shippingPromo = newCart.cart_promos_applied.filter((x) => x.applies_to === Cart_1.CartPromoAppliesToEnum.SHIPPING);
|
|
617
|
-
if (!!shippingPromo && !!shippingPromo.length) {
|
|
618
|
-
let flatPrice = 1000000;
|
|
619
|
-
let promo = 0;
|
|
620
|
-
for (let i = 0; i < shippingPromo.length; i++) {
|
|
621
|
-
if (shippingPromo[i].amount_unit === 'free_shipping') {
|
|
622
|
-
promo = i;
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
if (!!shippingPromo[i].flatrate_shipping && shippingPromo[i].flatrate_shipping < flatPrice) {
|
|
626
|
-
promo = i;
|
|
627
|
-
flatPrice = shippingPromo[i].flatrate_shipping;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
const promoSansShipping = newCart.cart_promos_applied.filter((x) => x.applies_to !== Cart_1.CartPromoAppliesToEnum.SHIPPING);
|
|
631
|
-
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [...promoSansShipping, shippingPromo[promo]] });
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
if (!!forcedPromos && !!forcedPromos.length) {
|
|
635
|
-
const appliedPromos = !!newCart.cart_promos_applied && !!newCart.cart_promos_applied.length
|
|
636
|
-
? newCart.cart_promos_applied.map((p) => p.discount_id)
|
|
637
|
-
: [];
|
|
638
|
-
const newForcedPromos = forcedPromos.filter((f) => !!!appliedPromos.includes(f.discount_id));
|
|
639
|
-
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [
|
|
640
|
-
...(!!newCart.cart_promos_applied && !!newCart.cart_promos_applied.length ? newCart.cart_promos_applied : []),
|
|
641
|
-
...newForcedPromos
|
|
642
|
-
] });
|
|
643
|
-
}
|
|
644
|
-
return Object.assign(Object.assign({}, newCart), { free_shipping: !!newCart.cart_promos_applied
|
|
645
|
-
? newCart.cart_promos_applied.some((p) => !!p.free_shipping)
|
|
646
|
-
: !!newCart.cart_promo_applied && newCart.cart_promo_applied.free_shipping });
|
|
647
|
-
};
|
|
648
|
-
exports.applyDiscountToCart = applyDiscountToCart;
|
|
649
|
-
const getStandardCartPromoFromDiscount = (cart, discount) => {
|
|
650
|
-
const promoType = (0, exports.getCartPromoType)(discount);
|
|
651
|
-
return Object.assign({ promo_name: (0, locale_1.getLocaleOfDictionnary)(discount.name, cart.locale), applies_to: promoType, amount_removed: promoType !== Cart_1.CartPromoAppliesToEnum.SHIPPING ? Number(discount.result.action_value) : 0, amount_unit: discount.result.action, item_given: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS ? discount.result.action_value.toString() : '', item_given_amount: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS && !!discount.result.action_qte
|
|
652
|
-
? Number(discount.result.action_qte)
|
|
653
|
-
: 0, stackable: discount.is_stackable, discount_id: discount.id, free_shipping: discount.result.action === IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, flatrate_shipping: promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING && discount.result.action === IDiscountRule_1.ResultActionEnum.FLATERATE_SHIPPING
|
|
654
|
-
? Number(discount.result.action_value)
|
|
655
|
-
: 0, promo_code: !!discount.promo_code ? discount.promo_code.code : undefined }, (typeof discount.result.exclude_services_and_fees === 'boolean'
|
|
656
|
-
? {
|
|
657
|
-
exclude_services_and_fees: discount.result.exclude_services_and_fees
|
|
658
|
-
}
|
|
659
|
-
: {}));
|
|
660
|
-
};
|
|
661
|
-
exports.getStandardCartPromoFromDiscount = getStandardCartPromoFromDiscount;
|
|
662
|
-
const getOnlyServicesAndFeesSubtotal = (cartData, allCurrentAppliedToItemPromos) => {
|
|
663
|
-
let servicesAndFeesTotal = 0;
|
|
664
|
-
cartData.items.forEach((i) => {
|
|
665
|
-
if (!!!i.is_service || !!(0, g2_1.isEscompteSuppItem)(i.sku))
|
|
666
|
-
return;
|
|
667
|
-
const associatedPromos = allCurrentAppliedToItemPromos.filter((p) => { var _a; return (0, exports.getSkuArrayForPromo)((_a = p.item_given) !== null && _a !== void 0 ? _a : []).includes(i.sku); });
|
|
668
|
-
servicesAndFeesTotal += (0, round_1.default)(i.qte * (0, products_1.getLowestPrice)(i).price.amount, 3);
|
|
669
|
-
if (!!associatedPromos.length) {
|
|
670
|
-
for (const promo of associatedPromos) {
|
|
671
|
-
if (!!!promo.amount_removed)
|
|
672
|
-
continue;
|
|
673
|
-
if ((0, exports.isPromoAPercentage)(promo, { defaultToPercent: true })) {
|
|
674
|
-
servicesAndFeesTotal -= (0, round_1.default)((promo.amount_removed / 100) * (i.qte * (0, products_1.getLowestPrice)(i).price.amount), 3);
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
servicesAndFeesTotal -= promo.amount_removed * i.qte;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
});
|
|
682
|
-
return servicesAndFeesTotal;
|
|
683
|
-
};
|
|
684
|
-
exports.getOnlyServicesAndFeesSubtotal = getOnlyServicesAndFeesSubtotal;
|
|
685
|
-
const _checkIfRuleAppliesToCart = (rule, appliesTo, cart) => {
|
|
686
|
-
var _a;
|
|
687
|
-
const todayDate = (0, moment_1.default)().toDate();
|
|
688
|
-
const ruleCondition = (_a = rule.condition) !== null && _a !== void 0 ? _a : IDiscountRule_1.RuleConditionEnum.AND;
|
|
689
|
-
switch (rule.field) {
|
|
690
|
-
case IDiscountRule_1.RuleFieldEnum.CART_TOTAL:
|
|
691
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
692
|
-
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, cart.subtotal)];
|
|
693
|
-
}));
|
|
694
|
-
case IDiscountRule_1.RuleFieldEnum.CART_ITEM_TOTAL:
|
|
695
|
-
let totalCartItems = (0, sumBy_1.default)(cart.items, (item) => item.qte);
|
|
696
|
-
if (!!appliesTo.check_other_items_category) {
|
|
697
|
-
const correspondingCartItems = cart.items.filter((item) => {
|
|
698
|
-
if (!!item.tier_pricing && !!item.tier_pricing.length) {
|
|
699
|
-
return (!!item.tier_pricing[0].check_other_items_category &&
|
|
700
|
-
item.tier_pricing[0].check_other_items_category === appliesTo.check_other_items_category);
|
|
701
|
-
}
|
|
702
|
-
return false;
|
|
703
|
-
});
|
|
704
|
-
totalCartItems = (0, sumBy_1.default)(correspondingCartItems, (item) => {
|
|
705
|
-
let amountInBox = 1;
|
|
706
|
-
const qte = item.qte;
|
|
707
|
-
if (!!item.attributes['8OUv9qj0aDbiLOovd4dp']) {
|
|
708
|
-
amountInBox = Number(item.attributes['8OUv9qj0aDbiLOovd4dp']);
|
|
709
|
-
}
|
|
710
|
-
return amountInBox * qte;
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
714
|
-
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, totalCartItems)];
|
|
715
|
-
}));
|
|
716
|
-
case IDiscountRule_1.RuleFieldEnum.CART_ITEM:
|
|
717
|
-
if (!!cart) {
|
|
718
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
719
|
-
if (ruleDetail.operator === 'contains') {
|
|
720
|
-
return [ruleCondition, ruleDetail.value.every((v) => !!cart.items.some((item) => item.sku === v))];
|
|
721
|
-
}
|
|
722
|
-
return [ruleCondition, !!!cart.items.find((item) => !!ruleDetail.value.find((v) => v === item.sku))];
|
|
723
|
-
}));
|
|
724
|
-
}
|
|
725
|
-
case IDiscountRule_1.RuleFieldEnum.CUSTOMER:
|
|
726
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
727
|
-
return [ruleCondition, cart.customer_id === ruleDetail.value[0]];
|
|
728
|
-
}));
|
|
729
|
-
case IDiscountRule_1.RuleFieldEnum.CUSTOMER_TYPE:
|
|
730
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
731
|
-
if (ruleDetail.operator === '!=') {
|
|
732
|
-
return [
|
|
733
|
-
ruleCondition,
|
|
734
|
-
(!!cart.customer_info && !!!cart.customer_info.pro_title) ||
|
|
735
|
-
(!!cart.customer_info &&
|
|
736
|
-
!!cart.customer_info.pro_title &&
|
|
737
|
-
!!!ruleDetail.value.includes(cart.customer_info.pro_title))
|
|
738
|
-
];
|
|
739
|
-
}
|
|
740
|
-
return [
|
|
741
|
-
ruleCondition,
|
|
742
|
-
!!cart.customer_info &&
|
|
743
|
-
!!cart.customer_info.pro_title &&
|
|
744
|
-
!!ruleDetail.value.includes(cart.customer_info.pro_title)
|
|
745
|
-
];
|
|
746
|
-
}));
|
|
747
|
-
case IDiscountRule_1.RuleFieldEnum.DATE:
|
|
748
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
749
|
-
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, todayDate)];
|
|
750
|
-
}));
|
|
751
|
-
case IDiscountRule_1.RuleFieldEnum.WEEKDAY:
|
|
752
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
753
|
-
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, todayDate)];
|
|
754
|
-
}));
|
|
755
|
-
case IDiscountRule_1.RuleFieldEnum.CART_PLATFORM:
|
|
756
|
-
const cartPlatform = !![Cart_1.CartTypeEnum.POS, Cart_1.CartTypeEnum.POS_TRANSACTIONNAL].includes(cart.cart_type)
|
|
757
|
-
? Cart_1.CartTypeEnum.POS
|
|
758
|
-
: Cart_1.CartTypeEnum.WEB;
|
|
759
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
760
|
-
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, cartPlatform)];
|
|
761
|
-
}));
|
|
762
|
-
case IDiscountRule_1.RuleFieldEnum.CART_TYPE:
|
|
763
|
-
const cartType = cart.cart_content_type === Cart_1.CartContentTypeEnum.MIXED
|
|
764
|
-
? Cart_1.CartContentTypeEnum.MIXED
|
|
765
|
-
: !!(0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.INSTALLATION, cart)
|
|
766
|
-
? cart_2.CartGeneralTypeEnum.INSTALLATION
|
|
767
|
-
: (0, cart_1.getCartType)(cart);
|
|
768
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
769
|
-
let result = (0, exports.getResultRuleDetail)(ruleDetail, cartType);
|
|
770
|
-
for (const value of ruleDetail.value) {
|
|
771
|
-
if (value === cart_2.CartGeneralTypeEnum.GRASS && cartType === cart_2.CartGeneralTypeEnum.INSTALLATION)
|
|
772
|
-
result = true;
|
|
773
|
-
}
|
|
774
|
-
return [ruleCondition, result];
|
|
775
|
-
}));
|
|
776
|
-
case IDiscountRule_1.RuleFieldEnum.CART_ITEM_CATEGORIES:
|
|
777
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
778
|
-
let result = ruleDetail.operator !== 'contains';
|
|
779
|
-
for (const i of cart.items) {
|
|
780
|
-
const categorySlugsToCheck = (0, exports.getItemCategorySlugArray)(i.categories);
|
|
781
|
-
if (!!categorySlugsToCheck.length) {
|
|
782
|
-
for (const ruleValue of ruleDetail.value) {
|
|
783
|
-
if (!!categorySlugsToCheck.includes(ruleValue))
|
|
784
|
-
result = ruleDetail.operator !== 'contains' ? false : true;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
return [ruleCondition, result];
|
|
789
|
-
}));
|
|
790
|
-
case IDiscountRule_1.RuleFieldEnum.ORDER_DAY:
|
|
791
|
-
const order_day_day = !!cart.shipping_payload && !!cart.shipping_payload.delivery_or_pickup_date
|
|
792
|
-
? cart.shipping_payload.delivery_or_pickup_date
|
|
793
|
-
: '';
|
|
794
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
795
|
-
return [ruleCondition, !!order_day_day ? (0, exports.getResultRuleDetail)(ruleDetail, (0, moment_1.default)(order_day_day).day()) : false];
|
|
796
|
-
}));
|
|
797
|
-
case IDiscountRule_1.RuleFieldEnum.ORDER_TYPE:
|
|
798
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
799
|
-
return [
|
|
800
|
-
ruleCondition,
|
|
801
|
-
!!cart.is_pickup
|
|
802
|
-
? ruleDetail.operator === '=='
|
|
803
|
-
? !!ruleDetail.value.includes('pickup')
|
|
804
|
-
: !!!ruleDetail.value.includes('pickup')
|
|
805
|
-
: ruleDetail.operator === '=='
|
|
806
|
-
? !!ruleDetail.value.includes('shipping')
|
|
807
|
-
: !!!ruleDetail.value.includes('shipping')
|
|
808
|
-
];
|
|
809
|
-
}));
|
|
810
|
-
case IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD:
|
|
811
|
-
if (cart.custom_payment_type &&
|
|
812
|
-
cart.custom_payment_type.method == Cart_1.CustomPaymentTypeEnum.INCENTIVE) {
|
|
813
|
-
return [ruleCondition, true];
|
|
814
|
-
}
|
|
815
|
-
const paymentTypesToCompare = !!cart.custom_payment_type
|
|
816
|
-
? [cart.custom_payment_type.method]
|
|
817
|
-
: !!(0, object_1.recursiveCheckObject)(cart, 'shipping_payload.chosen_payment')
|
|
818
|
-
? [(0, object_1.recursiveCheckObject)(cart, 'shipping_payload.chosen_payment')]
|
|
819
|
-
: !!cart.payment_details && cart.payment_details.length
|
|
820
|
-
? cart.payment_details.map((p) => p.method)
|
|
821
|
-
: !!cart.paid_by
|
|
822
|
-
? [cart.paid_by]
|
|
823
|
-
: [];
|
|
824
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
825
|
-
let result = ruleDetail.operator == 'contains'
|
|
826
|
-
? paymentTypesToCompare.some((type) => ruleDetail.value.includes(type))
|
|
827
|
-
: !paymentTypesToCompare.every((type) => ruleDetail.value.includes(type));
|
|
828
|
-
return [ruleCondition, result];
|
|
829
|
-
}));
|
|
830
|
-
case IDiscountRule_1.RuleFieldEnum.CUSTOMER_TERMS_CODE:
|
|
831
|
-
let customerTermsCode = (0, object_1.recursiveCheckObject)(cart, 'customer_info.terms_code');
|
|
832
|
-
let customerPrevTermsCode = (0, object_1.recursiveCheckObject)(cart, 'customer_info.previous_terms_code');
|
|
833
|
-
let trueTermsCode = customerTermsCode == 'HOLD' ? 'HOLD' : customerPrevTermsCode !== null && customerPrevTermsCode !== void 0 ? customerPrevTermsCode : customerTermsCode;
|
|
834
|
-
let termsCodeToCheck = !!!trueTermsCode
|
|
835
|
-
? undefined
|
|
836
|
-
: data_2.allCodesForHold.includes(trueTermsCode)
|
|
837
|
-
? 'HOLD'
|
|
838
|
-
: data_2.allCodesForPSL.includes(trueTermsCode)
|
|
839
|
-
? 'P.S.L'
|
|
840
|
-
: 'NET30';
|
|
841
|
-
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
842
|
-
let operator = ruleDetail.operator;
|
|
843
|
-
if (!!!termsCodeToCheck)
|
|
844
|
-
return [IDiscountRule_1.RuleConditionEnum.AND, operator == '!='];
|
|
845
|
-
return [
|
|
846
|
-
ruleCondition,
|
|
847
|
-
operator == '=='
|
|
848
|
-
? ruleDetail.value.includes(termsCodeToCheck)
|
|
849
|
-
: !ruleDetail.value.includes(termsCodeToCheck)
|
|
850
|
-
];
|
|
851
|
-
}));
|
|
852
|
-
default:
|
|
853
|
-
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
const _checkRuleApplicationArray = (checkedRulesApplicationArray) => {
|
|
857
|
-
return ((checkedRulesApplicationArray.some((option) => !!option && option.indexOf(IDiscountRule_1.RuleConditionEnum.OR) !== -1) &&
|
|
858
|
-
checkedRulesApplicationArray.some((option) => !!option && option.indexOf(true) !== -1)) ||
|
|
859
|
-
(checkedRulesApplicationArray.some((option) => !!option && option.indexOf(IDiscountRule_1.RuleConditionEnum.AND) !== -1) &&
|
|
860
|
-
!checkedRulesApplicationArray.some((option) => !!option && option.indexOf(false) !== -1)));
|
|
861
|
-
};
|
|
862
|
-
const checkIfCouldApplyIncentivePromo = (cartData, skipCheckFor = []) => {
|
|
863
|
-
let afterTaxesPromo = cartData.discount_rules.find((d) => !d.draft &&
|
|
864
|
-
(d.result.action == IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES ||
|
|
865
|
-
d.result.action == IDiscountRule_1.ResultActionEnum.AMOUNT_AFTER_TAXES));
|
|
866
|
-
if (!!!afterTaxesPromo)
|
|
867
|
-
return false;
|
|
868
|
-
if (!!!afterTaxesPromo.rules || afterTaxesPromo.rules.length == 0)
|
|
869
|
-
return true;
|
|
870
|
-
const appliesTo = afterTaxesPromo.appliesTo;
|
|
871
|
-
const canApply = afterTaxesPromo.rules.map((r) => {
|
|
872
|
-
if (r.field && skipCheckFor.includes(r.field))
|
|
873
|
-
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
874
|
-
return _checkIfRuleAppliesToCart(r, appliesTo, cartData);
|
|
875
|
-
});
|
|
876
|
-
return _checkRuleApplicationArray(canApply);
|
|
877
|
-
};
|
|
878
|
-
exports.checkIfCouldApplyIncentivePromo = checkIfCouldApplyIncentivePromo;
|
|
879
|
-
const getAfterTaxesPromosTotalAmount = (cartData, checkDiscountRules) => {
|
|
880
|
-
let currentSubtotal = cartData.subtotal;
|
|
881
|
-
let afterTaxesPromo = (0, exports.getAfterTaxesPromoInCart)(cartData, checkDiscountRules);
|
|
882
|
-
let totalAmountForAfterTaxesPromos = 0;
|
|
883
|
-
if (!!afterTaxesPromo && !!afterTaxesPromo.amount_removed) {
|
|
884
|
-
if ((0, exports.isPromoAPercentage)(afterTaxesPromo, { includePaymentIncentiveInCheck: true })) {
|
|
885
|
-
totalAmountForAfterTaxesPromos += currentSubtotal * (afterTaxesPromo.amount_removed / 100);
|
|
886
|
-
}
|
|
887
|
-
else {
|
|
888
|
-
totalAmountForAfterTaxesPromos += afterTaxesPromo.amount_removed;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
return totalAmountForAfterTaxesPromos;
|
|
892
|
-
};
|
|
893
|
-
exports.getAfterTaxesPromosTotalAmount = getAfterTaxesPromosTotalAmount;
|
|
894
|
-
const getAfterTaxesPromoInCart = (cartData, checkDiscountRules) => {
|
|
895
|
-
var _a;
|
|
896
|
-
let cartPromos = (_a = (0, exports.getCartPromo)(cartData)) !== null && _a !== void 0 ? _a : [];
|
|
897
|
-
let incentivePromo = cartPromos.find((p) => p.applies_to === Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
|
|
898
|
-
let discountIncentive = (0, exports.getPaymentIncentiveDiscount)(cartData.discount_rules);
|
|
899
|
-
if (!!checkDiscountRules &&
|
|
900
|
-
!!discountIncentive &&
|
|
901
|
-
(!!!incentivePromo || discountIncentive.result.action_value != incentivePromo.amount_removed)) {
|
|
902
|
-
incentivePromo = (0, exports.getStandardCartPromoFromDiscount)(cartData, discountIncentive);
|
|
903
|
-
}
|
|
904
|
-
return incentivePromo;
|
|
905
|
-
};
|
|
906
|
-
exports.getAfterTaxesPromoInCart = getAfterTaxesPromoInCart;
|
|
907
|
-
const getPaymentIncentiveDiscountInfo = (cartData, checkForAllPaidByDiscounts) => {
|
|
908
|
-
let appliesToPaymentTypes = undefined;
|
|
909
|
-
let paymentIncentiveDiscount = (0, exports.getPaymentIncentiveDiscount)(cartData.discount_rules);
|
|
910
|
-
if (!!!paymentIncentiveDiscount) {
|
|
911
|
-
if (!!checkForAllPaidByDiscounts)
|
|
912
|
-
paymentIncentiveDiscount = cartData.discount_rules.find((d) => (d.rules || []).some((r) => r.field == IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD));
|
|
913
|
-
if (!!!paymentIncentiveDiscount)
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
|
-
let ruleForPaymentType = (paymentIncentiveDiscount.rules || []).find((rule) => rule.field == IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD);
|
|
917
|
-
if (!!ruleForPaymentType) {
|
|
918
|
-
appliesToPaymentTypes = {
|
|
919
|
-
amount: (0, toNumber_1.default)(paymentIncentiveDiscount.result.action_value),
|
|
920
|
-
isPercent: (0, exports.isPromoAPercentage)(paymentIncentiveDiscount, { includePaymentIncentiveInCheck: true }),
|
|
921
|
-
paymentTypes: (0, flatten_1.default)(ruleForPaymentType.ruleDetails.map((d) => (0, flatten_1.default)(d.value)))
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
return appliesToPaymentTypes;
|
|
925
|
-
};
|
|
926
|
-
exports.getPaymentIncentiveDiscountInfo = getPaymentIncentiveDiscountInfo;
|
|
927
|
-
const getPaymentIncentiveDiscount = (discountRules) => {
|
|
928
|
-
if (!!!discountRules)
|
|
929
|
-
return;
|
|
930
|
-
let paymentIncentiveDiscount = discountRules.find((d) => !!d.result.action &&
|
|
931
|
-
[IDiscountRule_1.ResultActionEnum.AMOUNT_AFTER_TAXES, IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES].includes(d.result.action));
|
|
932
|
-
return paymentIncentiveDiscount;
|
|
933
|
-
};
|
|
934
|
-
exports.getPaymentIncentiveDiscount = getPaymentIncentiveDiscount;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getPaymentIncentiveDiscount = exports.getPaymentIncentiveDiscountInfo = exports.getAfterTaxesPromoInCart = exports.getAfterTaxesPromosTotalAmount = exports.checkIfCouldApplyIncentivePromo = exports.getOnlyServicesAndFeesSubtotal = exports.getStandardCartPromoFromDiscount = exports.applyDiscountToCart = exports.getItemCategorySlugArray = exports.getResultAppliedDiscountSkus = exports.getSkuArrayForPromo = exports.applyDiscountToPrice = exports.applyDiscountRulesOnProduct = exports.getNewDiscountPriceFromTierPricing = exports.applyTierPricing = exports.getTierPricingToApply = exports.checkPromoCodeEligibility = exports.getCartPromoType = exports.checkAttributes = exports.getResultRuleDetail = exports.shouldApplyRuleToDeclination = exports.getAppliedAmountsForSubtotalPromosOnCart = exports.getCartPromosByAppliesTo = exports.getSubtotalWithoutProductPromos = exports.isPromoAPercentage = exports.shouldCheckPromoCode = exports.getCartPromo = void 0;
|
|
18
|
+
const IDiscountRule_1 = require("../Interfaces/Rules/IDiscountRule");
|
|
19
|
+
const Cart_1 = require("../Interfaces/Cart");
|
|
20
|
+
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
21
|
+
const round_1 = __importDefault(require("lodash/round"));
|
|
22
|
+
const sumBy_1 = __importDefault(require("lodash/sumBy"));
|
|
23
|
+
const toNumber_1 = __importDefault(require("lodash/toNumber"));
|
|
24
|
+
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
25
|
+
const locale_1 = require("./locale");
|
|
26
|
+
const currency_1 = require("./currency");
|
|
27
|
+
const moment_1 = __importDefault(require("moment"));
|
|
28
|
+
const data_1 = require("./data");
|
|
29
|
+
const products_1 = require("./products");
|
|
30
|
+
const cart_1 = require("../rules/GR/utils/cart");
|
|
31
|
+
const cart_2 = require("../rules/GR/interfaces/cart");
|
|
32
|
+
const object_1 = require("./object");
|
|
33
|
+
const data_2 = require("../rules/GR/constants/data");
|
|
34
|
+
const g2_1 = require("../rules/GR/utils/g2");
|
|
35
|
+
const getCartPromo = (cartData) => {
|
|
36
|
+
if (!!!cartData.cart_promo_applied && !!!cartData.cart_promos_applied)
|
|
37
|
+
return;
|
|
38
|
+
return !!cartData.cart_promo_applied
|
|
39
|
+
? [cartData.cart_promo_applied]
|
|
40
|
+
: !!cartData.cart_promos_applied
|
|
41
|
+
? cartData.cart_promos_applied
|
|
42
|
+
: [];
|
|
43
|
+
};
|
|
44
|
+
exports.getCartPromo = getCartPromo;
|
|
45
|
+
const shouldCheckPromoCode = (cartData) => {
|
|
46
|
+
return ((!!cartData.cart_promos_applied && !!cartData.cart_promos_applied.some((p) => p.promo_code)) ||
|
|
47
|
+
(!!cartData.cart_promo_applied && !!cartData.cart_promo_applied.promo_code));
|
|
48
|
+
};
|
|
49
|
+
exports.shouldCheckPromoCode = shouldCheckPromoCode;
|
|
50
|
+
const isPromoAPercentage = (promo, options = {}) => {
|
|
51
|
+
const promoPercentOptions = [
|
|
52
|
+
IDiscountRule_1.ResultActionEnum.PERCENT,
|
|
53
|
+
IDiscountRule_1.ResultActionEnum.PERCENT_CATEGORY,
|
|
54
|
+
IDiscountRule_1.ResultActionEnum.PERCENT_SKU
|
|
55
|
+
];
|
|
56
|
+
if (options.includePaymentIncentiveInCheck)
|
|
57
|
+
promoPercentOptions.push(IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES);
|
|
58
|
+
let propertyToCheck = (0, object_1.recursiveCheckObject)(promo, 'result.action') || (0, object_1.recursiveCheckObject)(promo, 'amount_unit');
|
|
59
|
+
if (!!!propertyToCheck && options.defaultToPercent)
|
|
60
|
+
propertyToCheck = IDiscountRule_1.ResultActionEnum.PERCENT;
|
|
61
|
+
return !!propertyToCheck && promoPercentOptions.includes(propertyToCheck);
|
|
62
|
+
};
|
|
63
|
+
exports.isPromoAPercentage = isPromoAPercentage;
|
|
64
|
+
const getSubtotalWithoutProductPromos = (cartData, itemPromos) => {
|
|
65
|
+
const currentSubtotal = cartData.subtotalWithoutPromotions || cartData.subtotal;
|
|
66
|
+
let allProductSubtotalAmounts = (0, sumBy_1.default)(itemPromos, (i) => !!(0, data_1.getPromoTotalAmount)(cartData.items, i, 'number')
|
|
67
|
+
? (0, data_1.getPromoTotalAmount)(cartData.items, i, 'number')
|
|
68
|
+
: 0);
|
|
69
|
+
return currentSubtotal - allProductSubtotalAmounts;
|
|
70
|
+
};
|
|
71
|
+
exports.getSubtotalWithoutProductPromos = getSubtotalWithoutProductPromos;
|
|
72
|
+
const getCartPromosByAppliesTo = (cartData) => {
|
|
73
|
+
const appliedPromos = (0, exports.getCartPromo)(cartData) || [];
|
|
74
|
+
let subtotalPromos = appliedPromos.filter((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.SUBTOTAL);
|
|
75
|
+
let itemPromos = appliedPromos.filter((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.PRODUCT);
|
|
76
|
+
let afterTaxesPromos = appliedPromos.filter((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
|
|
77
|
+
return {
|
|
78
|
+
subtotal: subtotalPromos,
|
|
79
|
+
items: itemPromos,
|
|
80
|
+
afterTaxes: afterTaxesPromos
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.getCartPromosByAppliesTo = getCartPromosByAppliesTo;
|
|
84
|
+
const getAppliedAmountsForSubtotalPromosOnCart = (cartData) => {
|
|
85
|
+
const activePromos = (0, exports.getCartPromosByAppliesTo)(cartData);
|
|
86
|
+
let currentSubtotal = (0, exports.getSubtotalWithoutProductPromos)(cartData, activePromos.items);
|
|
87
|
+
let promoAmounts = {};
|
|
88
|
+
for (let promo of activePromos.subtotal.filter((p) => !!p.discount_id)) {
|
|
89
|
+
if (!!!promo.amount_removed)
|
|
90
|
+
continue;
|
|
91
|
+
let amountRemoved = promo.amount_removed;
|
|
92
|
+
const serviceAndFeesTotal = (0, exports.getOnlyServicesAndFeesSubtotal)(cartData, activePromos.items);
|
|
93
|
+
if ((0, exports.isPromoAPercentage)(promo, { defaultToPercent: true })) {
|
|
94
|
+
if (!!promo.exclude_services_and_fees) {
|
|
95
|
+
amountRemoved = (0, round_1.default)((promo.amount_removed / 100) * (currentSubtotal - serviceAndFeesTotal), 3);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
amountRemoved = (0, round_1.default)((promo.amount_removed / 100) * currentSubtotal, 3);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
promoAmounts[promo.discount_id] = amountRemoved;
|
|
102
|
+
currentSubtotal -= amountRemoved;
|
|
103
|
+
}
|
|
104
|
+
return promoAmounts;
|
|
105
|
+
};
|
|
106
|
+
exports.getAppliedAmountsForSubtotalPromosOnCart = getAppliedAmountsForSubtotalPromosOnCart;
|
|
107
|
+
const shouldApplyRuleToDeclination = (discount_rule, declination, parentSlug) => {
|
|
108
|
+
if (!!!discount_rule.rules || !!!discount_rule.rules.length)
|
|
109
|
+
return true;
|
|
110
|
+
const currentDiscountMap = discount_rule.rules.map((rule) => {
|
|
111
|
+
const todayDate = (0, moment_1.default)().format('YYYY-MM-DD');
|
|
112
|
+
switch (rule.field) {
|
|
113
|
+
case IDiscountRule_1.RuleFieldEnum.PRODUCT_PRICE:
|
|
114
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
115
|
+
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, declination.price.regular.amount)];
|
|
116
|
+
}));
|
|
117
|
+
case IDiscountRule_1.RuleFieldEnum.SKU:
|
|
118
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
119
|
+
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, declination.sku)];
|
|
120
|
+
}));
|
|
121
|
+
case IDiscountRule_1.RuleFieldEnum.DECLINATION:
|
|
122
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
123
|
+
return [rule.condition, declination.sku === ruleDetail.value[0]];
|
|
124
|
+
}));
|
|
125
|
+
case IDiscountRule_1.RuleFieldEnum.PRODUCT:
|
|
126
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
127
|
+
return [rule.condition, !!!parentSlug || (0, exports.getResultRuleDetail)(ruleDetail, parentSlug)];
|
|
128
|
+
}));
|
|
129
|
+
case IDiscountRule_1.RuleFieldEnum.DATE:
|
|
130
|
+
case IDiscountRule_1.RuleFieldEnum.WEEKDAY:
|
|
131
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
132
|
+
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, (0, moment_1.default)(todayDate).toDate())];
|
|
133
|
+
}));
|
|
134
|
+
case IDiscountRule_1.RuleFieldEnum.ATTRIBUTE:
|
|
135
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
136
|
+
return [rule.condition, (0, exports.checkAttributes)(ruleDetail, declination.attributes)];
|
|
137
|
+
}));
|
|
138
|
+
default:
|
|
139
|
+
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return _checkRuleApplicationArray(currentDiscountMap);
|
|
143
|
+
};
|
|
144
|
+
exports.shouldApplyRuleToDeclination = shouldApplyRuleToDeclination;
|
|
145
|
+
const getResultRuleDetail = (ruleDetail, cartValue, log) => {
|
|
146
|
+
let ruleRespected = false;
|
|
147
|
+
let isDate = false;
|
|
148
|
+
try {
|
|
149
|
+
let amountValue;
|
|
150
|
+
let amountValue2;
|
|
151
|
+
switch (true) {
|
|
152
|
+
case typeof cartValue === 'number':
|
|
153
|
+
if (ruleDetail.operator === 'between') {
|
|
154
|
+
amountValue = Number(ruleDetail.value[0].toString().replace(',', '.')) || [];
|
|
155
|
+
amountValue2 = Number(ruleDetail.value[1].toString().replace(',', '.')) || [];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
amountValue = ruleDetail.value.map((v) => Number(v.toString().replace(',', '.'))) || [];
|
|
159
|
+
amountValue2 = 0 || [];
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case typeof cartValue === 'string' && !!!moment_1.default.isDate((0, data_1.formatDate)(cartValue)):
|
|
163
|
+
if (ruleDetail.operator === 'between') {
|
|
164
|
+
amountValue = ruleDetail.value[0] || [];
|
|
165
|
+
amountValue2 = ruleDetail.value[1] || [];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
amountValue2 = [];
|
|
169
|
+
amountValue = ruleDetail.value || [];
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
if (!!log)
|
|
174
|
+
console.log('HERE!');
|
|
175
|
+
cartValue = (0, data_1.formatDate)(cartValue);
|
|
176
|
+
if (typeof ruleDetail.value[0] === 'number') {
|
|
177
|
+
if ((0, moment_1.default)(cartValue).isValid())
|
|
178
|
+
cartValue = (0, moment_1.default)(cartValue).day();
|
|
179
|
+
amountValue = ruleDetail.value || [];
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
isDate = true;
|
|
183
|
+
amountValue = (0, moment_1.default)(ruleDetail.value[0]);
|
|
184
|
+
if (!!ruleDetail.value[1] && moment_1.default.isDate(ruleDetail.value[1])) {
|
|
185
|
+
amountValue2 = (0, moment_1.default)(ruleDetail.value[1]);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
amountValue2 = (0, moment_1.default)();
|
|
189
|
+
}
|
|
190
|
+
switch (ruleDetail.operator) {
|
|
191
|
+
case '==':
|
|
192
|
+
ruleRespected = amountValue.isSame((0, moment_1.default)(cartValue), 'date');
|
|
193
|
+
break;
|
|
194
|
+
case '!=':
|
|
195
|
+
ruleRespected = !!!amountValue.isSame((0, moment_1.default)(cartValue), 'date');
|
|
196
|
+
break;
|
|
197
|
+
case '<=':
|
|
198
|
+
ruleRespected = (0, moment_1.default)(cartValue).isSameOrBefore(amountValue, 'date');
|
|
199
|
+
break;
|
|
200
|
+
case '>=':
|
|
201
|
+
ruleRespected = (0, moment_1.default)(cartValue).isSameOrAfter(amountValue, 'date');
|
|
202
|
+
break;
|
|
203
|
+
case '<':
|
|
204
|
+
ruleRespected = (0, moment_1.default)(cartValue).isBefore(amountValue, 'date');
|
|
205
|
+
break;
|
|
206
|
+
case '>':
|
|
207
|
+
ruleRespected = (0, moment_1.default)(cartValue).isAfter(amountValue, 'date');
|
|
208
|
+
break;
|
|
209
|
+
case 'between':
|
|
210
|
+
ruleRespected = (0, moment_1.default)(cartValue).isBetween(amountValue, amountValue2, 'date', '[]');
|
|
211
|
+
break;
|
|
212
|
+
case 'contains':
|
|
213
|
+
default:
|
|
214
|
+
ruleRespected = false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (!!!isDate) {
|
|
219
|
+
if (!Array.isArray(amountValue) && ruleDetail.operator !== 'between') {
|
|
220
|
+
amountValue = [amountValue];
|
|
221
|
+
}
|
|
222
|
+
switch (ruleDetail.operator) {
|
|
223
|
+
case '==':
|
|
224
|
+
ruleRespected = !!amountValue.some((v) => v === cartValue);
|
|
225
|
+
break;
|
|
226
|
+
case '!=':
|
|
227
|
+
ruleRespected = !!amountValue.every((v) => v !== cartValue);
|
|
228
|
+
break;
|
|
229
|
+
case '<=':
|
|
230
|
+
ruleRespected = !!amountValue.some((v) => cartValue <= v);
|
|
231
|
+
break;
|
|
232
|
+
case '>=':
|
|
233
|
+
ruleRespected = !!amountValue.some((v) => cartValue >= v);
|
|
234
|
+
break;
|
|
235
|
+
case '<':
|
|
236
|
+
ruleRespected = !!amountValue.some((v) => cartValue < v);
|
|
237
|
+
break;
|
|
238
|
+
case '>':
|
|
239
|
+
ruleRespected = !!amountValue.some((v) => cartValue > v);
|
|
240
|
+
break;
|
|
241
|
+
case 'between':
|
|
242
|
+
ruleRespected = cartValue > amountValue && cartValue < amountValue2;
|
|
243
|
+
break;
|
|
244
|
+
case 'contains':
|
|
245
|
+
ruleRespected = !!amountValue.some((v) => cartValue.toString().indexOf(v.toString()) !== -1);
|
|
246
|
+
break;
|
|
247
|
+
case 'contains-not':
|
|
248
|
+
ruleRespected = !!!amountValue.some((v) => cartValue.toString().indexOf(v.toString()) !== -1);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
console.log(error.toString());
|
|
255
|
+
}
|
|
256
|
+
return ruleRespected;
|
|
257
|
+
};
|
|
258
|
+
exports.getResultRuleDetail = getResultRuleDetail;
|
|
259
|
+
const checkAttributes = (attributeAndValues, arrDeclinationAttributes) => {
|
|
260
|
+
const parentAttributeID = attributeAndValues.value[0].parentAttribute;
|
|
261
|
+
const attributeValues = attributeAndValues.value[0].attributeOptions;
|
|
262
|
+
const operator = attributeAndValues.operator;
|
|
263
|
+
let matchingAttributes = false;
|
|
264
|
+
for (let declinationAttribute of arrDeclinationAttributes) {
|
|
265
|
+
if (!!matchingAttributes)
|
|
266
|
+
return true;
|
|
267
|
+
if (declinationAttribute.attribute_id !== parentAttributeID)
|
|
268
|
+
continue;
|
|
269
|
+
if (!!declinationAttribute.values) {
|
|
270
|
+
matchingAttributes =
|
|
271
|
+
operator === '=='
|
|
272
|
+
? attributeValues.some((attr) => declinationAttribute.values.some((value) => value.slug === attr))
|
|
273
|
+
: !!!attributeValues.some((attr) => declinationAttribute.values.some((value) => value.slug === attr));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return matchingAttributes;
|
|
277
|
+
};
|
|
278
|
+
exports.checkAttributes = checkAttributes;
|
|
279
|
+
const getCartPromoType = (discount) => {
|
|
280
|
+
return !!discount.result.action
|
|
281
|
+
? discount.result.action === IDiscountRule_1.ResultActionEnum.GET
|
|
282
|
+
? Cart_1.CartPromoAppliesToEnum.ITEMS
|
|
283
|
+
: [IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, IDiscountRule_1.ResultActionEnum.FLATERATE_SHIPPING].includes(discount.result.action)
|
|
284
|
+
? Cart_1.CartPromoAppliesToEnum.SHIPPING
|
|
285
|
+
: [
|
|
286
|
+
IDiscountRule_1.ResultActionEnum.AMOUNT_SKU,
|
|
287
|
+
IDiscountRule_1.ResultActionEnum.PERCENT_SKU,
|
|
288
|
+
IDiscountRule_1.ResultActionEnum.AMOUNT_CATEGORY,
|
|
289
|
+
IDiscountRule_1.ResultActionEnum.PERCENT_CATEGORY
|
|
290
|
+
].includes(discount.result.action)
|
|
291
|
+
? Cart_1.CartPromoAppliesToEnum.PRODUCT
|
|
292
|
+
: [IDiscountRule_1.ResultActionEnum.AMOUNT_AFTER_TAXES, IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES].includes(discount.result.action)
|
|
293
|
+
? Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES
|
|
294
|
+
: Cart_1.CartPromoAppliesToEnum.SUBTOTAL
|
|
295
|
+
: Cart_1.CartPromoAppliesToEnum.SUBTOTAL;
|
|
296
|
+
};
|
|
297
|
+
exports.getCartPromoType = getCartPromoType;
|
|
298
|
+
const checkPromoCodeEligibility = (cart, promoCode) => {
|
|
299
|
+
var _a;
|
|
300
|
+
let currentDiscountMap = [];
|
|
301
|
+
const promoType = (0, exports.getCartPromoType)(promoCode);
|
|
302
|
+
const currentPromos = (_a = (0, exports.getCartPromo)(cart)) !== null && _a !== void 0 ? _a : [];
|
|
303
|
+
if (promoType == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES &&
|
|
304
|
+
currentPromos.some((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
if (promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING && (!!cart.is_pickup || !!!cart.shipping_selected)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
if (promoType === Cart_1.CartPromoAppliesToEnum.PRODUCT &&
|
|
311
|
+
(!!promoCode.result.action_sku || !!promoCode.result.action_categories)) {
|
|
312
|
+
const itemsWherePromoApplicable = (0, exports.getResultAppliedDiscountSkus)(cart.items, promoCode);
|
|
313
|
+
if (!!!itemsWherePromoApplicable.length)
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
const rules = promoCode.rules;
|
|
317
|
+
if (!!promoCode.noExtraRules || !!!rules || !!!rules.length)
|
|
318
|
+
return true;
|
|
319
|
+
currentDiscountMap = rules.map((rule) => _checkIfRuleAppliesToCart(rule, promoCode.appliesTo, cart));
|
|
320
|
+
return _checkRuleApplicationArray(currentDiscountMap);
|
|
321
|
+
};
|
|
322
|
+
exports.checkPromoCodeEligibility = checkPromoCodeEligibility;
|
|
323
|
+
const getTierPricingToApply = (tierPricingToCheck, qte) => {
|
|
324
|
+
if (!!!tierPricingToCheck)
|
|
325
|
+
return;
|
|
326
|
+
return tierPricingToCheck.find((tp) => (0, toNumber_1.default)(tp.from) <= qte && (!!!tp.to || (0, toNumber_1.default)(tp.to) >= qte));
|
|
327
|
+
};
|
|
328
|
+
exports.getTierPricingToApply = getTierPricingToApply;
|
|
329
|
+
const applyTierPricing = (discountRule, price, space, decimals) => {
|
|
330
|
+
if (!!!discountRule.rules || !!!discountRule.rules.length)
|
|
331
|
+
return [];
|
|
332
|
+
if (!!discountRule.draft)
|
|
333
|
+
return [];
|
|
334
|
+
const rule = discountRule.rules.find((_rule) => _rule.field === IDiscountRule_1.RuleFieldEnum.QUANTITY && _rule.ruleDetails.find((detail) => detail.operator === 'between'));
|
|
335
|
+
if (!!!rule)
|
|
336
|
+
return [];
|
|
337
|
+
const details = rule.ruleDetails.find((detail) => detail.operator === 'between');
|
|
338
|
+
if (!!!details)
|
|
339
|
+
return [];
|
|
340
|
+
return [
|
|
341
|
+
{
|
|
342
|
+
from: !!!details.value[1] || !!!(0, toNumber_1.default)(details.value[1])
|
|
343
|
+
? details.value[0]
|
|
344
|
+
: (0, toNumber_1.default)(details.value[0]) < (0, toNumber_1.default)(details.value[1])
|
|
345
|
+
? details.value[0]
|
|
346
|
+
: details.value[1],
|
|
347
|
+
to: !!!details.value[1] || !!!(0, toNumber_1.default)(details.value[1])
|
|
348
|
+
? 0
|
|
349
|
+
: (0, toNumber_1.default)(details.value[0]) > (0, toNumber_1.default)(details.value[1])
|
|
350
|
+
? details.value[0]
|
|
351
|
+
: details.value[1],
|
|
352
|
+
price: (0, currency_1.calculateAmountByCurrencyAllDetails)(space, space.preferences.default.currency(), (0, round_1.default)((0, exports.applyDiscountToPrice)(Number(price), discountRule.result), !!decimals ? decimals : 2)),
|
|
353
|
+
check_attribute_value: !!discountRule.appliesTo.check_attribute_value
|
|
354
|
+
? discountRule.appliesTo.check_attribute_value
|
|
355
|
+
: '',
|
|
356
|
+
check_other_items_category: !!discountRule.appliesTo.check_other_items_category
|
|
357
|
+
? discountRule.appliesTo.check_other_items_category
|
|
358
|
+
: '',
|
|
359
|
+
name: discountRule.name
|
|
360
|
+
}
|
|
361
|
+
];
|
|
362
|
+
};
|
|
363
|
+
exports.applyTierPricing = applyTierPricing;
|
|
364
|
+
const getNewDiscountPriceFromTierPricing = (item, setOriginalPrice, originalDecli) => {
|
|
365
|
+
const tierPricingToApply = (0, exports.getTierPricingToApply)(item.tier_pricing, item.qte);
|
|
366
|
+
const currentDiscountPrice = item.discount_price;
|
|
367
|
+
const currentIsTierPricing = !!currentDiscountPrice && currentDiscountPrice.price_type === 'tierpricing';
|
|
368
|
+
const originalDiscountAmount = !!currentDiscountPrice ? currentDiscountPrice.original_amount : null;
|
|
369
|
+
let prevDiscountPrice = null;
|
|
370
|
+
if (!!currentIsTierPricing && typeof originalDiscountAmount === 'number') {
|
|
371
|
+
const { price_type, original_amount } = currentDiscountPrice, rest = __rest(currentDiscountPrice, ["price_type", "original_amount"]);
|
|
372
|
+
prevDiscountPrice = Object.assign(Object.assign({}, rest), { amount: original_amount });
|
|
373
|
+
}
|
|
374
|
+
if (!!!tierPricingToApply) {
|
|
375
|
+
if (!!setOriginalPrice && !!currentDiscountPrice) {
|
|
376
|
+
let amountToSet = item.regular_price.amount;
|
|
377
|
+
if (!!originalDecli) {
|
|
378
|
+
const calculatedPrice = (0, products_1.getLowestPrice)(Object.assign(Object.assign({}, originalDecli), { qte: item.qte }));
|
|
379
|
+
amountToSet = calculatedPrice.price.amount;
|
|
380
|
+
}
|
|
381
|
+
return Object.assign(Object.assign({}, currentDiscountPrice), { original_amount: !!originalDecli ? amountToSet : item.regular_price.amount });
|
|
382
|
+
}
|
|
383
|
+
return !!currentIsTierPricing ? prevDiscountPrice : currentDiscountPrice !== null && currentDiscountPrice !== void 0 ? currentDiscountPrice : null;
|
|
384
|
+
}
|
|
385
|
+
if (!!setOriginalPrice && !!currentDiscountPrice) {
|
|
386
|
+
return Object.assign(Object.assign({}, currentDiscountPrice), { original_amount: tierPricingToApply.price.amount });
|
|
387
|
+
}
|
|
388
|
+
return Object.assign(Object.assign(Object.assign({}, tierPricingToApply.price), { price_type: 'tierpricing' }), (!!currentDiscountPrice
|
|
389
|
+
? {
|
|
390
|
+
original_amount: typeof originalDiscountAmount === 'number' ? originalDiscountAmount : currentDiscountPrice.amount
|
|
391
|
+
}
|
|
392
|
+
: {}));
|
|
393
|
+
};
|
|
394
|
+
exports.getNewDiscountPriceFromTierPricing = getNewDiscountPriceFromTierPricing;
|
|
395
|
+
const applyDiscountRulesOnProduct = (discount_rules, amount, space) => {
|
|
396
|
+
if (!!!discount_rules || !!!discount_rules.length)
|
|
397
|
+
return undefined;
|
|
398
|
+
let discountIndex = 0;
|
|
399
|
+
let allPromo = discount_rules.filter((discount_rule) => discount_rule.discountRule_type !== 'tier-pricing');
|
|
400
|
+
let current_promo_price = Number(amount);
|
|
401
|
+
for (const discount of allPromo) {
|
|
402
|
+
if (discountIndex > 0 && !discount.is_stackable)
|
|
403
|
+
break;
|
|
404
|
+
let amountToRemove = (0, exports.isPromoAPercentage)(discount)
|
|
405
|
+
? (Number(discount.result.action_value) / 100) * current_promo_price
|
|
406
|
+
: Number(discount.result.action_value);
|
|
407
|
+
current_promo_price -= amountToRemove;
|
|
408
|
+
discountIndex++;
|
|
409
|
+
}
|
|
410
|
+
const spaceProductPrefs = space.preferences.products.get();
|
|
411
|
+
const allowNegativePrices = !!spaceProductPrefs && !!spaceProductPrefs.allow_negative_prices;
|
|
412
|
+
return current_promo_price === Number(amount)
|
|
413
|
+
? undefined
|
|
414
|
+
: current_promo_price < 0 && !!!allowNegativePrices
|
|
415
|
+
? 0
|
|
416
|
+
: current_promo_price;
|
|
417
|
+
};
|
|
418
|
+
exports.applyDiscountRulesOnProduct = applyDiscountRulesOnProduct;
|
|
419
|
+
const applyDiscountToPrice = (initial, discountResultObj) => {
|
|
420
|
+
return discountResultObj.action === 'amount'
|
|
421
|
+
? initial - Number(discountResultObj.action_value)
|
|
422
|
+
: initial * (1 - Number(discountResultObj.action_value) / 100);
|
|
423
|
+
};
|
|
424
|
+
exports.applyDiscountToPrice = applyDiscountToPrice;
|
|
425
|
+
const getSkuArrayForPromo = (valueToConvert) => {
|
|
426
|
+
if (!!Array.isArray(valueToConvert))
|
|
427
|
+
return valueToConvert;
|
|
428
|
+
return [valueToConvert];
|
|
429
|
+
};
|
|
430
|
+
exports.getSkuArrayForPromo = getSkuArrayForPromo;
|
|
431
|
+
const getResultAppliedDiscountSkus = (cartItems, promoToCheck) => {
|
|
432
|
+
var _a, _b, _c;
|
|
433
|
+
const action = (_a = promoToCheck.result.action) !== null && _a !== void 0 ? _a : '';
|
|
434
|
+
const skuArray = (0, exports.getSkuArrayForPromo)((_b = promoToCheck.result.action_sku) !== null && _b !== void 0 ? _b : []);
|
|
435
|
+
const categoryArray = (_c = promoToCheck.result.action_categories) !== null && _c !== void 0 ? _c : [];
|
|
436
|
+
const productsToApplyPromo = cartItems
|
|
437
|
+
.filter((item) => {
|
|
438
|
+
if (!!['amount_category', 'percent_category'].includes(action)) {
|
|
439
|
+
const categorySlugsToCheck = (0, exports.getItemCategorySlugArray)(item.categories);
|
|
440
|
+
return categoryArray.some((cat) => categorySlugsToCheck.includes(cat));
|
|
441
|
+
}
|
|
442
|
+
return skuArray.includes(item.sku);
|
|
443
|
+
})
|
|
444
|
+
.map((item) => item.sku);
|
|
445
|
+
return productsToApplyPromo;
|
|
446
|
+
};
|
|
447
|
+
exports.getResultAppliedDiscountSkus = getResultAppliedDiscountSkus;
|
|
448
|
+
const getItemCategorySlugArray = (itemCategories) => {
|
|
449
|
+
if (!!!itemCategories)
|
|
450
|
+
return [];
|
|
451
|
+
const orderedByLevel = (0, orderBy_1.default)(Object.entries(itemCategories), ([key, _value]) => key);
|
|
452
|
+
const lastLevelCategory = !!orderedByLevel.length ? orderedByLevel[orderedByLevel.length - 1][1] : '';
|
|
453
|
+
return lastLevelCategory.split(' > ');
|
|
454
|
+
};
|
|
455
|
+
exports.getItemCategorySlugArray = getItemCategorySlugArray;
|
|
456
|
+
const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPromos) => {
|
|
457
|
+
var _a;
|
|
458
|
+
const discountRules = !!forcedPromos
|
|
459
|
+
? ((_a = cart.discount_rules) !== null && _a !== void 0 ? _a : []).filter((d) => (!!d.created && (0, moment_1.default)((0, data_1.formatDate)(d.created)).isBefore((0, moment_1.default)((0, data_1.formatDate)(cart.paid_at)))) ||
|
|
460
|
+
(!!d.promo_code && !!d.promo_code.code) ||
|
|
461
|
+
!!!d.created)
|
|
462
|
+
: cart.discount_rules;
|
|
463
|
+
if (!!!discountRules || !!!discountRules.length) {
|
|
464
|
+
return Object.assign(Object.assign(Object.assign({}, cart), (!!cart.cart_promo_applied ? { cart_promo_applied: null } : {})), (!!cart.cart_promos_applied ? { cart_promos_applied: null } : {}));
|
|
465
|
+
}
|
|
466
|
+
let newCart = Object.assign(Object.assign(Object.assign({}, cart), (!!cart.cart_promo_applied &&
|
|
467
|
+
!!!discountRules.some((dr) => dr.id === cart.cart_promo_applied.discount_id)
|
|
468
|
+
? { cart_promo_applied: null }
|
|
469
|
+
: {})), (!!cart.cart_promos_applied
|
|
470
|
+
? {
|
|
471
|
+
cart_promos_applied: cart.cart_promos_applied.filter((promo) => discountRules.some((dr) => dr.id === promo.discount_id))
|
|
472
|
+
}
|
|
473
|
+
: {}));
|
|
474
|
+
const checkIfCanAddPromo = (promoToCheck) => {
|
|
475
|
+
const currentPromos = newCart.cart_promos_applied;
|
|
476
|
+
if (!!!currentPromos || !!!currentPromos.length)
|
|
477
|
+
return true;
|
|
478
|
+
const currentPromosHasPromo = !!currentPromos.some((e) => e.discount_id === promoToCheck.id);
|
|
479
|
+
if (!!currentPromosHasPromo)
|
|
480
|
+
return false;
|
|
481
|
+
if (!!isMultiPromo) {
|
|
482
|
+
return !!promoToCheck.is_stackable && !!currentPromos.every((x) => !!x.stackable);
|
|
483
|
+
}
|
|
484
|
+
return true;
|
|
485
|
+
};
|
|
486
|
+
const currentPromos = (0, exports.getCartPromo)(newCart);
|
|
487
|
+
if (!!currentPromos) {
|
|
488
|
+
let shouldRemovePromo = [];
|
|
489
|
+
let shouldUpdatePromo = [];
|
|
490
|
+
for (const appliedPromo of currentPromos) {
|
|
491
|
+
if (appliedPromo.applies_to === Cart_1.CartPromoAppliesToEnum.PRODUCT && !!appliedPromo.item_given) {
|
|
492
|
+
const sameInCartDiscounts = discountRules.find((d) => d.id == appliedPromo.discount_id);
|
|
493
|
+
if (!!sameInCartDiscounts) {
|
|
494
|
+
const itemsWherePromoApplicable = (0, exports.getResultAppliedDiscountSkus)(cart.items, sameInCartDiscounts);
|
|
495
|
+
if (!!!itemsWherePromoApplicable.length && !!appliedPromo.discount_id) {
|
|
496
|
+
shouldRemovePromo.push(appliedPromo.discount_id);
|
|
497
|
+
}
|
|
498
|
+
else if (itemsWherePromoApplicable.length !== appliedPromo.item_given.length) {
|
|
499
|
+
shouldUpdatePromo.push(Object.assign(Object.assign({}, appliedPromo), { item_given: itemsWherePromoApplicable }));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
newCart = Object.assign(Object.assign({}, newCart), (!!newCart.cart_promos_applied
|
|
505
|
+
? {
|
|
506
|
+
cart_promos_applied: newCart.cart_promos_applied
|
|
507
|
+
.filter((promo) => !shouldRemovePromo.includes(promo.discount_id))
|
|
508
|
+
.map((promo) => {
|
|
509
|
+
if (!!!shouldUpdatePromo.length)
|
|
510
|
+
return promo;
|
|
511
|
+
const sameInUpdated = shouldUpdatePromo.find((p) => p.discount_id == promo.discount_id);
|
|
512
|
+
return sameInUpdated !== null && sameInUpdated !== void 0 ? sameInUpdated : promo;
|
|
513
|
+
})
|
|
514
|
+
}
|
|
515
|
+
: {}));
|
|
516
|
+
}
|
|
517
|
+
for (const discount of discountRules) {
|
|
518
|
+
if (!!discount.promo_code && !!discount.promo_code.code) {
|
|
519
|
+
const promoCodeInCart = (currentPromos || []).find((p) => p.discount_id == discount.id);
|
|
520
|
+
if (!!promoCodeInCart) {
|
|
521
|
+
const shouldStillApplyCode = (0, exports.checkPromoCodeEligibility)(newCart, discount);
|
|
522
|
+
if (!!!shouldStillApplyCode) {
|
|
523
|
+
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!newCart.cart_promo_applied && newCart.cart_promo_applied.discount_id === discount.id
|
|
524
|
+
? { cart_promo_applied: null }
|
|
525
|
+
: {})), (!!newCart.cart_promos_applied
|
|
526
|
+
? {
|
|
527
|
+
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
528
|
+
}
|
|
529
|
+
: {}));
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const promoType = (0, exports.getCartPromoType)(discount);
|
|
535
|
+
let currentDiscountMap = [];
|
|
536
|
+
if (promoType == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES &&
|
|
537
|
+
((0, exports.getCartPromo)(newCart) || []).some((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES && p.discount_id != discount.id)) {
|
|
538
|
+
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, false]];
|
|
539
|
+
}
|
|
540
|
+
else if (promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING &&
|
|
541
|
+
(!!cart.is_pickup || !!!cart.shipping_selected) &&
|
|
542
|
+
!!!forceShipping) {
|
|
543
|
+
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, false]];
|
|
544
|
+
}
|
|
545
|
+
else if (!!!discount.rules || !!!discount.rules.length) {
|
|
546
|
+
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, true]];
|
|
547
|
+
}
|
|
548
|
+
else if (!!discount.draft) {
|
|
549
|
+
currentDiscountMap = [[IDiscountRule_1.RuleConditionEnum.AND, true]];
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
currentDiscountMap = discount.rules.map((rule) => _checkIfRuleAppliesToCart(rule, discount.appliesTo, cart));
|
|
553
|
+
}
|
|
554
|
+
if (_checkRuleApplicationArray(currentDiscountMap)) {
|
|
555
|
+
if (discount.draft) {
|
|
556
|
+
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!newCart.cart_promo_applied && newCart.cart_promo_applied.discount_id === discount.id
|
|
557
|
+
? { cart_promo_applied: null }
|
|
558
|
+
: {})), (!!newCart.cart_promos_applied
|
|
559
|
+
? {
|
|
560
|
+
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
561
|
+
}
|
|
562
|
+
: {}));
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
if (promoType === Cart_1.CartPromoAppliesToEnum.PRODUCT &&
|
|
566
|
+
(!!discount.result.action_sku || !!discount.result.action_categories)) {
|
|
567
|
+
const productsToApplyPromo = (0, exports.getResultAppliedDiscountSkus)(cart.items, discount);
|
|
568
|
+
if (!!productsToApplyPromo.length) {
|
|
569
|
+
const newPromo = Object.assign({ promo_name: (0, locale_1.getLocaleOfDictionnary)(discount.name, cart.locale), applies_to: promoType, amount_removed: Number(discount.result.action_value), amount_unit: discount.result.action, item_given: productsToApplyPromo, item_given_amount: 0, free_shipping: discount.result.action === IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, flatrate_shipping: 0, stackable: discount.is_stackable, discount_id: discount.id, promo_code: !!discount.promo_code ? discount.promo_code.code : undefined }, (typeof discount.result.exclude_services_and_fees === 'boolean'
|
|
570
|
+
? {
|
|
571
|
+
exclude_services_and_fees: discount.result.exclude_services_and_fees
|
|
572
|
+
}
|
|
573
|
+
: {}));
|
|
574
|
+
if (!!checkIfCanAddPromo(discount)) {
|
|
575
|
+
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [...(newCart.cart_promos_applied || []), newPromo] });
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!newCart.cart_promo_applied && newCart.cart_promo_applied.discount_id === discount.id
|
|
580
|
+
? { cart_promo_applied: null }
|
|
581
|
+
: {})), (!!newCart.cart_promos_applied
|
|
582
|
+
? {
|
|
583
|
+
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
584
|
+
}
|
|
585
|
+
: {}));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
const newPromo = Object.assign({ promo_name: (0, locale_1.getLocaleOfDictionnary)(discount.name, cart.locale), applies_to: promoType, amount_removed: promoType !== Cart_1.CartPromoAppliesToEnum.SHIPPING ? Number(discount.result.action_value) : 0, amount_unit: discount.result.action, item_given: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS ? discount.result.action_value.toString() : '', item_given_amount: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS && !!discount.result.action_qte
|
|
590
|
+
? Number(discount.result.action_qte)
|
|
591
|
+
: 0, stackable: discount.is_stackable, discount_id: discount.id, free_shipping: discount.result.action === IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, flatrate_shipping: promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING &&
|
|
592
|
+
discount.result.action === IDiscountRule_1.ResultActionEnum.FLATERATE_SHIPPING
|
|
593
|
+
? Number(discount.result.action_value)
|
|
594
|
+
: 0, promo_code: !!discount.promo_code ? discount.promo_code.code : undefined }, (typeof discount.result.exclude_services_and_fees === 'boolean'
|
|
595
|
+
? {
|
|
596
|
+
exclude_services_and_fees: discount.result.exclude_services_and_fees
|
|
597
|
+
}
|
|
598
|
+
: {}));
|
|
599
|
+
if (!!checkIfCanAddPromo(discount)) {
|
|
600
|
+
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [...(newCart.cart_promos_applied || []), newPromo] });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
newCart = Object.assign(Object.assign(Object.assign({}, newCart), (!!cart.cart_promo_applied && cart.cart_promo_applied.discount_id === discount.id
|
|
607
|
+
? { cart_promo_applied: null }
|
|
608
|
+
: {})), (!!newCart.cart_promos_applied
|
|
609
|
+
? {
|
|
610
|
+
cart_promos_applied: newCart.cart_promos_applied.filter((p) => p.discount_id !== discount.id)
|
|
611
|
+
}
|
|
612
|
+
: {}));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (!!newCart.cart_promos_applied && !!isMultiPromo) {
|
|
616
|
+
const shippingPromo = newCart.cart_promos_applied.filter((x) => x.applies_to === Cart_1.CartPromoAppliesToEnum.SHIPPING);
|
|
617
|
+
if (!!shippingPromo && !!shippingPromo.length) {
|
|
618
|
+
let flatPrice = 1000000;
|
|
619
|
+
let promo = 0;
|
|
620
|
+
for (let i = 0; i < shippingPromo.length; i++) {
|
|
621
|
+
if (shippingPromo[i].amount_unit === 'free_shipping') {
|
|
622
|
+
promo = i;
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
if (!!shippingPromo[i].flatrate_shipping && shippingPromo[i].flatrate_shipping < flatPrice) {
|
|
626
|
+
promo = i;
|
|
627
|
+
flatPrice = shippingPromo[i].flatrate_shipping;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const promoSansShipping = newCart.cart_promos_applied.filter((x) => x.applies_to !== Cart_1.CartPromoAppliesToEnum.SHIPPING);
|
|
631
|
+
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [...promoSansShipping, shippingPromo[promo]] });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (!!forcedPromos && !!forcedPromos.length) {
|
|
635
|
+
const appliedPromos = !!newCart.cart_promos_applied && !!newCart.cart_promos_applied.length
|
|
636
|
+
? newCart.cart_promos_applied.map((p) => p.discount_id)
|
|
637
|
+
: [];
|
|
638
|
+
const newForcedPromos = forcedPromos.filter((f) => !!!appliedPromos.includes(f.discount_id));
|
|
639
|
+
newCart = Object.assign(Object.assign({}, newCart), { cart_promos_applied: [
|
|
640
|
+
...(!!newCart.cart_promos_applied && !!newCart.cart_promos_applied.length ? newCart.cart_promos_applied : []),
|
|
641
|
+
...newForcedPromos
|
|
642
|
+
] });
|
|
643
|
+
}
|
|
644
|
+
return Object.assign(Object.assign({}, newCart), { free_shipping: !!newCart.cart_promos_applied
|
|
645
|
+
? newCart.cart_promos_applied.some((p) => !!p.free_shipping)
|
|
646
|
+
: !!newCart.cart_promo_applied && newCart.cart_promo_applied.free_shipping });
|
|
647
|
+
};
|
|
648
|
+
exports.applyDiscountToCart = applyDiscountToCart;
|
|
649
|
+
const getStandardCartPromoFromDiscount = (cart, discount) => {
|
|
650
|
+
const promoType = (0, exports.getCartPromoType)(discount);
|
|
651
|
+
return Object.assign({ promo_name: (0, locale_1.getLocaleOfDictionnary)(discount.name, cart.locale), applies_to: promoType, amount_removed: promoType !== Cart_1.CartPromoAppliesToEnum.SHIPPING ? Number(discount.result.action_value) : 0, amount_unit: discount.result.action, item_given: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS ? discount.result.action_value.toString() : '', item_given_amount: promoType === Cart_1.CartPromoAppliesToEnum.ITEMS && !!discount.result.action_qte
|
|
652
|
+
? Number(discount.result.action_qte)
|
|
653
|
+
: 0, stackable: discount.is_stackable, discount_id: discount.id, free_shipping: discount.result.action === IDiscountRule_1.ResultActionEnum.FREE_SHIPPING, flatrate_shipping: promoType === Cart_1.CartPromoAppliesToEnum.SHIPPING && discount.result.action === IDiscountRule_1.ResultActionEnum.FLATERATE_SHIPPING
|
|
654
|
+
? Number(discount.result.action_value)
|
|
655
|
+
: 0, promo_code: !!discount.promo_code ? discount.promo_code.code : undefined }, (typeof discount.result.exclude_services_and_fees === 'boolean'
|
|
656
|
+
? {
|
|
657
|
+
exclude_services_and_fees: discount.result.exclude_services_and_fees
|
|
658
|
+
}
|
|
659
|
+
: {}));
|
|
660
|
+
};
|
|
661
|
+
exports.getStandardCartPromoFromDiscount = getStandardCartPromoFromDiscount;
|
|
662
|
+
const getOnlyServicesAndFeesSubtotal = (cartData, allCurrentAppliedToItemPromos) => {
|
|
663
|
+
let servicesAndFeesTotal = 0;
|
|
664
|
+
cartData.items.forEach((i) => {
|
|
665
|
+
if (!!!i.is_service || !!(0, g2_1.isEscompteSuppItem)(i.sku))
|
|
666
|
+
return;
|
|
667
|
+
const associatedPromos = allCurrentAppliedToItemPromos.filter((p) => { var _a; return (0, exports.getSkuArrayForPromo)((_a = p.item_given) !== null && _a !== void 0 ? _a : []).includes(i.sku); });
|
|
668
|
+
servicesAndFeesTotal += (0, round_1.default)(i.qte * (0, products_1.getLowestPrice)(i).price.amount, 3);
|
|
669
|
+
if (!!associatedPromos.length) {
|
|
670
|
+
for (const promo of associatedPromos) {
|
|
671
|
+
if (!!!promo.amount_removed)
|
|
672
|
+
continue;
|
|
673
|
+
if ((0, exports.isPromoAPercentage)(promo, { defaultToPercent: true })) {
|
|
674
|
+
servicesAndFeesTotal -= (0, round_1.default)((promo.amount_removed / 100) * (i.qte * (0, products_1.getLowestPrice)(i).price.amount), 3);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
servicesAndFeesTotal -= promo.amount_removed * i.qte;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
return servicesAndFeesTotal;
|
|
683
|
+
};
|
|
684
|
+
exports.getOnlyServicesAndFeesSubtotal = getOnlyServicesAndFeesSubtotal;
|
|
685
|
+
const _checkIfRuleAppliesToCart = (rule, appliesTo, cart) => {
|
|
686
|
+
var _a;
|
|
687
|
+
const todayDate = (0, moment_1.default)().toDate();
|
|
688
|
+
const ruleCondition = (_a = rule.condition) !== null && _a !== void 0 ? _a : IDiscountRule_1.RuleConditionEnum.AND;
|
|
689
|
+
switch (rule.field) {
|
|
690
|
+
case IDiscountRule_1.RuleFieldEnum.CART_TOTAL:
|
|
691
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
692
|
+
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, cart.subtotal)];
|
|
693
|
+
}));
|
|
694
|
+
case IDiscountRule_1.RuleFieldEnum.CART_ITEM_TOTAL:
|
|
695
|
+
let totalCartItems = (0, sumBy_1.default)(cart.items, (item) => item.qte);
|
|
696
|
+
if (!!appliesTo.check_other_items_category) {
|
|
697
|
+
const correspondingCartItems = cart.items.filter((item) => {
|
|
698
|
+
if (!!item.tier_pricing && !!item.tier_pricing.length) {
|
|
699
|
+
return (!!item.tier_pricing[0].check_other_items_category &&
|
|
700
|
+
item.tier_pricing[0].check_other_items_category === appliesTo.check_other_items_category);
|
|
701
|
+
}
|
|
702
|
+
return false;
|
|
703
|
+
});
|
|
704
|
+
totalCartItems = (0, sumBy_1.default)(correspondingCartItems, (item) => {
|
|
705
|
+
let amountInBox = 1;
|
|
706
|
+
const qte = item.qte;
|
|
707
|
+
if (!!item.attributes['8OUv9qj0aDbiLOovd4dp']) {
|
|
708
|
+
amountInBox = Number(item.attributes['8OUv9qj0aDbiLOovd4dp']);
|
|
709
|
+
}
|
|
710
|
+
return amountInBox * qte;
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
714
|
+
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, totalCartItems)];
|
|
715
|
+
}));
|
|
716
|
+
case IDiscountRule_1.RuleFieldEnum.CART_ITEM:
|
|
717
|
+
if (!!cart) {
|
|
718
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
719
|
+
if (ruleDetail.operator === 'contains') {
|
|
720
|
+
return [ruleCondition, ruleDetail.value.every((v) => !!cart.items.some((item) => item.sku === v))];
|
|
721
|
+
}
|
|
722
|
+
return [ruleCondition, !!!cart.items.find((item) => !!ruleDetail.value.find((v) => v === item.sku))];
|
|
723
|
+
}));
|
|
724
|
+
}
|
|
725
|
+
case IDiscountRule_1.RuleFieldEnum.CUSTOMER:
|
|
726
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
727
|
+
return [ruleCondition, cart.customer_id === ruleDetail.value[0]];
|
|
728
|
+
}));
|
|
729
|
+
case IDiscountRule_1.RuleFieldEnum.CUSTOMER_TYPE:
|
|
730
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
731
|
+
if (ruleDetail.operator === '!=') {
|
|
732
|
+
return [
|
|
733
|
+
ruleCondition,
|
|
734
|
+
(!!cart.customer_info && !!!cart.customer_info.pro_title) ||
|
|
735
|
+
(!!cart.customer_info &&
|
|
736
|
+
!!cart.customer_info.pro_title &&
|
|
737
|
+
!!!ruleDetail.value.includes(cart.customer_info.pro_title))
|
|
738
|
+
];
|
|
739
|
+
}
|
|
740
|
+
return [
|
|
741
|
+
ruleCondition,
|
|
742
|
+
!!cart.customer_info &&
|
|
743
|
+
!!cart.customer_info.pro_title &&
|
|
744
|
+
!!ruleDetail.value.includes(cart.customer_info.pro_title)
|
|
745
|
+
];
|
|
746
|
+
}));
|
|
747
|
+
case IDiscountRule_1.RuleFieldEnum.DATE:
|
|
748
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
749
|
+
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, todayDate)];
|
|
750
|
+
}));
|
|
751
|
+
case IDiscountRule_1.RuleFieldEnum.WEEKDAY:
|
|
752
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
753
|
+
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, todayDate)];
|
|
754
|
+
}));
|
|
755
|
+
case IDiscountRule_1.RuleFieldEnum.CART_PLATFORM:
|
|
756
|
+
const cartPlatform = !![Cart_1.CartTypeEnum.POS, Cart_1.CartTypeEnum.POS_TRANSACTIONNAL].includes(cart.cart_type)
|
|
757
|
+
? Cart_1.CartTypeEnum.POS
|
|
758
|
+
: Cart_1.CartTypeEnum.WEB;
|
|
759
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
760
|
+
return [ruleCondition, (0, exports.getResultRuleDetail)(ruleDetail, cartPlatform)];
|
|
761
|
+
}));
|
|
762
|
+
case IDiscountRule_1.RuleFieldEnum.CART_TYPE:
|
|
763
|
+
const cartType = cart.cart_content_type === Cart_1.CartContentTypeEnum.MIXED
|
|
764
|
+
? Cart_1.CartContentTypeEnum.MIXED
|
|
765
|
+
: !!(0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.INSTALLATION, cart)
|
|
766
|
+
? cart_2.CartGeneralTypeEnum.INSTALLATION
|
|
767
|
+
: (0, cart_1.getCartType)(cart);
|
|
768
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
769
|
+
let result = (0, exports.getResultRuleDetail)(ruleDetail, cartType);
|
|
770
|
+
for (const value of ruleDetail.value) {
|
|
771
|
+
if (value === cart_2.CartGeneralTypeEnum.GRASS && cartType === cart_2.CartGeneralTypeEnum.INSTALLATION)
|
|
772
|
+
result = true;
|
|
773
|
+
}
|
|
774
|
+
return [ruleCondition, result];
|
|
775
|
+
}));
|
|
776
|
+
case IDiscountRule_1.RuleFieldEnum.CART_ITEM_CATEGORIES:
|
|
777
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
778
|
+
let result = ruleDetail.operator !== 'contains';
|
|
779
|
+
for (const i of cart.items) {
|
|
780
|
+
const categorySlugsToCheck = (0, exports.getItemCategorySlugArray)(i.categories);
|
|
781
|
+
if (!!categorySlugsToCheck.length) {
|
|
782
|
+
for (const ruleValue of ruleDetail.value) {
|
|
783
|
+
if (!!categorySlugsToCheck.includes(ruleValue))
|
|
784
|
+
result = ruleDetail.operator !== 'contains' ? false : true;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return [ruleCondition, result];
|
|
789
|
+
}));
|
|
790
|
+
case IDiscountRule_1.RuleFieldEnum.ORDER_DAY:
|
|
791
|
+
const order_day_day = !!cart.shipping_payload && !!cart.shipping_payload.delivery_or_pickup_date
|
|
792
|
+
? cart.shipping_payload.delivery_or_pickup_date
|
|
793
|
+
: '';
|
|
794
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
795
|
+
return [ruleCondition, !!order_day_day ? (0, exports.getResultRuleDetail)(ruleDetail, (0, moment_1.default)(order_day_day).day()) : false];
|
|
796
|
+
}));
|
|
797
|
+
case IDiscountRule_1.RuleFieldEnum.ORDER_TYPE:
|
|
798
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
799
|
+
return [
|
|
800
|
+
ruleCondition,
|
|
801
|
+
!!cart.is_pickup
|
|
802
|
+
? ruleDetail.operator === '=='
|
|
803
|
+
? !!ruleDetail.value.includes('pickup')
|
|
804
|
+
: !!!ruleDetail.value.includes('pickup')
|
|
805
|
+
: ruleDetail.operator === '=='
|
|
806
|
+
? !!ruleDetail.value.includes('shipping')
|
|
807
|
+
: !!!ruleDetail.value.includes('shipping')
|
|
808
|
+
];
|
|
809
|
+
}));
|
|
810
|
+
case IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD:
|
|
811
|
+
if (cart.custom_payment_type &&
|
|
812
|
+
cart.custom_payment_type.method == Cart_1.CustomPaymentTypeEnum.INCENTIVE) {
|
|
813
|
+
return [ruleCondition, true];
|
|
814
|
+
}
|
|
815
|
+
const paymentTypesToCompare = !!cart.custom_payment_type
|
|
816
|
+
? [cart.custom_payment_type.method]
|
|
817
|
+
: !!(0, object_1.recursiveCheckObject)(cart, 'shipping_payload.chosen_payment')
|
|
818
|
+
? [(0, object_1.recursiveCheckObject)(cart, 'shipping_payload.chosen_payment')]
|
|
819
|
+
: !!cart.payment_details && cart.payment_details.length
|
|
820
|
+
? cart.payment_details.map((p) => p.method)
|
|
821
|
+
: !!cart.paid_by
|
|
822
|
+
? [cart.paid_by]
|
|
823
|
+
: [];
|
|
824
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
825
|
+
let result = ruleDetail.operator == 'contains'
|
|
826
|
+
? paymentTypesToCompare.some((type) => ruleDetail.value.includes(type))
|
|
827
|
+
: !paymentTypesToCompare.every((type) => ruleDetail.value.includes(type));
|
|
828
|
+
return [ruleCondition, result];
|
|
829
|
+
}));
|
|
830
|
+
case IDiscountRule_1.RuleFieldEnum.CUSTOMER_TERMS_CODE:
|
|
831
|
+
let customerTermsCode = (0, object_1.recursiveCheckObject)(cart, 'customer_info.terms_code');
|
|
832
|
+
let customerPrevTermsCode = (0, object_1.recursiveCheckObject)(cart, 'customer_info.previous_terms_code');
|
|
833
|
+
let trueTermsCode = customerTermsCode == 'HOLD' ? 'HOLD' : customerPrevTermsCode !== null && customerPrevTermsCode !== void 0 ? customerPrevTermsCode : customerTermsCode;
|
|
834
|
+
let termsCodeToCheck = !!!trueTermsCode
|
|
835
|
+
? undefined
|
|
836
|
+
: data_2.allCodesForHold.includes(trueTermsCode)
|
|
837
|
+
? 'HOLD'
|
|
838
|
+
: data_2.allCodesForPSL.includes(trueTermsCode)
|
|
839
|
+
? 'P.S.L'
|
|
840
|
+
: 'NET30';
|
|
841
|
+
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
842
|
+
let operator = ruleDetail.operator;
|
|
843
|
+
if (!!!termsCodeToCheck)
|
|
844
|
+
return [IDiscountRule_1.RuleConditionEnum.AND, operator == '!='];
|
|
845
|
+
return [
|
|
846
|
+
ruleCondition,
|
|
847
|
+
operator == '=='
|
|
848
|
+
? ruleDetail.value.includes(termsCodeToCheck)
|
|
849
|
+
: !ruleDetail.value.includes(termsCodeToCheck)
|
|
850
|
+
];
|
|
851
|
+
}));
|
|
852
|
+
default:
|
|
853
|
+
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
const _checkRuleApplicationArray = (checkedRulesApplicationArray) => {
|
|
857
|
+
return ((checkedRulesApplicationArray.some((option) => !!option && option.indexOf(IDiscountRule_1.RuleConditionEnum.OR) !== -1) &&
|
|
858
|
+
checkedRulesApplicationArray.some((option) => !!option && option.indexOf(true) !== -1)) ||
|
|
859
|
+
(checkedRulesApplicationArray.some((option) => !!option && option.indexOf(IDiscountRule_1.RuleConditionEnum.AND) !== -1) &&
|
|
860
|
+
!checkedRulesApplicationArray.some((option) => !!option && option.indexOf(false) !== -1)));
|
|
861
|
+
};
|
|
862
|
+
const checkIfCouldApplyIncentivePromo = (cartData, skipCheckFor = []) => {
|
|
863
|
+
let afterTaxesPromo = cartData.discount_rules.find((d) => !d.draft &&
|
|
864
|
+
(d.result.action == IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES ||
|
|
865
|
+
d.result.action == IDiscountRule_1.ResultActionEnum.AMOUNT_AFTER_TAXES));
|
|
866
|
+
if (!!!afterTaxesPromo)
|
|
867
|
+
return false;
|
|
868
|
+
if (!!!afterTaxesPromo.rules || afterTaxesPromo.rules.length == 0)
|
|
869
|
+
return true;
|
|
870
|
+
const appliesTo = afterTaxesPromo.appliesTo;
|
|
871
|
+
const canApply = afterTaxesPromo.rules.map((r) => {
|
|
872
|
+
if (r.field && skipCheckFor.includes(r.field))
|
|
873
|
+
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
874
|
+
return _checkIfRuleAppliesToCart(r, appliesTo, cartData);
|
|
875
|
+
});
|
|
876
|
+
return _checkRuleApplicationArray(canApply);
|
|
877
|
+
};
|
|
878
|
+
exports.checkIfCouldApplyIncentivePromo = checkIfCouldApplyIncentivePromo;
|
|
879
|
+
const getAfterTaxesPromosTotalAmount = (cartData, checkDiscountRules) => {
|
|
880
|
+
let currentSubtotal = cartData.subtotal;
|
|
881
|
+
let afterTaxesPromo = (0, exports.getAfterTaxesPromoInCart)(cartData, checkDiscountRules);
|
|
882
|
+
let totalAmountForAfterTaxesPromos = 0;
|
|
883
|
+
if (!!afterTaxesPromo && !!afterTaxesPromo.amount_removed) {
|
|
884
|
+
if ((0, exports.isPromoAPercentage)(afterTaxesPromo, { includePaymentIncentiveInCheck: true })) {
|
|
885
|
+
totalAmountForAfterTaxesPromos += currentSubtotal * (afterTaxesPromo.amount_removed / 100);
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
totalAmountForAfterTaxesPromos += afterTaxesPromo.amount_removed;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return totalAmountForAfterTaxesPromos;
|
|
892
|
+
};
|
|
893
|
+
exports.getAfterTaxesPromosTotalAmount = getAfterTaxesPromosTotalAmount;
|
|
894
|
+
const getAfterTaxesPromoInCart = (cartData, checkDiscountRules) => {
|
|
895
|
+
var _a;
|
|
896
|
+
let cartPromos = (_a = (0, exports.getCartPromo)(cartData)) !== null && _a !== void 0 ? _a : [];
|
|
897
|
+
let incentivePromo = cartPromos.find((p) => p.applies_to === Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
|
|
898
|
+
let discountIncentive = (0, exports.getPaymentIncentiveDiscount)(cartData.discount_rules);
|
|
899
|
+
if (!!checkDiscountRules &&
|
|
900
|
+
!!discountIncentive &&
|
|
901
|
+
(!!!incentivePromo || discountIncentive.result.action_value != incentivePromo.amount_removed)) {
|
|
902
|
+
incentivePromo = (0, exports.getStandardCartPromoFromDiscount)(cartData, discountIncentive);
|
|
903
|
+
}
|
|
904
|
+
return incentivePromo;
|
|
905
|
+
};
|
|
906
|
+
exports.getAfterTaxesPromoInCart = getAfterTaxesPromoInCart;
|
|
907
|
+
const getPaymentIncentiveDiscountInfo = (cartData, checkForAllPaidByDiscounts) => {
|
|
908
|
+
let appliesToPaymentTypes = undefined;
|
|
909
|
+
let paymentIncentiveDiscount = (0, exports.getPaymentIncentiveDiscount)(cartData.discount_rules);
|
|
910
|
+
if (!!!paymentIncentiveDiscount) {
|
|
911
|
+
if (!!checkForAllPaidByDiscounts)
|
|
912
|
+
paymentIncentiveDiscount = cartData.discount_rules.find((d) => (d.rules || []).some((r) => r.field == IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD));
|
|
913
|
+
if (!!!paymentIncentiveDiscount)
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
let ruleForPaymentType = (paymentIncentiveDiscount.rules || []).find((rule) => rule.field == IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD);
|
|
917
|
+
if (!!ruleForPaymentType) {
|
|
918
|
+
appliesToPaymentTypes = {
|
|
919
|
+
amount: (0, toNumber_1.default)(paymentIncentiveDiscount.result.action_value),
|
|
920
|
+
isPercent: (0, exports.isPromoAPercentage)(paymentIncentiveDiscount, { includePaymentIncentiveInCheck: true }),
|
|
921
|
+
paymentTypes: (0, flatten_1.default)(ruleForPaymentType.ruleDetails.map((d) => (0, flatten_1.default)(d.value)))
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
return appliesToPaymentTypes;
|
|
925
|
+
};
|
|
926
|
+
exports.getPaymentIncentiveDiscountInfo = getPaymentIncentiveDiscountInfo;
|
|
927
|
+
const getPaymentIncentiveDiscount = (discountRules) => {
|
|
928
|
+
if (!!!discountRules)
|
|
929
|
+
return;
|
|
930
|
+
let paymentIncentiveDiscount = discountRules.find((d) => !!d.result.action &&
|
|
931
|
+
[IDiscountRule_1.ResultActionEnum.AMOUNT_AFTER_TAXES, IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES].includes(d.result.action));
|
|
932
|
+
return paymentIncentiveDiscount;
|
|
933
|
+
};
|
|
934
|
+
exports.getPaymentIncentiveDiscount = getPaymentIncentiveDiscount;
|
|
935
935
|
//# sourceMappingURL=discount.js.map
|