addio-admin-sdk 1.7.103 → 1.7.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Interfaces/Attribute/index.d.ts +1 -0
- package/dist/Interfaces/CMS/index.d.ts +3 -0
- package/dist/Interfaces/CMS/index.js +3 -0
- package/dist/Interfaces/CMS/index.js.map +1 -1
- package/dist/Interfaces/Cart/index.js +6 -2
- package/dist/Interfaces/Cart/index.js.map +1 -1
- package/dist/Interfaces/CartReservedQuantities/index.d.ts +2 -0
- package/dist/Interfaces/Customer/IStoreCredit.d.ts +1 -0
- package/dist/Interfaces/Customer/index.d.ts +7 -0
- package/dist/Interfaces/Customer/index.js +7 -0
- package/dist/Interfaces/Customer/index.js.map +1 -1
- package/dist/Interfaces/Declination/index.js +8 -2
- package/dist/Interfaces/Declination/index.js.map +1 -1
- package/dist/Interfaces/Email/IEmail.js +7 -3
- package/dist/Interfaces/Email/IEmail.js.map +1 -1
- package/dist/Interfaces/G2/index.js +2 -0
- package/dist/Interfaces/G2/index.js.map +1 -1
- package/dist/Interfaces/Indexed/Product/index.d.ts +3 -0
- package/dist/Interfaces/Indexed/Product/index.js +43 -2
- package/dist/Interfaces/Indexed/Product/index.js.map +1 -1
- package/dist/Interfaces/Menu/index.d.ts +11 -0
- package/dist/Interfaces/Product/IImportProduct.js +94 -3
- package/dist/Interfaces/Product/IImportProduct.js.map +1 -1
- package/dist/Interfaces/Product/IInventoryItem.d.ts +11 -27
- package/dist/Interfaces/Product/IInventoryItem.js +13 -4
- package/dist/Interfaces/Product/IInventoryItem.js.map +1 -1
- package/dist/Interfaces/Product/IPricing.js +6 -0
- package/dist/Interfaces/Product/IPricing.js.map +1 -1
- package/dist/Interfaces/Product/index.d.ts +8 -0
- package/dist/Interfaces/Product/index.js +8 -0
- package/dist/Interfaces/Product/index.js.map +1 -1
- package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +1 -1
- package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js.map +1 -1
- package/dist/Interfaces/Rules/IDiscountRule.d.ts +18 -0
- package/dist/Interfaces/Rules/IDiscountRule.js +19 -0
- package/dist/Interfaces/Rules/IDiscountRule.js.map +1 -1
- package/dist/Interfaces/Services/IService.d.ts +4 -0
- package/dist/Interfaces/Shipping/Shiptime/order.js +23 -0
- package/dist/Interfaces/Shipping/Shiptime/order.js.map +1 -1
- package/dist/Interfaces/Space/index.d.ts +8 -0
- package/dist/Interfaces/Space/index.js +9 -0
- package/dist/Interfaces/Space/index.js.map +1 -1
- package/dist/Interfaces/TCG/index.d.ts +12 -1
- package/dist/Interfaces/TCG/index.js +11 -0
- package/dist/Interfaces/TCG/index.js.map +1 -1
- package/dist/Interfaces/TransferRequest/index.js +3 -0
- package/dist/Interfaces/TransferRequest/index.js.map +1 -1
- package/dist/constants/services.js +1 -0
- package/dist/constants/services.js.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/Attribute/index.js +43 -0
- package/dist/lib/Attribute/index.js.map +1 -1
- package/dist/lib/BGJob/index.js +5 -1
- package/dist/lib/BGJob/index.js.map +1 -1
- package/dist/lib/Booking/index.d.ts +15 -0
- package/dist/lib/Booking/index.js +20 -0
- package/dist/lib/Booking/index.js.map +1 -1
- package/dist/lib/Brand/index.d.ts +9 -0
- package/dist/lib/Brand/index.js +18 -0
- package/dist/lib/Brand/index.js.map +1 -1
- package/dist/lib/Cart/index.d.ts +99 -0
- package/dist/lib/Cart/index.js +498 -9
- package/dist/lib/Cart/index.js.map +1 -1
- package/dist/lib/CartReservedQuantities/index.d.ts +29 -0
- package/dist/lib/CartReservedQuantities/index.js +41 -0
- package/dist/lib/CartReservedQuantities/index.js.map +1 -1
- package/dist/lib/Catalogue/index.d.ts +6 -0
- package/dist/lib/Catalogue/index.js +9 -0
- package/dist/lib/Catalogue/index.js.map +1 -1
- package/dist/lib/Category/index.d.ts +6 -0
- package/dist/lib/Category/index.js +15 -0
- package/dist/lib/Category/index.js.map +1 -1
- package/dist/lib/Class/index.d.ts +4 -0
- package/dist/lib/Class/index.js +8 -0
- package/dist/lib/Class/index.js.map +1 -1
- package/dist/lib/Customer/index.d.ts +12 -0
- package/dist/lib/Customer/index.js +13 -0
- package/dist/lib/Customer/index.js.map +1 -1
- package/dist/lib/Declination/index.js +2 -0
- package/dist/lib/Declination/index.js.map +1 -1
- package/dist/lib/Discount/index.d.ts +9 -0
- package/dist/lib/Discount/index.js +23 -0
- package/dist/lib/Discount/index.js.map +1 -1
- package/dist/lib/ElasticSearch/index.d.ts +5 -0
- package/dist/lib/ElasticSearch/index.js +5 -0
- package/dist/lib/ElasticSearch/index.js.map +1 -1
- package/dist/lib/Elavon/index.js +5 -0
- package/dist/lib/Elavon/index.js.map +1 -1
- package/dist/lib/Email/AbandonedCartEmail.d.ts +8 -0
- package/dist/lib/Email/AbandonedCartEmail.js +8 -0
- package/dist/lib/Email/AbandonedCartEmail.js.map +1 -1
- package/dist/lib/Email/AccountConfirmationEmail.d.ts +8 -0
- package/dist/lib/Email/AccountConfirmationEmail.js +8 -0
- package/dist/lib/Email/AccountConfirmationEmail.js.map +1 -1
- package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +8 -0
- package/dist/lib/Email/AdminOrderConfirmationEmail.js +8 -0
- package/dist/lib/Email/AdminOrderConfirmationEmail.js.map +1 -1
- package/dist/lib/Email/ApplicationEmail.d.ts +8 -0
- package/dist/lib/Email/ApplicationEmail.js +8 -0
- package/dist/lib/Email/ApplicationEmail.js.map +1 -1
- package/dist/lib/Email/BackInStockEmail.d.ts +8 -0
- package/dist/lib/Email/BackInStockEmail.js +8 -0
- package/dist/lib/Email/BackInStockEmail.js.map +1 -1
- package/dist/lib/Email/ContactEmail.d.ts +8 -0
- package/dist/lib/Email/ContactEmail.js +8 -0
- package/dist/lib/Email/ContactEmail.js.map +1 -1
- package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +8 -0
- package/dist/lib/Email/CustomerBookingAdminEmail.js +8 -0
- package/dist/lib/Email/CustomerBookingAdminEmail.js.map +1 -1
- package/dist/lib/Email/CustomerBookingEmail.d.ts +8 -0
- package/dist/lib/Email/CustomerBookingEmail.js +8 -0
- package/dist/lib/Email/CustomerBookingEmail.js.map +1 -1
- package/dist/lib/Email/OrderConfirmationEmail.d.ts +8 -0
- package/dist/lib/Email/OrderConfirmationEmail.js +8 -0
- package/dist/lib/Email/OrderConfirmationEmail.js.map +1 -1
- package/dist/lib/Email/OrderDenounciationEmail.d.ts +8 -0
- package/dist/lib/Email/OrderDenounciationEmail.js +8 -0
- package/dist/lib/Email/OrderDenounciationEmail.js.map +1 -1
- package/dist/lib/Email/OrderSampleEmail.d.ts +8 -0
- package/dist/lib/Email/OrderSampleEmail.js +8 -0
- package/dist/lib/Email/OrderSampleEmail.js.map +1 -1
- package/dist/lib/Email/OtherTypeEmails.d.ts +8 -0
- package/dist/lib/Email/OtherTypeEmails.js +8 -0
- package/dist/lib/Email/OtherTypeEmails.js.map +1 -1
- package/dist/lib/Email/PasswordResetEmail.d.ts +8 -0
- package/dist/lib/Email/PasswordResetEmail.js +8 -0
- package/dist/lib/Email/PasswordResetEmail.js.map +1 -1
- package/dist/lib/Email/PhotoShootEmail.d.ts +8 -0
- package/dist/lib/Email/PhotoShootEmail.js +8 -0
- package/dist/lib/Email/PhotoShootEmail.js.map +1 -1
- package/dist/lib/Email/PickUpConfirmation.d.ts +8 -0
- package/dist/lib/Email/PickUpConfirmation.js +8 -0
- package/dist/lib/Email/PickUpConfirmation.js.map +1 -1
- package/dist/lib/Email/ShippingConfirmation.d.ts +8 -0
- package/dist/lib/Email/ShippingConfirmation.js +8 -0
- package/dist/lib/Email/ShippingConfirmation.js.map +1 -1
- package/dist/lib/Email/WelcomeEmail.d.ts +8 -0
- package/dist/lib/Email/WelcomeEmail.js +8 -0
- package/dist/lib/Email/WelcomeEmail.js.map +1 -1
- package/dist/lib/Email/index.d.ts +8 -0
- package/dist/lib/Email/index.js +8 -0
- package/dist/lib/Email/index.js.map +1 -1
- package/dist/lib/ExternalService/Ebay.d.ts +12 -0
- package/dist/lib/ExternalService/Ebay.js +22 -0
- package/dist/lib/ExternalService/Ebay.js.map +1 -1
- package/dist/lib/Indexed/IndexedCart.js +5 -0
- package/dist/lib/Indexed/IndexedCart.js.map +1 -1
- package/dist/lib/Indexed/Product.js +50 -0
- package/dist/lib/Indexed/Product.js.map +1 -1
- package/dist/lib/Inventory/index.d.ts +59 -0
- package/dist/lib/Inventory/index.js +157 -9
- package/dist/lib/Inventory/index.js.map +1 -1
- package/dist/lib/Invoice/index.d.ts +11 -0
- package/dist/lib/Invoice/index.js +11 -0
- package/dist/lib/Invoice/index.js.map +1 -1
- package/dist/lib/MarketplacePublication/index.js +308 -0
- package/dist/lib/MarketplacePublication/index.js.map +1 -1
- package/dist/lib/Menu/index.js +2 -0
- package/dist/lib/Menu/index.js.map +1 -1
- package/dist/lib/Order/index.d.ts +20 -0
- package/dist/lib/Order/index.js +23 -0
- package/dist/lib/Order/index.js.map +1 -1
- package/dist/lib/Org/index.d.ts +41 -0
- package/dist/lib/Org/index.js +41 -0
- package/dist/lib/Org/index.js.map +1 -1
- package/dist/lib/PandaPay/index.js +6 -0
- package/dist/lib/PandaPay/index.js.map +1 -1
- package/dist/lib/Paysafe/index.js +1 -0
- package/dist/lib/Paysafe/index.js.map +1 -1
- package/dist/lib/Product/index.d.ts +25 -0
- package/dist/lib/Product/index.js +55 -1
- package/dist/lib/Product/index.js.map +1 -1
- package/dist/lib/PromiseToPurchase/index.d.ts +72 -0
- package/dist/lib/PromiseToPurchase/index.js +79 -0
- package/dist/lib/PromiseToPurchase/index.js.map +1 -1
- package/dist/lib/PurchaseOrder/index.d.ts +11 -0
- package/dist/lib/PurchaseOrder/index.js +12 -0
- package/dist/lib/PurchaseOrder/index.js.map +1 -1
- package/dist/lib/Service/index.d.ts +8 -0
- package/dist/lib/Service/index.js +8 -0
- package/dist/lib/Service/index.js.map +1 -1
- package/dist/lib/Shipment/index.js +13 -0
- package/dist/lib/Shipment/index.js.map +1 -1
- package/dist/lib/Slider/index.d.ts +6 -0
- package/dist/lib/Slider/index.js +6 -0
- package/dist/lib/Slider/index.js.map +1 -1
- package/dist/lib/Space/index.d.ts +178 -0
- package/dist/lib/Space/index.js +495 -6
- package/dist/lib/Space/index.js.map +1 -1
- package/dist/lib/Supplier/index.js +5 -0
- package/dist/lib/Supplier/index.js.map +1 -1
- package/dist/lib/Tags/index.js +5 -0
- package/dist/lib/Tags/index.js.map +1 -1
- package/dist/lib/TransferRequest/index.d.ts +178 -0
- package/dist/lib/TransferRequest/index.js +236 -4
- package/dist/lib/TransferRequest/index.js.map +1 -1
- package/dist/lib/User/index.d.ts +54 -0
- package/dist/lib/User/index.js +101 -21
- package/dist/lib/User/index.js.map +1 -1
- package/dist/lib/baseService.js +26 -0
- package/dist/lib/baseService.js.map +1 -1
- package/dist/rules/GR/constants/data.js +22 -0
- package/dist/rules/GR/constants/data.js.map +1 -1
- package/dist/rules/GR/constants/products.d.ts +3 -0
- package/dist/rules/GR/constants/products.js +16 -0
- package/dist/rules/GR/constants/products.js.map +1 -1
- package/dist/rules/GR/interfaces/data.js +7 -1
- package/dist/rules/GR/interfaces/data.js.map +1 -1
- package/dist/rules/GR/utils/cart.d.ts +41 -0
- package/dist/rules/GR/utils/cart.js +107 -1
- package/dist/rules/GR/utils/cart.js.map +1 -1
- package/dist/rules/GR/utils/data.js +4 -1
- package/dist/rules/GR/utils/data.js.map +1 -1
- package/dist/rules/GR/utils/expedition.d.ts +69 -0
- package/dist/rules/GR/utils/expedition.js +399 -11
- package/dist/rules/GR/utils/expedition.js.map +1 -1
- package/dist/rules/GR/utils/g2.d.ts +33 -0
- package/dist/rules/GR/utils/g2.js +135 -3
- package/dist/rules/GR/utils/g2.js.map +1 -1
- package/dist/rules/GR/utils/invoices.d.ts +27 -0
- package/dist/rules/GR/utils/invoices.js +41 -0
- package/dist/rules/GR/utils/invoices.js.map +1 -1
- package/dist/rules/GR/utils/products.d.ts +161 -0
- package/dist/rules/GR/utils/products.js +272 -1
- package/dist/rules/GR/utils/products.js.map +1 -1
- package/dist/rules/GR/utils/upsells.d.ts +32 -0
- package/dist/rules/GR/utils/upsells.js +32 -0
- package/dist/rules/GR/utils/upsells.js.map +1 -1
- package/dist/services/database/DatabaseService.d.ts +84 -0
- package/dist/services/database/DatabaseService.js +85 -0
- package/dist/services/database/DatabaseService.js.map +1 -1
- package/dist/services/database/FirebaseProvider.js +17 -0
- package/dist/services/database/FirebaseProvider.js.map +1 -1
- package/dist/services/database/NotFirebaseProvider.d.ts +14 -0
- package/dist/services/database/NotFirebaseProvider.js +19 -0
- package/dist/services/database/NotFirebaseProvider.js.map +1 -1
- package/dist/services/g2/G2OrderSlip.d.ts +7 -0
- package/dist/services/g2/G2OrderSlip.js +18 -0
- package/dist/services/g2/G2OrderSlip.js.map +1 -1
- package/dist/services/g2/utils.d.ts +10 -0
- package/dist/services/g2/utils.js +189 -3
- package/dist/services/g2/utils.js.map +1 -1
- package/dist/services/logs/index.d.ts +3 -0
- package/dist/services/logs/index.js +6 -1
- package/dist/services/logs/index.js.map +1 -1
- package/dist/services/products/BaseClass.js +2 -0
- package/dist/services/products/BaseClass.js.map +1 -1
- package/dist/services/products/TCGService.js +17 -1
- package/dist/services/products/TCGService.js.map +1 -1
- package/dist/services/products/utils.d.ts +22 -0
- package/dist/services/products/utils.js +50 -0
- package/dist/services/products/utils.js.map +1 -1
- package/dist/utils/anonymisation.d.ts +24 -0
- package/dist/utils/anonymisation.js +30 -0
- package/dist/utils/anonymisation.js.map +1 -1
- package/dist/utils/aws.d.ts +22 -0
- package/dist/utils/aws.js +28 -0
- package/dist/utils/aws.js.map +1 -1
- package/dist/utils/booking.d.ts +8 -0
- package/dist/utils/booking.js +9 -0
- package/dist/utils/booking.js.map +1 -1
- package/dist/utils/cart.d.ts +81 -0
- package/dist/utils/cart.js +172 -9
- package/dist/utils/cart.js.map +1 -1
- package/dist/utils/context.js +2 -2
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/currency.js +31 -1
- package/dist/utils/currency.js.map +1 -1
- package/dist/utils/data.js +2 -0
- package/dist/utils/data.js.map +1 -1
- package/dist/utils/discount.d.ts +118 -0
- package/dist/utils/discount.js +178 -1
- package/dist/utils/discount.js.map +1 -1
- package/dist/utils/file-admin.js +1 -0
- package/dist/utils/file-admin.js.map +1 -1
- package/dist/utils/file.js +9 -1
- package/dist/utils/file.js.map +1 -1
- package/dist/utils/firebase-admin.d.ts +9 -0
- package/dist/utils/firebase-admin.js +12 -0
- package/dist/utils/firebase-admin.js.map +1 -1
- package/dist/utils/firebase.d.ts +17 -0
- package/dist/utils/firebase.js +17 -0
- package/dist/utils/firebase.js.map +1 -1
- package/dist/utils/inventories.d.ts +52 -0
- package/dist/utils/inventories.js +77 -2
- package/dist/utils/inventories.js.map +1 -1
- package/dist/utils/locale.d.ts +9 -0
- package/dist/utils/locale.js +9 -0
- package/dist/utils/locale.js.map +1 -1
- package/dist/utils/mailchimp.js +36 -0
- package/dist/utils/mailchimp.js.map +1 -1
- package/dist/utils/mathUtils.js +9 -0
- package/dist/utils/mathUtils.js.map +1 -1
- package/dist/utils/object.d.ts +19 -0
- package/dist/utils/object.js +21 -3
- package/dist/utils/object.js.map +1 -1
- package/dist/utils/products.d.ts +7 -0
- package/dist/utils/products.js +9 -0
- package/dist/utils/products.js.map +1 -1
- package/dist/utils/promiseToPurchase.d.ts +32 -0
- package/dist/utils/promiseToPurchase.js +34 -0
- package/dist/utils/promiseToPurchase.js.map +1 -1
- package/dist/utils/prosprsearch.d.ts +15 -0
- package/dist/utils/prosprsearch.js +15 -0
- package/dist/utils/prosprsearch.js.map +1 -1
- package/dist/utils/sdc.js +7 -0
- package/dist/utils/sdc.js.map +1 -1
- package/dist/utils/searchIndexes.d.ts +37 -0
- package/dist/utils/searchIndexes.js +37 -0
- package/dist/utils/searchIndexes.js.map +1 -1
- package/dist/utils/string.js +7 -6
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/tools.d.ts +4 -0
- package/dist/utils/tools.js +4 -0
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/transferRequests.d.ts +24 -0
- package/dist/utils/transferRequests.js +24 -0
- package/dist/utils/transferRequests.js.map +1 -1
- package/dist/utils/update.js +12 -0
- package/dist/utils/update.js.map +1 -1
- package/package.json +1 -1
package/dist/utils/discount.js
CHANGED
|
@@ -32,6 +32,12 @@ const cart_2 = require("../rules/GR/interfaces/cart");
|
|
|
32
32
|
const object_1 = require("./object");
|
|
33
33
|
const data_2 = require("../rules/GR/constants/data");
|
|
34
34
|
const g2_1 = require("../rules/GR/utils/g2");
|
|
35
|
+
// -----------------------------------------------------------------------------------
|
|
36
|
+
// #region GENERAL
|
|
37
|
+
/**
|
|
38
|
+
* Get formatted array of cart promos applied to a specific cart
|
|
39
|
+
* @param cartData
|
|
40
|
+
*/
|
|
35
41
|
const getCartPromo = (cartData) => {
|
|
36
42
|
if (!!!cartData.cart_promo_applied && !!!cartData.cart_promos_applied)
|
|
37
43
|
return;
|
|
@@ -42,11 +48,21 @@ const getCartPromo = (cartData) => {
|
|
|
42
48
|
: [];
|
|
43
49
|
};
|
|
44
50
|
exports.getCartPromo = getCartPromo;
|
|
51
|
+
/**
|
|
52
|
+
* Check if current cart promos applied contain a promo_code type promotion
|
|
53
|
+
* @param cartData
|
|
54
|
+
*/
|
|
45
55
|
const shouldCheckPromoCode = (cartData) => {
|
|
46
56
|
return ((!!cartData.cart_promos_applied && !!cartData.cart_promos_applied.some((p) => p.promo_code)) ||
|
|
47
57
|
(!!cartData.cart_promo_applied && !!cartData.cart_promo_applied.promo_code));
|
|
48
58
|
};
|
|
49
59
|
exports.shouldCheckPromoCode = shouldCheckPromoCode;
|
|
60
|
+
/**
|
|
61
|
+
* Check if promo is expressed as a percentage
|
|
62
|
+
* @param promo The promo to check. Works for cart applied promo as well as discount rule
|
|
63
|
+
* @param options.includePaymentIncentiveInCheck Optionnal. If payement incentive promotions should also be included in check
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
50
66
|
const isPromoAPercentage = (promo, options = {}) => {
|
|
51
67
|
const promoPercentOptions = [
|
|
52
68
|
IDiscountRule_1.ResultActionEnum.PERCENT,
|
|
@@ -91,6 +107,7 @@ const getAppliedAmountsForSubtotalPromosOnCart = (cartData) => {
|
|
|
91
107
|
let amountRemoved = promo.amount_removed;
|
|
92
108
|
const serviceAndFeesTotal = (0, exports.getOnlyServicesAndFeesSubtotal)(cartData, activePromos.items);
|
|
93
109
|
if ((0, exports.isPromoAPercentage)(promo, { defaultToPercent: true })) {
|
|
110
|
+
// if the promo excludes services and fees, subtract the serviceAndFeesTotal from the subtotal
|
|
94
111
|
if (!!promo.exclude_services_and_fees) {
|
|
95
112
|
amountRemoved = (0, round_1.default)((promo.amount_removed / 100) * (currentSubtotal - serviceAndFeesTotal), 3);
|
|
96
113
|
}
|
|
@@ -104,7 +121,17 @@ const getAppliedAmountsForSubtotalPromosOnCart = (cartData) => {
|
|
|
104
121
|
return promoAmounts;
|
|
105
122
|
};
|
|
106
123
|
exports.getAppliedAmountsForSubtotalPromosOnCart = getAppliedAmountsForSubtotalPromosOnCart;
|
|
124
|
+
// #endregion
|
|
125
|
+
// -----------------------------------------------------------------------------------
|
|
126
|
+
// #region CHECK DISCOUNT ELIGIBILITY
|
|
127
|
+
/**
|
|
128
|
+
* Check if a discount rule applies to a specific declination
|
|
129
|
+
* @param discount_rule - The discount rule to check
|
|
130
|
+
* @param declination - The declination to compare
|
|
131
|
+
* @param parentSlug - Optionnal. Used to check parent product slug with 'product' rule specifications. If not provided and 'product' rule found, returns true by default for rule check
|
|
132
|
+
*/
|
|
107
133
|
const shouldApplyRuleToDeclination = (discount_rule, declination, parentSlug) => {
|
|
134
|
+
// If discount has no rules, it means it applies to declination automatically
|
|
108
135
|
if (!!!discount_rule.rules || !!!discount_rule.rules.length)
|
|
109
136
|
return true;
|
|
110
137
|
const currentDiscountMap = discount_rule.rules.map((rule) => {
|
|
@@ -119,6 +146,7 @@ const shouldApplyRuleToDeclination = (discount_rule, declination, parentSlug) =>
|
|
|
119
146
|
return [rule.condition, (0, exports.getResultRuleDetail)(ruleDetail, declination.sku)];
|
|
120
147
|
}));
|
|
121
148
|
case IDiscountRule_1.RuleFieldEnum.DECLINATION:
|
|
149
|
+
// case 'slug':
|
|
122
150
|
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
123
151
|
return [rule.condition, declination.sku === ruleDetail.value[0]];
|
|
124
152
|
}));
|
|
@@ -142,6 +170,11 @@ const shouldApplyRuleToDeclination = (discount_rule, declination, parentSlug) =>
|
|
|
142
170
|
return _checkRuleApplicationArray(currentDiscountMap);
|
|
143
171
|
};
|
|
144
172
|
exports.shouldApplyRuleToDeclination = shouldApplyRuleToDeclination;
|
|
173
|
+
/**
|
|
174
|
+
* Check if a specific rule of a discount rule is respected
|
|
175
|
+
* @param ruleDetail - The rule details object to check
|
|
176
|
+
* @param cartValue - The value to compare with rule specifications
|
|
177
|
+
*/
|
|
145
178
|
const getResultRuleDetail = (ruleDetail, cartValue, log) => {
|
|
146
179
|
let ruleRespected = false;
|
|
147
180
|
let isDate = false;
|
|
@@ -256,11 +289,17 @@ const getResultRuleDetail = (ruleDetail, cartValue, log) => {
|
|
|
256
289
|
return ruleRespected;
|
|
257
290
|
};
|
|
258
291
|
exports.getResultRuleDetail = getResultRuleDetail;
|
|
292
|
+
/**
|
|
293
|
+
* Check if rule applied to product attributes is respected for specific declination attributes
|
|
294
|
+
* @param attributeAndValues - The rule details object to check
|
|
295
|
+
* @param arrDeclinationAttributes - The declinations attributes to compare
|
|
296
|
+
*/
|
|
259
297
|
const checkAttributes = (attributeAndValues, arrDeclinationAttributes) => {
|
|
260
298
|
const parentAttributeID = attributeAndValues.value[0].parentAttribute;
|
|
261
299
|
const attributeValues = attributeAndValues.value[0].attributeOptions;
|
|
262
300
|
const operator = attributeAndValues.operator;
|
|
263
301
|
let matchingAttributes = false;
|
|
302
|
+
// const attrArray = arrDeclinationAttributes.map(decliAttr=>Array.isArray(decliAttr)?decliAttr.values[0].)
|
|
264
303
|
for (let declinationAttribute of arrDeclinationAttributes) {
|
|
265
304
|
if (!!matchingAttributes)
|
|
266
305
|
return true;
|
|
@@ -295,11 +334,17 @@ const getCartPromoType = (discount) => {
|
|
|
295
334
|
: Cart_1.CartPromoAppliesToEnum.SUBTOTAL;
|
|
296
335
|
};
|
|
297
336
|
exports.getCartPromoType = getCartPromoType;
|
|
337
|
+
/**
|
|
338
|
+
* Check if promo code can be applied to a specific cart
|
|
339
|
+
* @param cart - The cart to check
|
|
340
|
+
* @param promoCode - The discount rule with promo code to check
|
|
341
|
+
*/
|
|
298
342
|
const checkPromoCodeEligibility = (cart, promoCode) => {
|
|
299
343
|
var _a;
|
|
300
344
|
let currentDiscountMap = [];
|
|
301
345
|
const promoType = (0, exports.getCartPromoType)(promoCode);
|
|
302
346
|
const currentPromos = (_a = (0, exports.getCartPromo)(cart)) !== null && _a !== void 0 ? _a : [];
|
|
347
|
+
// Only one promo for total_after_taxes can be applied to cart
|
|
303
348
|
if (promoType == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES &&
|
|
304
349
|
currentPromos.some((p) => p.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES)) {
|
|
305
350
|
return false;
|
|
@@ -320,12 +365,27 @@ const checkPromoCodeEligibility = (cart, promoCode) => {
|
|
|
320
365
|
return _checkRuleApplicationArray(currentDiscountMap);
|
|
321
366
|
};
|
|
322
367
|
exports.checkPromoCodeEligibility = checkPromoCodeEligibility;
|
|
368
|
+
// #endregion
|
|
369
|
+
// -----------------------------------------------------------------------------------
|
|
370
|
+
// #region TIER PRICING
|
|
371
|
+
/**
|
|
372
|
+
* Returns tier pricing step that should be applied for provided quantity, or undefined if none should apply
|
|
373
|
+
* @param tierPricingToCheck - the indexed tier-pricing array to check
|
|
374
|
+
* @param qte
|
|
375
|
+
*/
|
|
323
376
|
const getTierPricingToApply = (tierPricingToCheck, qte) => {
|
|
324
377
|
if (!!!tierPricingToCheck)
|
|
325
378
|
return;
|
|
326
379
|
return tierPricingToCheck.find((tp) => (0, toNumber_1.default)(tp.from) <= qte && (!!!tp.to || (0, toNumber_1.default)(tp.to) >= qte));
|
|
327
380
|
};
|
|
328
381
|
exports.getTierPricingToApply = getTierPricingToApply;
|
|
382
|
+
/**
|
|
383
|
+
* Converts tier-pricing found in discount_rule to IIndexedTierPricing.
|
|
384
|
+
* @param discountRule - the tier-pricing tier discountRule to check
|
|
385
|
+
* @param price - declinations regular price from which tier-pricing result is calculated
|
|
386
|
+
* @param space
|
|
387
|
+
* @param decimals - the amount of decimals to show on tier-pricing result
|
|
388
|
+
*/
|
|
329
389
|
const applyTierPricing = (discountRule, price, space, decimals) => {
|
|
330
390
|
if (!!!discountRule.rules || !!!discountRule.rules.length)
|
|
331
391
|
return [];
|
|
@@ -361,6 +421,12 @@ const applyTierPricing = (discountRule, price, space, decimals) => {
|
|
|
361
421
|
];
|
|
362
422
|
};
|
|
363
423
|
exports.applyTierPricing = applyTierPricing;
|
|
424
|
+
/**
|
|
425
|
+
* Calculate new discount_price object for cart item base on qte and tier_pricing
|
|
426
|
+
* @param item - the item to check
|
|
427
|
+
* @param setOriginalPrice - if original_amount should be set instead of discount_price.amount
|
|
428
|
+
* @param originalDecli - Optionnal. The IIndexedDeclination used to construct the cart item originally.
|
|
429
|
+
*/
|
|
364
430
|
const getNewDiscountPriceFromTierPricing = (item, setOriginalPrice, originalDecli) => {
|
|
365
431
|
const tierPricingToApply = (0, exports.getTierPricingToApply)(item.tier_pricing, item.qte);
|
|
366
432
|
const currentDiscountPrice = item.discount_price;
|
|
@@ -371,17 +437,23 @@ const getNewDiscountPriceFromTierPricing = (item, setOriginalPrice, originalDecl
|
|
|
371
437
|
const { price_type, original_amount } = currentDiscountPrice, rest = __rest(currentDiscountPrice, ["price_type", "original_amount"]);
|
|
372
438
|
prevDiscountPrice = Object.assign(Object.assign({}, rest), { amount: original_amount });
|
|
373
439
|
}
|
|
440
|
+
// if current quantity does not fit in any defined tier_pricing tiers
|
|
374
441
|
if (!!!tierPricingToApply) {
|
|
442
|
+
// if current item has overidden price as discount_price, set original_amount props instead of amount
|
|
375
443
|
if (!!setOriginalPrice && !!currentDiscountPrice) {
|
|
376
444
|
let amountToSet = item.regular_price.amount;
|
|
445
|
+
// if originalDecli was provided, fetch true original price from decli, else use items's regular price
|
|
377
446
|
if (!!originalDecli) {
|
|
378
447
|
const calculatedPrice = (0, products_1.getLowestPrice)(Object.assign(Object.assign({}, originalDecli), { qte: item.qte }));
|
|
379
448
|
amountToSet = calculatedPrice.price.amount;
|
|
380
449
|
}
|
|
381
450
|
return Object.assign(Object.assign({}, currentDiscountPrice), { original_amount: !!originalDecli ? amountToSet : item.regular_price.amount });
|
|
382
451
|
}
|
|
452
|
+
// if current discount_price has 'tierpricing' price_type, return prevDiscountPrice
|
|
453
|
+
// else, return current item discount_price
|
|
383
454
|
return !!currentIsTierPricing ? prevDiscountPrice : currentDiscountPrice !== null && currentDiscountPrice !== void 0 ? currentDiscountPrice : null;
|
|
384
455
|
}
|
|
456
|
+
// if current item has overidden price as discount_price,
|
|
385
457
|
if (!!setOriginalPrice && !!currentDiscountPrice) {
|
|
386
458
|
return Object.assign(Object.assign({}, currentDiscountPrice), { original_amount: tierPricingToApply.price.amount });
|
|
387
459
|
}
|
|
@@ -392,6 +464,15 @@ const getNewDiscountPriceFromTierPricing = (item, setOriginalPrice, originalDecl
|
|
|
392
464
|
: {}));
|
|
393
465
|
};
|
|
394
466
|
exports.getNewDiscountPriceFromTierPricing = getNewDiscountPriceFromTierPricing;
|
|
467
|
+
// #endregion
|
|
468
|
+
// -----------------------------------------------------------------------------------
|
|
469
|
+
// #region APPLY DISCOUNTS/PROMOS
|
|
470
|
+
/**
|
|
471
|
+
* Get discounted price after applying discount rules to a provided price
|
|
472
|
+
* @param discount_rules - The discount rules to apply
|
|
473
|
+
* @param amount - The initial amount on which to apply discounts
|
|
474
|
+
* @param space
|
|
475
|
+
*/
|
|
395
476
|
const applyDiscountRulesOnProduct = (discount_rules, amount, space) => {
|
|
396
477
|
if (!!!discount_rules || !!!discount_rules.length)
|
|
397
478
|
return undefined;
|
|
@@ -416,18 +497,34 @@ const applyDiscountRulesOnProduct = (discount_rules, amount, space) => {
|
|
|
416
497
|
: current_promo_price;
|
|
417
498
|
};
|
|
418
499
|
exports.applyDiscountRulesOnProduct = applyDiscountRulesOnProduct;
|
|
500
|
+
/**
|
|
501
|
+
* Get result of discount rule discount on a provided amount
|
|
502
|
+
* @param initial - The price on which to apply the discount
|
|
503
|
+
* @param discountResultObj - The discount rule result object
|
|
504
|
+
*/
|
|
419
505
|
const applyDiscountToPrice = (initial, discountResultObj) => {
|
|
420
506
|
return discountResultObj.action === 'amount'
|
|
421
507
|
? initial - Number(discountResultObj.action_value)
|
|
422
508
|
: initial * (1 - Number(discountResultObj.action_value) / 100);
|
|
423
509
|
};
|
|
424
510
|
exports.applyDiscountToPrice = applyDiscountToPrice;
|
|
511
|
+
/**
|
|
512
|
+
* Get sku(s) affected by a promo as an array of strings
|
|
513
|
+
* @param valueToConvert - The sku or sku array associated with the promo
|
|
514
|
+
* @returns And array of strings
|
|
515
|
+
*/
|
|
425
516
|
const getSkuArrayForPromo = (valueToConvert) => {
|
|
426
517
|
if (!!Array.isArray(valueToConvert))
|
|
427
518
|
return valueToConvert;
|
|
428
519
|
return [valueToConvert];
|
|
429
520
|
};
|
|
430
521
|
exports.getSkuArrayForPromo = getSkuArrayForPromo;
|
|
522
|
+
/**
|
|
523
|
+
* Returns a list of all skus where promo applied to specific products should apply. Check for both amount/percent_sku and amount/percent_category options.
|
|
524
|
+
* @param cartItems - The current cart items
|
|
525
|
+
* @param promoToCheck - The promo to check
|
|
526
|
+
* @returns An array of strings
|
|
527
|
+
*/
|
|
431
528
|
const getResultAppliedDiscountSkus = (cartItems, promoToCheck) => {
|
|
432
529
|
var _a, _b, _c;
|
|
433
530
|
const action = (_a = promoToCheck.result.action) !== null && _a !== void 0 ? _a : '';
|
|
@@ -437,6 +534,8 @@ const getResultAppliedDiscountSkus = (cartItems, promoToCheck) => {
|
|
|
437
534
|
.filter((item) => {
|
|
438
535
|
if (!!['amount_category', 'percent_category'].includes(action)) {
|
|
439
536
|
const categorySlugsToCheck = (0, exports.getItemCategorySlugArray)(item.categories);
|
|
537
|
+
// Check if one of the slugs in item is EXACTLY the same as a category slug found in discount
|
|
538
|
+
// -- Done to remove cases where slug in discount is found partially in one of the levels
|
|
440
539
|
return categoryArray.some((cat) => categorySlugsToCheck.includes(cat));
|
|
441
540
|
}
|
|
442
541
|
return skuArray.includes(item.sku);
|
|
@@ -445,14 +544,29 @@ const getResultAppliedDiscountSkus = (cartItems, promoToCheck) => {
|
|
|
445
544
|
return productsToApplyPromo;
|
|
446
545
|
};
|
|
447
546
|
exports.getResultAppliedDiscountSkus = getResultAppliedDiscountSkus;
|
|
547
|
+
/**
|
|
548
|
+
* Creates array of all category level slugs for a cart item.
|
|
549
|
+
* @param itemCategories - Value found in props cart.categories
|
|
550
|
+
* @returns An array of strings
|
|
551
|
+
*/
|
|
448
552
|
const getItemCategorySlugArray = (itemCategories) => {
|
|
449
553
|
if (!!!itemCategories)
|
|
450
554
|
return [];
|
|
555
|
+
// 1. Reorder item categories by key (can be in diff order in database)
|
|
451
556
|
const orderedByLevel = (0, orderBy_1.default)(Object.entries(itemCategories), ([key, _value]) => key);
|
|
557
|
+
// 2. Then, isolate last category level's value, since it should contain all category levels seperated by string ' > '
|
|
452
558
|
const lastLevelCategory = !!orderedByLevel.length ? orderedByLevel[orderedByLevel.length - 1][1] : '';
|
|
559
|
+
// 3. Split on ' > ' to create array of possible category slug values.
|
|
560
|
+
// Check if one of the slugs is EXACTLY the same as the category slug found in le discount
|
|
453
561
|
return lastLevelCategory.split(' > ');
|
|
454
562
|
};
|
|
455
563
|
exports.getItemCategorySlugArray = getItemCategorySlugArray;
|
|
564
|
+
/**
|
|
565
|
+
* Apply all valid discounts found in a specific cart's discount_rules props to cart
|
|
566
|
+
* @param cart - The cart to check
|
|
567
|
+
* @param isMultiPromo
|
|
568
|
+
* @param forceShipping - If cart should be considered as a shipping cart, even if is_pickup is true
|
|
569
|
+
*/
|
|
456
570
|
const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPromos) => {
|
|
457
571
|
var _a;
|
|
458
572
|
const discountRules = !!forcedPromos
|
|
@@ -463,6 +577,7 @@ const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPr
|
|
|
463
577
|
if (!!!discountRules || !!!discountRules.length) {
|
|
464
578
|
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
579
|
}
|
|
580
|
+
// Remove all promos not found in cart discount_rules array
|
|
466
581
|
let newCart = Object.assign(Object.assign(Object.assign({}, cart), (!!cart.cart_promo_applied &&
|
|
467
582
|
!!!discountRules.some((dr) => dr.id === cart.cart_promo_applied.discount_id)
|
|
468
583
|
? { cart_promo_applied: null }
|
|
@@ -483,10 +598,15 @@ const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPr
|
|
|
483
598
|
}
|
|
484
599
|
return true;
|
|
485
600
|
};
|
|
601
|
+
// Chaque fois que les totaux sont recalculés :
|
|
602
|
+
// -- on vérifie les codes promos déjà dans le panier qui s'appliquent sur des skus OU catégories spécifiques
|
|
603
|
+
// -- s'ils n'ont plus d'affaire à s'appliquer, on les retire du cartPromosApplied
|
|
604
|
+
// -- si de nouveaux produits eligibles sont ajoutés, on modifie le array de item_given avec les nouvelles valeurs à jour.
|
|
486
605
|
const currentPromos = (0, exports.getCartPromo)(newCart);
|
|
487
606
|
if (!!currentPromos) {
|
|
488
607
|
let shouldRemovePromo = [];
|
|
489
608
|
let shouldUpdatePromo = [];
|
|
609
|
+
// const currentPromoCodesApplied = currentPromos.filter((p) => !!p.promo_code)
|
|
490
610
|
for (const appliedPromo of currentPromos) {
|
|
491
611
|
if (appliedPromo.applies_to === Cart_1.CartPromoAppliesToEnum.PRODUCT && !!appliedPromo.item_given) {
|
|
492
612
|
const sameInCartDiscounts = discountRules.find((d) => d.id == appliedPromo.discount_id);
|
|
@@ -501,6 +621,7 @@ const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPr
|
|
|
501
621
|
}
|
|
502
622
|
}
|
|
503
623
|
}
|
|
624
|
+
// Update cart_promos_applied to remove unapplicable promos and update promos to current cart items
|
|
504
625
|
newCart = Object.assign(Object.assign({}, newCart), (!!newCart.cart_promos_applied
|
|
505
626
|
? {
|
|
506
627
|
cart_promos_applied: newCart.cart_promos_applied
|
|
@@ -516,6 +637,7 @@ const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPr
|
|
|
516
637
|
}
|
|
517
638
|
for (const discount of discountRules) {
|
|
518
639
|
if (!!discount.promo_code && !!discount.promo_code.code) {
|
|
640
|
+
// CHECK FOR PROMO_CODE ELIGIBILITY
|
|
519
641
|
const promoCodeInCart = (currentPromos || []).find((p) => p.discount_id == discount.id);
|
|
520
642
|
if (!!promoCodeInCart) {
|
|
521
643
|
const shouldStillApplyCode = (0, exports.checkPromoCodeEligibility)(newCart, discount);
|
|
@@ -619,6 +741,7 @@ const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPr
|
|
|
619
741
|
let promo = 0;
|
|
620
742
|
for (let i = 0; i < shippingPromo.length; i++) {
|
|
621
743
|
if (shippingPromo[i].amount_unit === 'free_shipping') {
|
|
744
|
+
// si free on stop la
|
|
622
745
|
promo = i;
|
|
623
746
|
break;
|
|
624
747
|
}
|
|
@@ -646,6 +769,11 @@ const applyDiscountToCart = (cart, isMultiPromo, forceShipping = false, forcedPr
|
|
|
646
769
|
: !!newCart.cart_promo_applied && newCart.cart_promo_applied.free_shipping });
|
|
647
770
|
};
|
|
648
771
|
exports.applyDiscountToCart = applyDiscountToCart;
|
|
772
|
+
/**
|
|
773
|
+
* Get the ICartPromoApplied object for a specified discount_rule. Only works for promos that do not apply to products of certain categories/skus.
|
|
774
|
+
* @param cart
|
|
775
|
+
* @param discount
|
|
776
|
+
*/
|
|
649
777
|
const getStandardCartPromoFromDiscount = (cart, discount) => {
|
|
650
778
|
const promoType = (0, exports.getCartPromoType)(discount);
|
|
651
779
|
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
|
|
@@ -659,7 +787,15 @@ const getStandardCartPromoFromDiscount = (cart, discount) => {
|
|
|
659
787
|
: {}));
|
|
660
788
|
};
|
|
661
789
|
exports.getStandardCartPromoFromDiscount = getStandardCartPromoFromDiscount;
|
|
790
|
+
/**
|
|
791
|
+
* Calculates the cumulative subtotal for all service/fee type items in cart, including any applied promos. Usefull when calculating a promo's amount when all fees and services should be excluded.
|
|
792
|
+
* @param cartData - The cartData to check
|
|
793
|
+
* @param allCurrentAppliedToItemPromos - All currently active cartPromos that apply to items in cart. Sent seperatly in case local state is different from current cartData.
|
|
794
|
+
* @returns A number
|
|
795
|
+
*/
|
|
662
796
|
const getOnlyServicesAndFeesSubtotal = (cartData, allCurrentAppliedToItemPromos) => {
|
|
797
|
+
// Calculate the subtotal for just the fees and services, including their promos
|
|
798
|
+
// ** NEW - Now does not count escompte supp products as services when in promo on subtotal check
|
|
663
799
|
let servicesAndFeesTotal = 0;
|
|
664
800
|
cartData.items.forEach((i) => {
|
|
665
801
|
if (!!!i.is_service || !!(0, g2_1.isEscompteSuppItem)(i.sku))
|
|
@@ -682,6 +818,8 @@ const getOnlyServicesAndFeesSubtotal = (cartData, allCurrentAppliedToItemPromos)
|
|
|
682
818
|
return servicesAndFeesTotal;
|
|
683
819
|
};
|
|
684
820
|
exports.getOnlyServicesAndFeesSubtotal = getOnlyServicesAndFeesSubtotal;
|
|
821
|
+
// =========================================================
|
|
822
|
+
// #region UTILS FOR APPLYING CART DISCOUNTS AND PROMO CODES
|
|
685
823
|
const _checkIfRuleAppliesToCart = (rule, appliesTo, cart) => {
|
|
686
824
|
var _a;
|
|
687
825
|
const todayDate = (0, moment_1.default)().toDate();
|
|
@@ -808,7 +946,11 @@ const _checkIfRuleAppliesToCart = (rule, appliesTo, cart) => {
|
|
|
808
946
|
];
|
|
809
947
|
}));
|
|
810
948
|
case IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD:
|
|
811
|
-
|
|
949
|
+
// If incentive custom_payment_type is registered, let this check pass, since payment_method will only be chosen on last step
|
|
950
|
+
// NOTE - Used to only apply to POS and POS_TRASACTIONNAL carts, now applies to all carts.
|
|
951
|
+
if (
|
|
952
|
+
// cart.cart_type != CartTypeEnum.WEB &&
|
|
953
|
+
cart.custom_payment_type &&
|
|
812
954
|
cart.custom_payment_type.method == Cart_1.CustomPaymentTypeEnum.INCENTIVE) {
|
|
813
955
|
return [ruleCondition, true];
|
|
814
956
|
}
|
|
@@ -822,6 +964,8 @@ const _checkIfRuleAppliesToCart = (rule, appliesTo, cart) => {
|
|
|
822
964
|
? [cart.paid_by]
|
|
823
965
|
: [];
|
|
824
966
|
return (0, flatten_1.default)(rule.ruleDetails.map((ruleDetail) => {
|
|
967
|
+
// Si contains, doit contenir AU MOINS UN des modes de paiement ciblés
|
|
968
|
+
// Si contains-not, ne doit pas contenir QUE les modes de paiement exclus
|
|
825
969
|
let result = ruleDetail.operator == 'contains'
|
|
826
970
|
? paymentTypesToCompare.some((type) => ruleDetail.value.includes(type))
|
|
827
971
|
: !paymentTypesToCompare.every((type) => ruleDetail.value.includes(type));
|
|
@@ -853,12 +997,27 @@ const _checkIfRuleAppliesToCart = (rule, appliesTo, cart) => {
|
|
|
853
997
|
return [IDiscountRule_1.RuleConditionEnum.AND, true];
|
|
854
998
|
}
|
|
855
999
|
};
|
|
1000
|
+
/**
|
|
1001
|
+
* Checks if discount rule should be applied to cart based on each rule verification results.
|
|
1002
|
+
* @param checkedRulesApplicationArray - Array where each position is a verified rule result (condition with passed of failed (boolean))
|
|
1003
|
+
* @returns A boolean
|
|
1004
|
+
*/
|
|
856
1005
|
const _checkRuleApplicationArray = (checkedRulesApplicationArray) => {
|
|
857
1006
|
return ((checkedRulesApplicationArray.some((option) => !!option && option.indexOf(IDiscountRule_1.RuleConditionEnum.OR) !== -1) &&
|
|
858
1007
|
checkedRulesApplicationArray.some((option) => !!option && option.indexOf(true) !== -1)) ||
|
|
859
1008
|
(checkedRulesApplicationArray.some((option) => !!option && option.indexOf(IDiscountRule_1.RuleConditionEnum.AND) !== -1) &&
|
|
860
1009
|
!checkedRulesApplicationArray.some((option) => !!option && option.indexOf(false) !== -1)));
|
|
861
1010
|
};
|
|
1011
|
+
// #endregion
|
|
1012
|
+
// #endregion
|
|
1013
|
+
// -----------------------------------------------------------------------------------
|
|
1014
|
+
// #region PAYMENT INCENTIVE DISCOUNTS/PROMOS
|
|
1015
|
+
/**
|
|
1016
|
+
* Checks if an incentive discount could (in theory) by added to provided cart, by checking found incentive discount's rule array.
|
|
1017
|
+
* @param cartData - The cart to check (checks discount_rules for incentive)
|
|
1018
|
+
* @param skipCheckFor - If certain rules should be ignore for check
|
|
1019
|
+
* @returns a boolean
|
|
1020
|
+
*/
|
|
862
1021
|
const checkIfCouldApplyIncentivePromo = (cartData, skipCheckFor = []) => {
|
|
863
1022
|
let afterTaxesPromo = cartData.discount_rules.find((d) => !d.draft &&
|
|
864
1023
|
(d.result.action == IDiscountRule_1.ResultActionEnum.PERCENT_AFTER_TAXES ||
|
|
@@ -876,6 +1035,11 @@ const checkIfCouldApplyIncentivePromo = (cartData, skipCheckFor = []) => {
|
|
|
876
1035
|
return _checkRuleApplicationArray(canApply);
|
|
877
1036
|
};
|
|
878
1037
|
exports.checkIfCouldApplyIncentivePromo = checkIfCouldApplyIncentivePromo;
|
|
1038
|
+
/**
|
|
1039
|
+
* Calculates amount to be removed for payment incentive type promos.
|
|
1040
|
+
* @param cartData
|
|
1041
|
+
* @param checkDiscountRules - Optionnal. If cart discount_rules should be checked if cart_promos_applied does not have promo yet.
|
|
1042
|
+
*/
|
|
879
1043
|
const getAfterTaxesPromosTotalAmount = (cartData, checkDiscountRules) => {
|
|
880
1044
|
let currentSubtotal = cartData.subtotal;
|
|
881
1045
|
let afterTaxesPromo = (0, exports.getAfterTaxesPromoInCart)(cartData, checkDiscountRules);
|
|
@@ -891,10 +1055,16 @@ const getAfterTaxesPromosTotalAmount = (cartData, checkDiscountRules) => {
|
|
|
891
1055
|
return totalAmountForAfterTaxesPromos;
|
|
892
1056
|
};
|
|
893
1057
|
exports.getAfterTaxesPromosTotalAmount = getAfterTaxesPromosTotalAmount;
|
|
1058
|
+
/**
|
|
1059
|
+
* Returns cart_promos_applied corresponding to payment incentive, if found. Can also check in discount_rules if props provided
|
|
1060
|
+
* @param cartData
|
|
1061
|
+
* @param checkDiscountRules - Optionnal. If the function should check in cart discount_rules if nothing found in cart_promos_applied or if value differs between discount and promo applied
|
|
1062
|
+
*/
|
|
894
1063
|
const getAfterTaxesPromoInCart = (cartData, checkDiscountRules) => {
|
|
895
1064
|
var _a;
|
|
896
1065
|
let cartPromos = (_a = (0, exports.getCartPromo)(cartData)) !== null && _a !== void 0 ? _a : [];
|
|
897
1066
|
let incentivePromo = cartPromos.find((p) => p.applies_to === Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
|
|
1067
|
+
// Check discount_rule in case value changed or cart promo
|
|
898
1068
|
let discountIncentive = (0, exports.getPaymentIncentiveDiscount)(cartData.discount_rules);
|
|
899
1069
|
if (!!checkDiscountRules &&
|
|
900
1070
|
!!discountIncentive &&
|
|
@@ -904,10 +1074,16 @@ const getAfterTaxesPromoInCart = (cartData, checkDiscountRules) => {
|
|
|
904
1074
|
return incentivePromo;
|
|
905
1075
|
};
|
|
906
1076
|
exports.getAfterTaxesPromoInCart = getAfterTaxesPromoInCart;
|
|
1077
|
+
/**
|
|
1078
|
+
* Returns the information regarding the payment incentive promo if found in cart's discount_rules
|
|
1079
|
+
* @param cartData
|
|
1080
|
+
* @param checkForAllPaidByDiscounts Optionnal. If defined, will check all discounts if no specific incentive found
|
|
1081
|
+
*/
|
|
907
1082
|
const getPaymentIncentiveDiscountInfo = (cartData, checkForAllPaidByDiscounts) => {
|
|
908
1083
|
let appliesToPaymentTypes = undefined;
|
|
909
1084
|
let paymentIncentiveDiscount = (0, exports.getPaymentIncentiveDiscount)(cartData.discount_rules);
|
|
910
1085
|
if (!!!paymentIncentiveDiscount) {
|
|
1086
|
+
// If not found and props set, check all discounts and use first found with rule on payment methode
|
|
911
1087
|
if (!!checkForAllPaidByDiscounts)
|
|
912
1088
|
paymentIncentiveDiscount = cartData.discount_rules.find((d) => (d.rules || []).some((r) => r.field == IDiscountRule_1.RuleFieldEnum.PAYMENT_METHOD));
|
|
913
1089
|
if (!!!paymentIncentiveDiscount)
|
|
@@ -932,4 +1108,5 @@ const getPaymentIncentiveDiscount = (discountRules) => {
|
|
|
932
1108
|
return paymentIncentiveDiscount;
|
|
933
1109
|
};
|
|
934
1110
|
exports.getPaymentIncentiveDiscount = getPaymentIncentiveDiscount;
|
|
1111
|
+
// #endregion
|
|
935
1112
|
//# sourceMappingURL=discount.js.map
|