Rust discount function (one automatic discount evaluating all offers in priority order, parity with the Odoo engine), React Router admin with Polaris, theme app extension and app proxy pages, webhooks incl. GDPR, managed-pricing limits, and a Docker Compose stack (Postgres + Caddy HTTPS) for a single VPS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
1.3 KiB
TypeScript
25 lines
1.3 KiB
TypeScript
// Types for engine.js (used by the admin editor's example-cart preview).
|
|
export interface EngineScope { variantIds?: Set<string>; productIds?: Set<string>; collectionIds?: Set<string> }
|
|
export interface EngineOffer {
|
|
id: string;
|
|
type: "fixed" | "mix" | "bxgy" | string;
|
|
maxUses?: number;
|
|
discountType?: string;
|
|
value?: number;
|
|
lines?: { variantId?: string; productId?: string; quantity: number }[];
|
|
qty?: number;
|
|
scope?: EngineScope;
|
|
buyQty?: number;
|
|
getQty?: number;
|
|
getPercent?: number;
|
|
buyScope?: EngineScope;
|
|
getScope?: EngineScope;
|
|
}
|
|
export interface EngineUnit { lineId: string; variantId: string; productId: string; collectionIds: string[]; price: number }
|
|
export interface EngineApplication { offerId: string; discount: number; units: EngineUnit[]; getUnits: EngineUnit[] | null }
|
|
export function bundleDiscount(regular: number, discountType: string, value: number): number;
|
|
export function applyOffers(units: EngineUnit[], offers: EngineOffer[]): EngineApplication[];
|
|
export function allocateByLine(apps: EngineApplication[], options?: { bxgyGetUnitsOnly?: boolean }): Map<string, number>;
|
|
export function largestRemainderCents(amounts: number[]): number[];
|
|
export function toUnits(lines: { id: string; variantId: string; productId: string; collectionIds?: string[]; unitPrice: number; quantity: number }[]): EngineUnit[];
|