addio-admin-sdk 1.7.102 → 1.7.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Interfaces/Algolia/index.d.ts +1 -0
- 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.d.ts +1 -0
- 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 +175 -10
- 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 +16 -0
- package/dist/utils/prosprsearch.js +34 -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/cart.js
CHANGED
|
@@ -50,10 +50,13 @@ const updateCartItems = async (currentCart, items, fetchInventory, shouldCheckIn
|
|
|
50
50
|
}
|
|
51
51
|
if (!!inventoryItem) {
|
|
52
52
|
const webStore = inventoryItem.web_inventory;
|
|
53
|
+
// If the item is NOT infinite_stock ans is NOT a service
|
|
53
54
|
if (!!!inventoryItem.is_infinite_stock && !!!cartItem.is_service) {
|
|
55
|
+
// If webstore is not defined or the avaibility = 0
|
|
54
56
|
if (!!!webStore || !!!webStore.available) {
|
|
55
57
|
continue;
|
|
56
58
|
}
|
|
59
|
+
// If the quantity we are setting is more than the available qte of the item
|
|
57
60
|
if (item.qte > webStore.available) {
|
|
58
61
|
if (!!handleInventoryError) {
|
|
59
62
|
await handleInventoryError(true);
|
|
@@ -74,6 +77,16 @@ const updateCartItems = async (currentCart, items, fetchInventory, shouldCheckIn
|
|
|
74
77
|
return { updatedCart, updatedItems };
|
|
75
78
|
};
|
|
76
79
|
exports.updateCartItems = updateCartItems;
|
|
80
|
+
/**
|
|
81
|
+
* For now, copy of `updateCartItems` function in most aspects, with slight optim. Meant to replace updateCartItems eventually!
|
|
82
|
+
* Verify a list of items that could be added to a cart. Returns the list of items to update as well as the updated cart data.
|
|
83
|
+
* @param currentCart
|
|
84
|
+
* @param items
|
|
85
|
+
* @param fetchInventory
|
|
86
|
+
* @param options.shouldCheckInventory
|
|
87
|
+
* @param options.handleInventoryError
|
|
88
|
+
* @param options.shouldCheckStoreInventory
|
|
89
|
+
*/
|
|
77
90
|
const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetchInventory, options = {}) => {
|
|
78
91
|
let updatedCartItems = [...currentCartItems];
|
|
79
92
|
const updatedDetails = [];
|
|
@@ -90,6 +103,7 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
|
|
|
90
103
|
console.log('error on fetching inventoryItem: ', e);
|
|
91
104
|
}
|
|
92
105
|
if (!!inventoryItem) {
|
|
106
|
+
// Check store inventory if specified, or default to web inventory
|
|
93
107
|
let inventoryToCheck;
|
|
94
108
|
if (options.shouldCheckStoreInventory) {
|
|
95
109
|
const sameStoreInventory = inventoryItem.inventories.find((i) => i.store_id == options.shouldCheckStoreInventory);
|
|
@@ -100,6 +114,7 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
|
|
|
100
114
|
else {
|
|
101
115
|
inventoryToCheck = (0, object_1.recursiveCheckObject)(inventoryItem, 'web_inventory.available');
|
|
102
116
|
}
|
|
117
|
+
// If no inventory found, continue
|
|
103
118
|
if (typeof inventoryToCheck == 'undefined') {
|
|
104
119
|
updatedDetails.push({
|
|
105
120
|
sku: item.sku,
|
|
@@ -107,7 +122,9 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
|
|
|
107
122
|
});
|
|
108
123
|
continue;
|
|
109
124
|
}
|
|
125
|
+
// If the item is NOT infinite_stock ans is NOT a service
|
|
110
126
|
if (!!!inventoryItem.is_infinite_stock && !!!cartItem.is_service) {
|
|
127
|
+
// If the avaibility = 0
|
|
111
128
|
if (!inventoryToCheck) {
|
|
112
129
|
updatedDetails.push({
|
|
113
130
|
sku: item.sku,
|
|
@@ -115,6 +132,7 @@ const verifyAndReturnToBeUpdatedCartItems = async (currentCartItems, items, fetc
|
|
|
115
132
|
});
|
|
116
133
|
continue;
|
|
117
134
|
}
|
|
135
|
+
// If the quantity we are setting is more than the available qte of the item
|
|
118
136
|
if (item.qte > inventoryToCheck) {
|
|
119
137
|
if (!!options.handleInventoryError) {
|
|
120
138
|
await options.handleInventoryError(true);
|
|
@@ -152,9 +170,9 @@ const priceWasOverridden = (itemToCheck) => {
|
|
|
152
170
|
exports.priceWasOverridden = priceWasOverridden;
|
|
153
171
|
const getActualPromoPrice = (item, output) => {
|
|
154
172
|
const orgPrice = (0, exports.getActualDiscountPrice)(item, '$');
|
|
155
|
-
let price = orgPrice;
|
|
173
|
+
let price = orgPrice; // default value
|
|
156
174
|
if (!!item.promo_price) {
|
|
157
|
-
price = item.promo_price.amount;
|
|
175
|
+
price = item.promo_price.amount; // this is the first promo
|
|
158
176
|
}
|
|
159
177
|
if (output === '%')
|
|
160
178
|
return !!!orgPrice ? 0 : (1 - price / orgPrice) * 100;
|
|
@@ -162,20 +180,28 @@ const getActualPromoPrice = (item, output) => {
|
|
|
162
180
|
};
|
|
163
181
|
exports.getActualPromoPrice = getActualPromoPrice;
|
|
164
182
|
const getActualDiscountPrice = (item, output) => {
|
|
165
|
-
let price = item.regular_price.amount;
|
|
183
|
+
let price = item.regular_price.amount; // default value
|
|
166
184
|
if (!!item.discount_price) {
|
|
167
|
-
price = item.discount_price.amount;
|
|
185
|
+
price = item.discount_price.amount; // this is the first promo
|
|
168
186
|
}
|
|
169
187
|
if (output === '%')
|
|
170
188
|
return (1 - price / item.regular_price.amount) * 100;
|
|
171
189
|
return price;
|
|
172
190
|
};
|
|
173
191
|
exports.getActualDiscountPrice = getActualDiscountPrice;
|
|
192
|
+
/**
|
|
193
|
+
* Generate a cart item from corresonding indexedProduct
|
|
194
|
+
* @param indexedProduct
|
|
195
|
+
* @param sku
|
|
196
|
+
* @param qte
|
|
197
|
+
*/
|
|
174
198
|
const generateCartItemForSku = async (indexedProduct, sku, qte) => {
|
|
175
199
|
try {
|
|
200
|
+
// Isolate decli with corresponding sku
|
|
176
201
|
const sameDecli = indexedProduct.declinations.find((d) => d.sku == sku);
|
|
177
202
|
if (!sameDecli)
|
|
178
203
|
throw new Error('Could not find decli in product!');
|
|
204
|
+
// Construct CartItem from decli and prod values
|
|
179
205
|
let decliImgs = sameDecli.images_path;
|
|
180
206
|
if (!decliImgs || decliImgs.length == 0) {
|
|
181
207
|
const parentImgs = indexedProduct.image_files;
|
|
@@ -212,8 +238,10 @@ const addCartItems = async (currentCart, newItems, fetchInventory, shouldCheckIn
|
|
|
212
238
|
}
|
|
213
239
|
const itemAlreadyInCart = (0, findIndex_1.default)(newCart.items, (item) => item.sku === cartItem.sku);
|
|
214
240
|
if (!!checkInventory) {
|
|
241
|
+
// If inventory not found, return error
|
|
215
242
|
if (!!!inventoryItem)
|
|
216
243
|
return 'already_max_qte';
|
|
244
|
+
// If the webstore is not defined or the avaibility = 0
|
|
217
245
|
if (!!inventoryItem.is_infinite_stock || !!cartItem.is_service || !!cartItem.is_sample)
|
|
218
246
|
return cartItem;
|
|
219
247
|
if (!!!inventoryItem.web_inventory || !!!inventoryItem.web_inventory.available) {
|
|
@@ -223,6 +251,7 @@ const addCartItems = async (currentCart, newItems, fetchInventory, shouldCheckIn
|
|
|
223
251
|
return 'already_max_qte';
|
|
224
252
|
}
|
|
225
253
|
if (itemAlreadyInCart !== -1 && !!!isServiceUpsellOfSku) {
|
|
254
|
+
// If the quantity we are adding is more than the available qte of the item
|
|
226
255
|
if (!!shouldCheckInventory && !!inventoryItem.web_inventory && !!inventoryItem.web_inventory.available) {
|
|
227
256
|
if ((0, toNumber_1.default)(newCart.items[itemAlreadyInCart].qte) + (0, toNumber_1.default)(cartItem.qte) >
|
|
228
257
|
(0, toNumber_1.default)(inventoryItem.web_inventory.available)) {
|
|
@@ -272,6 +301,14 @@ const addCartItems = async (currentCart, newItems, fetchInventory, shouldCheckIn
|
|
|
272
301
|
};
|
|
273
302
|
};
|
|
274
303
|
exports.addCartItems = addCartItems;
|
|
304
|
+
/**
|
|
305
|
+
* Optimized copy of addCartItems function for now. Will eventually replace addCartItems.
|
|
306
|
+
* Verify a list of items to be potentially added to cart.
|
|
307
|
+
* @param currentCart
|
|
308
|
+
* @param newItems
|
|
309
|
+
* @param fetchInventory
|
|
310
|
+
* @param options
|
|
311
|
+
*/
|
|
275
312
|
const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInventory, options = {}) => {
|
|
276
313
|
let newCart = Object.assign({}, currentCart);
|
|
277
314
|
let items = [...newItems];
|
|
@@ -292,10 +329,13 @@ const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInv
|
|
|
292
329
|
}
|
|
293
330
|
const itemAlreadyInCart = (0, findIndex_1.default)(newCart.items, (item) => item.sku === cartItem.sku);
|
|
294
331
|
if (!!checkInventory) {
|
|
332
|
+
// If inventory not found, return error
|
|
295
333
|
if (!!!inventoryItem)
|
|
296
334
|
return 'inventory_not_found';
|
|
335
|
+
// Check if item's inventory is not followed (if item is a service, a sample, etc...). Skip check if true
|
|
297
336
|
if (inventoryItem.is_infinite_stock || cartItem.is_service || cartItem.is_sample)
|
|
298
337
|
return cartItem;
|
|
338
|
+
// Check store inventory if specified, or default to web inventory
|
|
299
339
|
let inventoryToCheck;
|
|
300
340
|
if (options.shouldCheckStoreInventory) {
|
|
301
341
|
const sameStoreInventory = inventoryItem.inventories.find((i) => i.store_id == options.shouldCheckStoreInventory);
|
|
@@ -306,13 +346,16 @@ const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInv
|
|
|
306
346
|
else {
|
|
307
347
|
inventoryToCheck = (0, object_1.recursiveCheckObject)(inventoryItem, 'web_inventory.available');
|
|
308
348
|
}
|
|
349
|
+
// If no inventory found, return false
|
|
309
350
|
if (typeof inventoryToCheck == 'undefined') {
|
|
310
351
|
return 'inventory_not_found';
|
|
311
352
|
}
|
|
312
353
|
if (cartItem.qte > inventoryToCheck) {
|
|
313
354
|
return 'already_max_qte';
|
|
314
355
|
}
|
|
356
|
+
// If item already in cart
|
|
315
357
|
if (itemAlreadyInCart !== -1 && !!!options.isServiceUpsellOfSku) {
|
|
358
|
+
// If the quantity we are adding is more than the available qte of the item
|
|
316
359
|
if (!!options.shouldCheckInventory && !!inventoryToCheck) {
|
|
317
360
|
if ((0, toNumber_1.default)(newCart.items[itemAlreadyInCart].qte) + (0, toNumber_1.default)(cartItem.qte) > (0, toNumber_1.default)(inventoryToCheck)) {
|
|
318
361
|
return 'already_max_qte';
|
|
@@ -360,6 +403,7 @@ const verifyAndReturnToBeAddedCartItems = async (currentCart, newItems, fetchInv
|
|
|
360
403
|
};
|
|
361
404
|
};
|
|
362
405
|
exports.verifyAndReturnToBeAddedCartItems = verifyAndReturnToBeAddedCartItems;
|
|
406
|
+
// Get province from province array with english, french or abbreviation
|
|
363
407
|
const getCurrentProvince = (provinceToCheck) => {
|
|
364
408
|
let formattedProvince = (0, string_1.stripAccents)(provinceToCheck.toLowerCase());
|
|
365
409
|
return (0, find_1.default)(data_1.provinces, (province) => (0, string_1.stripAccents)(province.value.toLowerCase()) === formattedProvince ||
|
|
@@ -378,6 +422,17 @@ const getTaxProvinceFromShippingAddress = (address) => {
|
|
|
378
422
|
return taxProvince;
|
|
379
423
|
};
|
|
380
424
|
exports.getTaxProvinceFromShippingAddress = getTaxProvinceFromShippingAddress;
|
|
425
|
+
/**
|
|
426
|
+
* Constructs and returns data for indexed cart (algolia or addio)
|
|
427
|
+
* @param cartData - Current cart data
|
|
428
|
+
* @param space - Space object
|
|
429
|
+
* @param options.setPaidAtIfUndefined - Optionnal - If true, will set paid_at with current date
|
|
430
|
+
* @param options.customer - Optionnal - If defined, adds info based on customer to indexedCart
|
|
431
|
+
* @param option.createdAt - Optionnal - If defined, added to indexedCart, else null value added
|
|
432
|
+
* @param option.updatedAt - Optionnal - If defined, added to indexedCart, else null value added
|
|
433
|
+
* @param associatedTransfers - Optionnal, used to pass transfers and statuses to indexed cart. Will only be added if cart's has_transfers prop is true
|
|
434
|
+
* @returns <IIndexedCart>
|
|
435
|
+
*/
|
|
381
436
|
const getIndexedCartData = (cartData, space, options = {}) => {
|
|
382
437
|
var _a, _b, _c, _d, _e;
|
|
383
438
|
const getPaidAt = () => {
|
|
@@ -402,16 +457,38 @@ const getIndexedCartData = (cartData, space, options = {}) => {
|
|
|
402
457
|
: {}));
|
|
403
458
|
}
|
|
404
459
|
const cartPromos = (0, discount_1.getCartPromo)(cartData);
|
|
460
|
+
// If the cart has a promo applied with a promo code, or a discount on a product added via the POS, save info to index
|
|
405
461
|
let hasPromos = !!cartPromos && !!cartPromos.length;
|
|
406
462
|
let hasCustomDiscount = !!cartData.items.some((i) => !!(0, object_1.recursiveCheckObject)(i, 'promo_price.authorization.note') ||
|
|
407
463
|
!!(0, object_1.recursiveCheckObject)(i, 'discount_price.authorization.note'));
|
|
408
|
-
const indexedCartData = Object.assign(Object.assign(Object.assign(Object.assign({ objectID: cartData.id, cart_type: cartData.cart_type, status: cartData.status, ref: cartData.ref || '', invoice_ref: (_c = cartData.invoice_ref) !== null && _c !== void 0 ? _c : null, created_at: !!options.createdAt ? (0, moment_1.default)(options.createdAt).unix() : null, updated_at: !!options.updatedAt
|
|
464
|
+
const indexedCartData = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ objectID: cartData.id, cart_type: cartData.cart_type, status: cartData.status, ref: cartData.ref || '', invoice_ref: (_c = cartData.invoice_ref) !== null && _c !== void 0 ? _c : null, created_at: !!options.createdAt ? (0, moment_1.default)(options.createdAt).unix() : null, updated_at: !!options.updatedAt
|
|
409
465
|
? (0, moment_1.default)(options.updatedAt).unix()
|
|
410
466
|
: !!cartData.paid_at
|
|
411
467
|
? getPaidAt().paid_at
|
|
412
468
|
: (0, moment_1.default)().unix(), processed_at: !!cartData.processed_by && !!cartData.processed_by.date
|
|
413
469
|
? (0, moment_1.default)((0, data_1.formatDate)(cartData.processed_by.date)).unix()
|
|
414
|
-
: null
|
|
470
|
+
: null }, (typeof cartData.to_be_verified_by_clerk !== 'undefined'
|
|
471
|
+
? { to_be_verified_by_clerk: cartData.to_be_verified_by_clerk }
|
|
472
|
+
: {})), {
|
|
473
|
+
// --------------------------------
|
|
474
|
+
// #region PROMOS
|
|
475
|
+
cart_promos_applied: cartPromos !== null && cartPromos !== void 0 ? cartPromos : null, has_promos: !!hasPromos ? hasPromos : null, has_custom_discount: !!hasCustomDiscount ? hasCustomDiscount : null,
|
|
476
|
+
// #endregion
|
|
477
|
+
// --------------------------------
|
|
478
|
+
// #region ITEMS AND SPECIFIC TYPES
|
|
479
|
+
items: itemDict, is_booking: !!cartData.is_booking, is_promise_to_purchase: !!cartData.promise_to_purchase,
|
|
480
|
+
// #endregion
|
|
481
|
+
// --------------------------------
|
|
482
|
+
// #region TRANSFERS
|
|
483
|
+
has_transfers: !!cartData.has_transfers && !!options.associatedTransfers ? options.associatedTransfers : undefined }), getPaidAt()), (0, exports.getPaidByForIndexedCart)(cartData)), { subtotal: cartData.subtotal, total: cartData.total,
|
|
484
|
+
// #endregions
|
|
485
|
+
// --------------------------------
|
|
486
|
+
// #region EXPEDITION
|
|
487
|
+
is_pickup: !!cartData.is_pickup, out_of_zone: !!cartData.shipping_payload && !!cartData.shipping_payload.isOutOfArea, billing_phone: cartData.billing_address ? cartData.billing_address.expedition_recipient_phone : null, shipping_phone: cartData.shipping_address ? cartData.shipping_address.expedition_recipient_phone : null,
|
|
488
|
+
// #endregion
|
|
489
|
+
// --------------------------------
|
|
490
|
+
// #region CUSTOMER
|
|
491
|
+
customer_id: !!cartData.customer_id ? cartData.customer_id : null, customer_name: cartData.billing_address ? cartData.billing_address.expedition_recipient_name : null, customer_email: cartData.customer_info && cartData.customer_info.customer_default_email
|
|
415
492
|
? cartData.customer_info.customer_default_email
|
|
416
493
|
: cartData.user_email
|
|
417
494
|
? cartData.user_email
|
|
@@ -425,7 +502,11 @@ const getIndexedCartData = (cartData, space, options = {}) => {
|
|
|
425
502
|
? Cart_1.CartCustomerEnum.CONNECTED
|
|
426
503
|
: Cart_1.CartCustomerEnum.GUEST, customer_rep: !!options.customer ? options.customer.represented_by : null, customer_external_class: (0, object_1.recursiveCheckObject)(cartData, 'customer_info.customer_external_class') ||
|
|
427
504
|
(0, object_1.recursiveCheckObject)(options.customer, 'basic_info.customer_professionnal_info.external_customer_class') ||
|
|
428
|
-
null,
|
|
505
|
+
null,
|
|
506
|
+
// #endregion
|
|
507
|
+
// --------------------------------
|
|
508
|
+
// #region SEO / MARKETING
|
|
509
|
+
keywords: (0, uniq_1.default)((0, flatten_1.default)(cartData.items.map((item) => {
|
|
429
510
|
return [...(item.name || []).map((n) => n.value), item.sku];
|
|
430
511
|
}))), cart_slug_list: (0, uniq_1.default)(cartData.items.map((item) => {
|
|
431
512
|
return item.parent_slug || '';
|
|
@@ -435,7 +516,9 @@ const getIndexedCartData = (cartData, space, options = {}) => {
|
|
|
435
516
|
frOnly: true,
|
|
436
517
|
slugSafe: (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.BOOKING_BETON, cartData),
|
|
437
518
|
installAsType: true
|
|
438
|
-
}) }, (0, exports.getAssignedToInfo)(cartData)), { project_number: (_e = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.orderOrProjectNumber')) !== null && _e !== void 0 ? _e : null }) : {})) : {})
|
|
519
|
+
}) }, (0, exports.getAssignedToInfo)(cartData)), { project_number: (_e = (0, object_1.recursiveCheckObject)(cartData, 'shipping_payload.orderOrProjectNumber')) !== null && _e !== void 0 ? _e : null }) : {})) : {})
|
|
520
|
+
// #endregion
|
|
521
|
+
);
|
|
439
522
|
return indexedCartData;
|
|
440
523
|
};
|
|
441
524
|
exports.getIndexedCartData = getIndexedCartData;
|
|
@@ -445,6 +528,7 @@ const getPaidByForIndexedCart = (order) => {
|
|
|
445
528
|
const currentPaidBy = !!order.custom_payment_type && !!order.custom_payment_type.method
|
|
446
529
|
? order.custom_payment_type.method
|
|
447
530
|
: order.paid_by;
|
|
531
|
+
// If order has multiple payment types...
|
|
448
532
|
if (currentPaidBy === Cart_1.PaymentTypeEnum.MULTIPLE && !!order.payment_details && !!order.payment_details.length) {
|
|
449
533
|
const firstPayment = order.payment_details.length === 1 || order.payment_details[0].method !== Cart_1.PaymentTypeEnum.TOBERECEIVED
|
|
450
534
|
? order.payment_details[0]
|
|
@@ -497,6 +581,7 @@ const checkIfShippingSameAsBilling = (cart) => {
|
|
|
497
581
|
};
|
|
498
582
|
exports.checkIfShippingSameAsBilling = checkIfShippingSameAsBilling;
|
|
499
583
|
const getOrderStoreInfo = (spaceData, storeAddress) => {
|
|
584
|
+
// Pour algo, si informations du store correspondant non-trouvés, renvoit un 'all' pour qu'il affiche tout le temps
|
|
500
585
|
const defaultStoreInfo = {
|
|
501
586
|
id: 'all',
|
|
502
587
|
name: 'all'
|
|
@@ -523,12 +608,15 @@ const getModifiedItems = (newItems, oldItems) => {
|
|
|
523
608
|
let itemsForInventory = [];
|
|
524
609
|
for (const i of newItems) {
|
|
525
610
|
const itemInOldArray = oldItems.find((o) => o.sku === i.sku);
|
|
611
|
+
// If the item was not in the old cart, keep all its info
|
|
526
612
|
if (!!!itemInOldArray) {
|
|
527
613
|
itemsForInventory = [...itemsForInventory, i];
|
|
528
614
|
continue;
|
|
529
615
|
}
|
|
616
|
+
// If the item is the same in the old cart and in the new one, do nothing
|
|
530
617
|
if (i.qte === itemInOldArray.qte)
|
|
531
618
|
continue;
|
|
619
|
+
// If we are here, it means the item is still in the cart, but it's quantities changed. If the new qte is smaller, the new qte will be negative to add items back to inventory
|
|
532
620
|
const newQte = i.qte - itemInOldArray.qte;
|
|
533
621
|
itemsForInventory = [
|
|
534
622
|
...itemsForInventory,
|
|
@@ -537,6 +625,7 @@ const getModifiedItems = (newItems, oldItems) => {
|
|
|
537
625
|
}
|
|
538
626
|
for (const i of oldItems) {
|
|
539
627
|
const itemInNewArray = newItems.find((o) => o.sku === i.sku);
|
|
628
|
+
// If the item used to be in the cart, but is no longer there, save all it's quantity as negative to put it back in the inventory
|
|
540
629
|
if (!!!itemInNewArray) {
|
|
541
630
|
itemsForInventory = [
|
|
542
631
|
...itemsForInventory,
|
|
@@ -547,6 +636,11 @@ const getModifiedItems = (newItems, oldItems) => {
|
|
|
547
636
|
return itemsForInventory;
|
|
548
637
|
};
|
|
549
638
|
exports.getModifiedItems = getModifiedItems;
|
|
639
|
+
/**
|
|
640
|
+
* Get all active transfers for a cart where given items are found
|
|
641
|
+
* @param allTransfersForCart All transfers associated to a given cart
|
|
642
|
+
* @param cartItems All cart items for whitch to check transfers if found
|
|
643
|
+
*/
|
|
550
644
|
const getActiveTransfersByItemInCart = (allTransfersForCart, cartItems) => {
|
|
551
645
|
if (!!!allTransfersForCart || !!!allTransfersForCart.length)
|
|
552
646
|
return [];
|
|
@@ -567,11 +661,23 @@ const getActiveTransfersByItemInCart = (allTransfersForCart, cartItems) => {
|
|
|
567
661
|
return foundInTransfer;
|
|
568
662
|
};
|
|
569
663
|
exports.getActiveTransfersByItemInCart = getActiveTransfersByItemInCart;
|
|
664
|
+
/**
|
|
665
|
+
* Get the sale unit slug for a cart item
|
|
666
|
+
*
|
|
667
|
+
* @param item the cart item
|
|
668
|
+
* @returns unit slug or empty if not found
|
|
669
|
+
*/
|
|
570
670
|
const getItemSaleUnitSlug = (item) => {
|
|
571
671
|
const unit = (item.other_units || []).find((x) => x.is_sale_unit);
|
|
572
672
|
return unit ? unit.unit_slug : '';
|
|
573
673
|
};
|
|
574
674
|
exports.getItemSaleUnitSlug = getItemSaleUnitSlug;
|
|
675
|
+
/**
|
|
676
|
+
* Constructs an object for each transfer, with corresponding products to update and by which quantity
|
|
677
|
+
* @param allCartTransfers All transfer objects associated to a given cart
|
|
678
|
+
* @param updatedItems Array of pertinent data per item updated to determine which transfers to update quantities for
|
|
679
|
+
* @returns {TransfersWithItemsToUpdate | undefined}
|
|
680
|
+
*/
|
|
575
681
|
const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
|
|
576
682
|
if (!!!allCartTransfers.length || !!!updatedItems.length)
|
|
577
683
|
return;
|
|
@@ -589,8 +695,10 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
|
|
|
589
695
|
const filteredInventoriesByTransferStores = !!upItem.inventoryItem
|
|
590
696
|
? upItem.inventoryItem.inventories.filter((i) => transfersWithSameItem.some((t) => !!t.data().from && t.data().from == i.store_id))
|
|
591
697
|
: undefined;
|
|
698
|
+
// A. If quantities are to be added...
|
|
592
699
|
if (qteToUpdate > 0) {
|
|
593
700
|
const inventoryUnitQteToUpdate = (0, inventories_1.getConvertedUnitQuantity)(upItem.item.other_units, qteToUpdate, 'inventory_unit', true);
|
|
701
|
+
// A1. ... If some transfers are currently at status INITIALIZED (with no "from" store set), add to first initialized found (since quantities can be redistributed by store when opening transfer)
|
|
594
702
|
const initializedStatusTransfers = transfersWithSameItem.filter((t) => t.data().status == TransferRequest_1.TransferRequestStatusEnum.INITIATED);
|
|
595
703
|
if (!!initializedStatusTransfers.length) {
|
|
596
704
|
const firstTransfer = initializedStatusTransfers[0];
|
|
@@ -605,6 +713,9 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
|
|
|
605
713
|
transfersToUpdate[transferID] = dataForTransfer;
|
|
606
714
|
continue;
|
|
607
715
|
}
|
|
716
|
+
// A2. ... Else, add to transfer where store has most quantities
|
|
717
|
+
// TODO - Should we check if quantities are available in store before adding to transfer ?
|
|
718
|
+
// TODO - Maybe based on if property space.options.transfer_requests.dont_limit_qty ?
|
|
608
719
|
const storeWithMostQuantities = !!filteredInventoriesByTransferStores
|
|
609
720
|
? filteredInventoriesByTransferStores.reduce((storeA, storeB) => (0, toNumber_1.default)(storeA.qty.available) > (0, toNumber_1.default)(storeB.qty.available) ? storeA : storeB)
|
|
610
721
|
: undefined;
|
|
@@ -618,8 +729,10 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
|
|
|
618
729
|
transfersToUpdate[transferToUse.data().id] = dataForTransfer;
|
|
619
730
|
continue;
|
|
620
731
|
}
|
|
732
|
+
// B. If quantities are to be removed...
|
|
621
733
|
if (qteToUpdate < 0) {
|
|
622
|
-
|
|
734
|
+
// ... remove from all transfers until done, starting with transfers at status INITIALIZED, then by the store with the least quantities currently available
|
|
735
|
+
let qteToRemove = qteToUpdate * -1; // change to positive value to facilitate checks later. Will be changed to negative when saved in qteToUpdate props for each transfer
|
|
623
736
|
let inventoryUnitQteToRemove = (0, inventories_1.getConvertedUnitQuantity)(upItem.item.other_units, qteToRemove, 'inventory_unit', true);
|
|
624
737
|
const inventoriesByAvailabilityAsc = (0, orderBy_1.default)(filteredInventoriesByTransferStores, (i) => (0, toNumber_1.default)(i.qty.available));
|
|
625
738
|
const transfersByInventory = (0, orderBy_1.default)(transfersWithSameItem, (t) => [
|
|
@@ -635,7 +748,7 @@ const getItemsToUpdateByTransfer = (allCartTransfers, updatedItems) => {
|
|
|
635
748
|
const currentQte = sameProd.qte;
|
|
636
749
|
const qteToBeUpdated = currentQte < inventoryUnitQteToRemove ? currentQte : inventoryUnitQteToRemove;
|
|
637
750
|
const dataForTransfer = transfersToUpdate[transfer.data().id] || [];
|
|
638
|
-
dataForTransfer.push({ sku, ajustmentQte: qteToBeUpdated == 0 ? qteToBeUpdated : qteToBeUpdated * -1 });
|
|
751
|
+
dataForTransfer.push({ sku, ajustmentQte: qteToBeUpdated == 0 ? qteToBeUpdated : qteToBeUpdated * -1 }); // value changed back to a negative here
|
|
639
752
|
transfersToUpdate[transfer.data().id] = dataForTransfer;
|
|
640
753
|
inventoryUnitQteToRemove -= qteToBeUpdated;
|
|
641
754
|
if (qteToRemove <= 0)
|
|
@@ -658,6 +771,7 @@ const getILangForUpdateType = (updateType) => {
|
|
|
658
771
|
};
|
|
659
772
|
exports.getILangForUpdateType = getILangForUpdateType;
|
|
660
773
|
const getSubtotalToCheckForPromo = (allCartItems, currentCartSubtotal, space, feePromosTotalRemoved, removeServiceFees) => {
|
|
774
|
+
// ** NEW - Now excludes escompte supp. products from services when checking subtotal for promotions
|
|
661
775
|
const serviceFeeProducts = !!!removeServiceFees
|
|
662
776
|
? []
|
|
663
777
|
: allCartItems.filter((i) => !!i.is_service && !(0, g2_1.isEscompteSuppItem)(i.sku));
|
|
@@ -668,9 +782,11 @@ const getSubtotalToCheckForPromo = (allCartItems, currentCartSubtotal, space, fe
|
|
|
668
782
|
return (0, round_1.default)(((0, isNumber_1.default)(itemPrice) ? Number(itemPrice) : 0) * i.qte, space.data().product_preferences.decimals || 2);
|
|
669
783
|
});
|
|
670
784
|
let totalRemoved = serviceFeeSubtotal;
|
|
785
|
+
// If there is a service and fees total, calculates the service and fees total after taking into account their promos
|
|
671
786
|
if (!!totalRemoved) {
|
|
672
787
|
totalRemoved -= feePromosTotalRemoved;
|
|
673
788
|
}
|
|
789
|
+
// Removes that calculated total from the current subtotal to get the subtotal without services and fees, in order to calculate the right promo amount
|
|
674
790
|
return currentCartSubtotal - totalRemoved;
|
|
675
791
|
};
|
|
676
792
|
exports.getSubtotalToCheckForPromo = getSubtotalToCheckForPromo;
|
|
@@ -678,7 +794,15 @@ const getAllPromoAppliedPrices = (allPromos, subtotalToUse, items, space, isRefu
|
|
|
678
794
|
var _a;
|
|
679
795
|
let promoAmounts = [];
|
|
680
796
|
let updatedSubtotal = subtotalToUse;
|
|
797
|
+
// REMOVE PAYMENT INCENTIVE PROMOS FROM ARRAY
|
|
798
|
+
// Since this type of promos ('total_after_taxes') must be calculated and
|
|
799
|
+
// removed from total amount AFTER shipping and taxes are calculated,
|
|
800
|
+
// they will be dealt with later in process and must not count in "subtotalWithoutPromotions" prop
|
|
681
801
|
let cartPromos = allPromos.filter((c) => c.applies_to != Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
|
|
802
|
+
// REORDER PROMOS
|
|
803
|
+
// a. if promos apply to products, bring to front of array
|
|
804
|
+
// b. if promos contain a promo_code that applies to subtotal,
|
|
805
|
+
// push it to the end of the array to check that one last
|
|
682
806
|
cartPromos = (0, orderBy_1.default)(cartPromos, (p) => {
|
|
683
807
|
if ([Cart_1.CartPromoAppliesToEnum.PRODUCT, Cart_1.CartPromoAppliesToEnum.ITEMS].includes(p.applies_to))
|
|
684
808
|
return 1;
|
|
@@ -722,6 +846,7 @@ const getAllPromoAppliedPrices = (allPromos, subtotalToUse, items, space, isRefu
|
|
|
722
846
|
else {
|
|
723
847
|
amountToRemove = (_a = aPromo.amount_removed) !== null && _a !== void 0 ? _a : 0;
|
|
724
848
|
}
|
|
849
|
+
// round amountToRemove before removing from subtotal
|
|
725
850
|
amountToRemove = (0, round_1.default)(amountToRemove, 2);
|
|
726
851
|
const newSubtotal = amountUnit === IDiscountRule_1.ResultActionEnum.AMOUNT || aPromo.applies_to === Cart_1.CartPromoAppliesToEnum.PRODUCT
|
|
727
852
|
? updatedSubtotal - amountToRemove
|
|
@@ -749,6 +874,10 @@ const getAddressStrArray = (address) => {
|
|
|
749
874
|
].filter((addr) => !!addr.trim());
|
|
750
875
|
};
|
|
751
876
|
exports.getAddressStrArray = getAddressStrArray;
|
|
877
|
+
/**
|
|
878
|
+
* Returns all payement methods for a given cart
|
|
879
|
+
* @param cartData
|
|
880
|
+
*/
|
|
752
881
|
const getCartPaymentMethods = (cartData) => {
|
|
753
882
|
return !!cartData.payment_details
|
|
754
883
|
? (cartData.payment_details || []).map((p) => p.method)
|
|
@@ -757,9 +886,15 @@ const getCartPaymentMethods = (cartData) => {
|
|
|
757
886
|
: [];
|
|
758
887
|
};
|
|
759
888
|
exports.getCartPaymentMethods = getCartPaymentMethods;
|
|
889
|
+
/**
|
|
890
|
+
* Return last user to take payment for cart. Checks in order : 'completed_by' -> 'updated_by' -> 'processed_by' -> 'created_by'
|
|
891
|
+
* @param cartData The cart to check
|
|
892
|
+
* @param startCheckAt The step to start check at. Defaults to 'processed_by'
|
|
893
|
+
*/
|
|
760
894
|
const getLastUserWhoTookPayment = (cartData, startCheckAt = 'processed_by') => {
|
|
761
895
|
let foundUser = undefined;
|
|
762
896
|
let allSteps = ['completed_by', 'updated_by', 'processed_by', 'created_by'];
|
|
897
|
+
// Splice original array to only keep entries from specified startCheckAt property
|
|
763
898
|
allSteps.splice(allSteps.indexOf(startCheckAt));
|
|
764
899
|
const checkCartProp = (property) => {
|
|
765
900
|
const foundData = cartData[property];
|
|
@@ -778,6 +913,14 @@ const getLastUserWhoTookPayment = (cartData, startCheckAt = 'processed_by') => {
|
|
|
778
913
|
return foundUser;
|
|
779
914
|
};
|
|
780
915
|
exports.getLastUserWhoTookPayment = getLastUserWhoTookPayment;
|
|
916
|
+
// #region CUSTOM PRICES AND ESCOMPTES (added by POS)
|
|
917
|
+
/**
|
|
918
|
+
* Calculates applied amout for a custom added promo.
|
|
919
|
+
* @param item Cart item on which custom promo was applied
|
|
920
|
+
* @param type The custom promo type (unit price of added escompte)
|
|
921
|
+
* @param amount The fixed amount or percentage of custom price allocated
|
|
922
|
+
* @returns {number}
|
|
923
|
+
*/
|
|
781
924
|
const calculateAmountForCustomPromo = (item, type, amount) => {
|
|
782
925
|
if (type === Cart_1.CustomPromoType.UNIT_PRICE)
|
|
783
926
|
return amount;
|
|
@@ -786,6 +929,15 @@ const calculateAmountForCustomPromo = (item, type, amount) => {
|
|
|
786
929
|
return initialPrice - promoAmount;
|
|
787
930
|
};
|
|
788
931
|
exports.calculateAmountForCustomPromo = calculateAmountForCustomPromo;
|
|
932
|
+
// #endregion
|
|
933
|
+
// #region STORE CREDIT MANAGEMENT
|
|
934
|
+
/**
|
|
935
|
+
* Check if credit quantity for cart is valid and available.
|
|
936
|
+
* @param creditToBeUsedInCart Amount to be used in credits.
|
|
937
|
+
* @param customerID The customer's ID to check for available store credits.
|
|
938
|
+
* @param space The current space obj
|
|
939
|
+
* @param creditSlug La référence au type de store credit à vérifier
|
|
940
|
+
*/
|
|
789
941
|
const validateStoreCreditUsage = async (creditToBeUsedInCart, customerID, space, creditSlug) => {
|
|
790
942
|
const hasStoreCreditsSet = space.options.checkIfOptionIsSet('payment.space_has_store_credits');
|
|
791
943
|
if (!hasStoreCreditsSet) {
|
|
@@ -807,7 +959,10 @@ const validateStoreCreditUsage = async (creditToBeUsedInCart, customerID, space,
|
|
|
807
959
|
};
|
|
808
960
|
}
|
|
809
961
|
const creditAmount = creditToBeUsedInCart !== null && creditToBeUsedInCart !== void 0 ? creditToBeUsedInCart : 0;
|
|
962
|
+
// VALIDATIONS
|
|
963
|
+
// a. Valide que le crédit demandé est positif
|
|
810
964
|
let valid = creditAmount >= 0;
|
|
965
|
+
// b. Valide que le client a le reste nécessaire pour utiliser ses crédits comme mode de paiement
|
|
811
966
|
if (valid) {
|
|
812
967
|
let clientCheck = await space.customers.credits.validate(customerID, creditSlug, creditAmount);
|
|
813
968
|
valid = !clientCheck;
|
|
@@ -822,14 +977,24 @@ const validateStoreCreditUsage = async (creditToBeUsedInCart, customerID, space,
|
|
|
822
977
|
: {}));
|
|
823
978
|
};
|
|
824
979
|
exports.validateStoreCreditUsage = validateStoreCreditUsage;
|
|
980
|
+
// #endregion
|
|
981
|
+
/**
|
|
982
|
+
* Get total quantity of pallets purchased by a customer
|
|
983
|
+
* @param space - Space object
|
|
984
|
+
* @param customerId - Customer ID
|
|
985
|
+
* @returns Total quantity of pallets purchased
|
|
986
|
+
*/
|
|
825
987
|
const getPurchasedPalletsQuantityForCustomer = async (space, customerId) => {
|
|
826
988
|
const palletSku = '210000000';
|
|
827
989
|
const completedStatus = Cart_1.CartStatusEnum.COMPLETED;
|
|
828
990
|
try {
|
|
991
|
+
// 1. Get search index info for the space
|
|
829
992
|
const searchInfo = (0, searchIndexes_1.getFetchInfoAlgoliaAddioSearch)(space);
|
|
993
|
+
// 2. Fetch indexed completed orders for this customer that contain the pallet SKU (from 2026-01-01)
|
|
830
994
|
const startDate = (0, moment_1.default)('2026-01-01');
|
|
831
995
|
const endDate = (0, moment_1.default)();
|
|
832
996
|
const filterStr = `customer_id:${customerId} AND status:${completedStatus} AND (created_at:${startDate.unix()} TO ${endDate.unix()}) AND (items.${palletSku}.refunded:false OR items.${palletSku}.refunded:true)`;
|
|
997
|
+
// 3. Fetch all pages and sum pallet quantities
|
|
833
998
|
let totalPallets = 0;
|
|
834
999
|
let currentPage = 0;
|
|
835
1000
|
let nbPages = 1;
|