import type { CommerceCart, CommerceCartLineChange, CommerceItem } from '@evershop/evershop/types/commerceEvents'; /** * Builds commerce event data (`types/commerceEvents.ts`) from the cart and * order lines of the storefront's GraphQL (`ShoppingCartItem`). Amounts are * without tax: `finalPrice` and `lineTotalWithDiscount` are, whatever the * store's tax display setting (before an address, a store whose catalog * prices include tax has no rate to take out: see `types/commerceEvents.ts`). */ /** The fields of a cart or order line the events read */ export interface CommerceLine { productId: string | number; variantGroupId?: string | number | null; productSku: string; productName?: string | null; qty: number; thumbnail?: string | null; productUrl?: string | null; finalPrice?: { value: number; } | null; finalPriceInclTax?: { value: number; } | null; lineTotal?: { value: number; } | null; lineTotalWithDiscount?: { value: number; } | null; variantOptions?: Array<{ optionText?: string | null; } | null> | null; category?: { name?: string | null; } | null; } /** The fields of a cart the events read */ export interface CommerceCartSource { uuid?: string; currency: string; coupon?: string | null; totalQty?: number; items: CommerceLine[]; } /** The digits of the currency's minor unit (USD 2, JPY 0), 2 when unknown */ export declare function currencyDigits(currency?: string | null): number; /** * Rounds to the currency's minor unit. Core keeps a discounted line total * at 4 decimals (32.7273); a pixel expects 32.73. */ export declare function roundAmount(n: number, currency?: string | null): number; export declare function absoluteUrl(path?: string | null): string | undefined; /** The line's total after discounts, without tax */ export declare const netLineTotal: (line: CommerceLine) => number; /** The line's discount, without tax */ export declare const lineDiscountTotal: (line: CommerceLine) => number; /** `qty` of the line's units, valued as the line values them */ export declare function lineValue(line: CommerceLine, qty?: number, currency?: string): number; /** A cart or order line as an item; `qty` defaults to the line's */ export declare function toCommerceItem(line: CommerceLine, qty?: number, currency?: string): CommerceItem; export declare function toCommerceCart(cart: CommerceCartSource): CommerceCart; /** * A line's quantity change: `before` is the line before (undefined when it * is new), `after` the line now (undefined when it was removed). Returns * the event and its data, or null when the quantity did not change. */ export declare function toLineChange(before: CommerceLine | undefined, after: CommerceLine | undefined, cart: CommerceCartSource): { name: 'product_added_to_cart' | 'product_removed_from_cart'; data: CommerceCartLineChange; } | null; /** * Run code that publishes a commerce event. A failure is logged, never * thrown: a cart change must not fail because its event could not be built. */ export declare function publishSafely(publish: () => void): void;