import Space from '../lib/Space'; import ICart, { CartErrorEnum, CartPromoAppliesToEnum, CustomPromoType, ICartAssignedUser, ICartItem, ICartPromoApplied, PaymentTypeEnum, UpdateTypeEnum } from '../Interfaces/Cart'; import { ICustomPriceItem } from '../Interfaces/G2'; import IInventoryItem from '../Interfaces/Product/IInventoryItem'; import ILang from './string'; import ISpace, { ISpaceOptions } from '../Interfaces/Space'; import IAddress from '../Interfaces/Address'; import IStore from '../Interfaces/Store'; import ICustomer from '../Interfaces/Customer'; import { IIndexedCart } from '../Interfaces/Algolia'; import { unitTypeEnum } from './products'; import { TransferRequest } from '../lib/TransferRequest'; import IIndexedProduct from '../Interfaces/Indexed/Product'; import IPayment from '../Interfaces/Payment'; import IUser from '../Interfaces/User/IUser'; export declare const updateCartItems: (currentCart: ICart, items: { sku: string; qte: number; qte_override?: boolean; }[], fetchInventory: (sku: string) => Promise, shouldCheckInventory?: boolean, handleInventoryError?: ((shouldSave?: boolean) => Promise) | undefined) => Promise<{ updatedCart: ICart; updatedItems: { sku: string; updated: boolean; error?: ILang; }[]; }>; /** * For now, copy of `updateCartItems` function in most aspects, with slight optim. Meant to replace updateCartItems eventually! * 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. * @param currentCartItems * @param items * @param fetchInventory * @param options.shouldCheckInventory * @param options.handleInventoryError * @param options.shouldCheckStoreInventory * @param options.useReservedInventory if the inventory is reserved on add to cart */ export declare const verifyAndReturnToBeUpdatedCartItems: (currentCartItems: ICartItem[], items: { sku: string; qte: number; qte_override?: boolean; }[], fetchInventory: (sku: string) => Promise, options?: { shouldCheckInventory?: boolean | undefined; handleInventoryError?: ((shouldSave?: boolean) => Promise) | undefined; shouldCheckStoreInventory?: string | undefined; useReservedInventory?: boolean | undefined; }) => Promise<{ updatedCartItems: ICartItem[]; updatedDetails: { sku: string; updated: boolean; error?: ILang; }[]; }>; export declare const deleteCartItem: (currentCart: ICart, sku: string[], onlyIfUpsellOf?: string) => ICart; export declare const priceWasOverridden: (itemToCheck: ICartItem) => boolean; export declare const getActualPromoPrice: (item: ICartItem, output: unitTypeEnum) => number; export declare const getActualDiscountPrice: (item: ICartItem, output: unitTypeEnum) => number; /** * Generate a cart item from corresonding indexedProduct * @param indexedProduct * @param sku * @param qte */ export declare const generateCartItemForSku: (indexedProduct: IIndexedProduct, sku: string, qte: number) => Promise; export declare const addCartItems: (currentCart: ICart, newItems: ICartItem[], fetchInventory: (sku: string) => Promise, shouldCheckInventory: boolean | undefined, handleInventoryError: ((shouldSave?: boolean) => Promise) | undefined, defaultAdd?: boolean, isServiceUpsellOfSku?: boolean, customPriceList?: ICustomPriceItem[]) => Promise<{ cartData: ICart; added: boolean; updated: boolean; maxQtyItems: boolean; }>; /** * Optimized copy of addCartItems function for now. Will eventually replace addCartItems. * Verify a list of items to be potentially added to cart. * @param currentCart * @param newItems * @param fetchInventory * @param options */ export declare const verifyAndReturnToBeAddedCartItems: (currentCart: ICart, newItems: ICartItem[], fetchInventory: (sku: string) => Promise, options?: { shouldCheckInventory?: boolean | undefined; handleInventoryError?: ((shouldSave?: boolean) => Promise) | undefined; shouldCheckStoreInventory?: string | undefined; defaultAdd?: boolean | undefined; isServiceUpsellOfSku?: boolean | undefined; customPriceList?: ICustomPriceItem[] | undefined; useReservedInventory?: boolean | undefined; }) => Promise<{ cartData: ICart; added: boolean; updated: boolean; hasErrors: boolean; }>; export declare const getCurrentProvince: (provinceToCheck: string) => { value: string; label: string; label_en: string; } | undefined; export declare const getTaxProvinceFromShippingAddress: (address: IAddress) => string | undefined; /** * Constructs and returns data for indexed cart (algolia or addio) * @param cartData - Current cart data * @param space - Space object * @param options.setPaidAtIfUndefined - Optionnal - If true, will set paid_at with current date * @param options.customer - Optionnal - If defined, adds info based on customer to indexedCart * @param option.createdAt - Optionnal - If defined, added to indexedCart, else null value added * @param option.updatedAt - Optionnal - If defined, added to indexedCart, else null value added * @param associatedTransfers - Optionnal, used to pass transfers and statuses to indexed cart. Will only be added if cart's has_transfers prop is true * @returns */ export declare const getIndexedCartData: (cartData: ICart, space: Space, options?: { setPaidAtIfUndefined?: boolean; customer?: ICustomer; createdAt?: Date; updatedAt?: Date; associatedTransfers?: IIndexedCart['has_transfers']; }) => IIndexedCart; export declare const getPaidByForIndexedCart: (order: ICart) => { paid_by?: PaymentTypeEnum | null; multiple_payments?: boolean | null; }; export declare const getAssignedToInfo: (order: ICart) => { assigned_to: string | null; }; export declare const getShippingStoreInfo: (order: ICart, space: Space) => { store: { id: any; name: any; }; }; export declare const checkIfShippingSameAsBilling: (cart: ICart) => boolean; export declare const getOrderStoreInfo: (spaceData: ISpace, storeAddress: IAddress) => { id: string | undefined; name: string; }; export declare const getModifiedItems: (newItems: ICartItem[], oldItems: ICartItem[]) => ICartItem[]; /** * Get all active transfers for a cart where given items are found * @param allTransfersForCart All transfers associated to a given cart * @param cartItems All cart items for whitch to check transfers if found * @param spaceOptions Used to check if TO_BE_PREPARED should accept item updates without status change */ export declare const getActiveTransfersByItemInCart: (allTransfersForCart: TransferRequest[] | undefined, cartItems: ICartItem[], spaceOptions: ISpaceOptions | undefined) => { sku: string; transfers: TransferRequest[]; hasUpdatableTransfer: boolean; hasNonUpdatableTransfer: boolean; }[]; /** * Get the sale unit slug for a cart item * * @param item the cart item * @returns unit slug or empty if not found */ export declare const getItemSaleUnitSlug: (item: ICartItem) => string; type TransfersWithItemsToUpdate = { [transferID: string]: { sku: string; ajustmentQte: number; }[]; }; /** * Constructs an object for each transfer, with corresponding products to update and by which quantity * @param allCartTransfers All transfer objects associated to a given cart * @param updatedItems Array of pertinent data per item updated to determine which transfers to update quantities for * @param spaceOptions Used to check if TO_BE_PREPARED should accept item updates without status change * @returns {TransfersWithItemsToUpdate | undefined} */ export declare const getItemsToUpdateByTransfer: (allCartTransfers: TransferRequest[], updatedItems: { item: ICartItem; qteToUpdate: number; inventoryItem: IInventoryItem | undefined; }[], spaceOptions: ISpaceOptions | undefined) => TransfersWithItemsToUpdate | undefined; export declare const getILangForUpdateType: (updateType: UpdateTypeEnum | undefined) => ILang; export declare const getSubtotalToCheckForPromo: (allCartItems: ICartItem[], currentCartSubtotal: number, space: Space, itemPromos: ICartPromoApplied[], removeServiceFees?: boolean, removeDiscounted?: boolean) => number; export declare const getAllPromoAppliedPrices: (allPromos: ICartPromoApplied[], subtotalToUse: number, items: ICartItem[], space: Space, isRefund?: boolean) => { id: string; subtotalBefore: number; subtotalAfter: number; amountRemoved: number; productTotalAmount: number; appliesTo: CartPromoAppliesToEnum; }[]; /** Retrieves the original discount price of an item. @param {ICartItem} item - The cart item object. @param {'%' | '$'} output - The desired output format: percentage ('%') or currency ('$'). @returns - The original discount price. */ export declare const getOriginalPromoPriceForItem: (item: ICartItem, output: unitTypeEnum) => number; /** Retrieves the original promo price of an item. @param {ICartItem} item - The cart item object. @param {unitTypeEnum} output - The desired output format: PERCENT ('%') or AMOUNT ('$'). @returns - The original promo price. */ export declare const getOriginalDiscountPriceForItem: (item: ICartItem, output: unitTypeEnum) => number; /** * Reajusts promo price with a provided "original" regular price amount * @param item * @param original * @returns the cart item with updated promo price */ export declare const adjustPromoPrice: (item: ICartItem, original: number) => ICartItem; export declare const getAddressStrArray: (address: IAddress) => string[]; /** * Returns all payement methods for a given cart * @param cartData */ export declare const getCartPaymentMethods: (cartData: ICart) => PaymentTypeEnum[]; type onlyCartUserProps = Pick; /** * Return last user to take payment for cart. Checks in order : 'completed_by' -> 'updated_by' -> 'processed_by' -> 'created_by' * @param cartData The cart to check * @param startCheckAt The step to start check at. Defaults to 'processed_by' */ export declare const getLastUserWhoTookPayment: (cartData: ICart, startCheckAt?: keyof onlyCartUserProps) => ICartAssignedUser | undefined; /** * Construct assigned user data from user provided. * @param user IUser data to use * @param atStore Optionnal. Store where assgined user did something to cart * @param updateType Optionnal. Defaults to "cart content" */ export declare const getAssignedUserData: (user: IUser, atStore?: IStore, updateType?: UpdateTypeEnum) => ICartAssignedUser; /** * Constructs and returns an IPayment object for store credit * @param storeCreditSlug The associated store credit's slug * @param amount The amount of credits used as payment * @returns {IPayment} */ export declare const constructStoreCreditPaymentEntry: (storeCreditSlug: string, amount: number) => IPayment; /** * Calculates applied amout for a custom added promo. * @param item Cart item on which custom promo was applied * @param type The custom promo type (unit price of added escompte) * @param amount The fixed amount or percentage of custom price allocated * @param substractAmountIfUnitPrice Optionnal. If true, amount received is removed from initialPrice. Else, amount is returned as is. * @returns {number} */ export declare const calculateAmountForCustomPromo: (item: ICartItem, type: CustomPromoType, amount: number, substractAmountIfUnitPrice?: boolean) => number; /** * Check if credit quantity for cart is valid and available. * @param creditToBeUsedInCart Amount to be used in credits. * @param customerID The customer's ID to check for available store credits. * @param space The current space obj * @param creditSlug La référence au type de store credit à vérifier */ export declare const validateStoreCreditUsage: (creditToBeUsedInCart: number, customerID: string | undefined, space: Space, creditSlug: string) => Promise<{ valid: boolean; error?: CartErrorEnum | undefined; }>; /** * Get total quantity of pallets purchased by a customer * @param space - Space object * @param customerId - Customer ID * @returns Total quantity of pallets purchased */ export declare const getPurchasedPalletsQuantityForCustomer: (space: Space, customerId: string) => Promise; export declare const shouldIgnoreInventoryForItem: (item: ICartItem) => boolean; /** * Builds a unique sku for a custom (temp) product when the same predefined sku is added more than once to a cart. * If the base sku is not already present, it is returned as-is. Otherwise an iterative "-temp-X" suffix is appended, * incrementing X until a sku not already present in the cart is found. * @param baseSku The predefined sku selected for the custom product * @param existingItems The cart items already in the cart */ export declare const generateUniqueTempSku: (baseSku: string, existingItems: ICartItem[]) => string; /** * Strips the iterative "-temp-X" suffix added by {@link generateUniqueTempSku}. * @param sku */ export declare const stripTempSuffix: (sku: string) => string; export {};