You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature: Real product variants (variant groups/options with SKU, barcode, price delta, optional stock) #357
Feature: Real product variants (variant groups/options with SKU, barcode, price delta, optional stock)
Summary
Implement the dormant variant concept as a real catalog model: Coffee → Small / Medium / Large, where a variant can affect SKU, barcode, price and optionally stock.
What already exists
order_items.variant_selection column is already persisted (main/db.ts:4294; written via main/routes/orders.ts ~549/760) but the product create/update API never manages variants — it's always null today.
Frontend Product type already has variants: Record<string, unknown>[] | null (frontend/src/lib/types.ts:81) — unused.
Proposed model
variant_groups
id, product_id, name ("Size"), required, min/max
product_variants
id, product_id, group_id, name ("Large"),
sku, barcode, price_delta, stock_quantity, is_active
For the first release support one common case well (e.g. Coffee → Small/Medium/Large), including variant-level barcode scanning.
Important constraint
Keep variants separate from add-ons. Add-ons are "Large Coffee → extra shot / oat milk" on an already-chosen product; variants are the product's own sizing. Their inventory and reporting meaning differ.
Suggested acceptance criteria
Product create/update API can create/manage variant groups and variants.
POS lets you pick a variant; variant_selection gets populated; price/SKU/barcode/stock resolve through the variant.
Barcode scan of a variant barcode resolves to that variant.
Migration preserves existing order data (variant_selection snapshot already present).
Implementation is up on branch feat/product-variants in #959, following the approved "Native Product Variants & Omnichannel Catalog Foundation" architecture.
The approved architecture, in the shape it actually landed:
Normalized 1-to-many, never destructive.product_variants is a real table with a products FK ON DELETE CASCADE. A merchant removing a size soft-deactivates it (is_active = 0) rather than deleting the row, so historical receipts, bills, and tax reports keep resolving the variant they were sold against. This is the CSO's zero-data-loss condition, and it is why the back-office "remove" button is a toggle, not a delete.
Backend-authoritative pricing in one module.main/services/product-variants.ts holds resolveOrderItemVariant and variantUnitPrice, and it is the only place the rule lives. Order creation, item append, and the cart tax preview all call it. That is deliberate: the checkout preview and the order it becomes resolve the variant through the same lookup, so they cannot disagree about price.
Discrete vs. multiplier inventory are separate mechanisms. A variant with track_inventory depletes its own stock pool; a variant linked to inventory_product_id depletes the base ingredient by inventory_deduction_quantity (a Large pizza consuming 2x dough). resolveInventoryDeduction makes the variant decide first and falls back to the product's own rules, so existing products are untouched. The ledger stays pool-aware: movements are chained by product AND variant, which is what lets a cancellation refund the exact pool the sale depleted.
Variants are mandatory identity, add-ons stay optional modifiers. A product with active variants cannot be sold without one - the backend returns 400 rather than silently selling at the base price. Add-on groups continue to layer on top of the chosen variant.
Cart identity carries the variant.generateCartItemId canonicalizes { productId, variantId, addons, specialInstructions }, so two lines with the same variant merge and the same product with a different variant stays on its own line.
One heading rule across every surface. The variant is named on the classic receipt, KOT, delivery slip, kitchen display, and the browser print mirror, so the kitchen and the customer ticket never disagree about what was sold.
Barcode resolution. A scanned code resolves to exactly one sellable thing - one product or one active variant - enforced by a catalog-wide uniqueness check across products and their variants.
Offline-first is unaffected: this is local SQLite plus the existing Express API, with no new network dependency and no change to the static desktop export boundary.
Activity
khaira777 commentedon Oct 4, 2026
Implementation is up on branch
feat/product-variantsin #959, following the approved "Native Product Variants & Omnichannel Catalog Foundation" architecture.The approved architecture, in the shape it actually landed:
Normalized 1-to-many, never destructive.
product_variantsis a real table with aproductsFKON DELETE CASCADE. A merchant removing a size soft-deactivates it (is_active = 0) rather than deleting the row, so historical receipts, bills, and tax reports keep resolving the variant they were sold against. This is the CSO's zero-data-loss condition, and it is why the back-office "remove" button is a toggle, not a delete.Backend-authoritative pricing in one module.
main/services/product-variants.tsholdsresolveOrderItemVariantandvariantUnitPrice, and it is the only place the rule lives. Order creation, item append, and the cart tax preview all call it. That is deliberate: the checkout preview and the order it becomes resolve the variant through the same lookup, so they cannot disagree about price.Discrete vs. multiplier inventory are separate mechanisms. A variant with
track_inventorydepletes its own stock pool; a variant linked toinventory_product_iddepletes the base ingredient byinventory_deduction_quantity(a Large pizza consuming 2x dough).resolveInventoryDeductionmakes the variant decide first and falls back to the product's own rules, so existing products are untouched. The ledger stays pool-aware: movements are chained by product AND variant, which is what lets a cancellation refund the exact pool the sale depleted.Variants are mandatory identity, add-ons stay optional modifiers. A product with active variants cannot be sold without one - the backend returns
400rather than silently selling at the base price. Add-on groups continue to layer on top of the chosen variant.Cart identity carries the variant.
generateCartItemIdcanonicalizes{ productId, variantId, addons, specialInstructions }, so two lines with the same variant merge and the same product with a different variant stays on its own line.One heading rule across every surface. The variant is named on the classic receipt, KOT, delivery slip, kitchen display, and the browser print mirror, so the kitchen and the customer ticket never disagree about what was sold.
Barcode resolution. A scanned code resolves to exactly one sellable thing - one product or one active variant - enforced by a catalog-wide uniqueness check across products and their variants.
Offline-first is unaffected: this is local SQLite plus the existing Express API, with no new network dependency and no change to the static desktop export boundary.