Cart
Sale lines with quantity controls, discounts, charges, totals, and payment actions
Import
import { Cart } from '@tallyui/components';Usage
import { useSale } from '@tallyui/pos';
import { Cart } from '@tallyui/components';
// Inside a component under TaxProvider.
const sale = useSale(settings, { registerId, cashierRef });
<Cart sale={sale} />Renders the sale's lines with quantity and removal controls, line and order discounts, totals, and cash or card terminal actions. Price editing appears when permitted, and the charge form appears when the sale's capabilities support it. The charge form takes a fee as a percent of the cart, whose Price cell then shows the percent, and a fee or shipping charge's own Amount Includes Tax choice, which starts at the order's tax mode.
Pass orderActions={false} when the app hosts the Order discount and Add charge controls in its own menu, as WCPOS v2's cart "+" menu does. Applied order discounts, fees and shipping still show with their own Remove controls.
Pass orderDiscountChips={false} when the app draws the applied order discounts itself, for example as a removable Discount row in afterSubtotal, and add order.display.orderDiscountMinor to couponDiscountMinor so the totals' Discount row does not count them twice.
Pass checkout to use WCPOS v2's foot, CartFoot, in place of the Cash and Card terminal buttons: one "Checkout" button that reads the order total and calls onCheckout, beside a ⋮ menu of the actions the app passes. The label follows the sale as lines change, and Checkout is disabled while the cart is empty, as Cash and Card terminal are. Without checkout, the Cash and Card terminal buttons show as before.
The lines sit under CartColumnHeads (Qty, Item, Price and Total by default; columns changes which show and their order). Each line shows its variant attributes under the name, and its regular price struck through when the line costs less, from the line's attributes and regularUnitPriceMinor. The Price column is hidden when the cart is under 300 wide, or the window is under 768 wide or 480 tall. The Discount and Price actions sit with each line's quantity buttons.
With lineEditor="popover", pass lineCommit="close" for WCPOS v2's quantity and price keypads: closing either any way but Escape writes what was typed, and a price refused on such a close shows under its line. On the quantity keypad, − and + write at once and − turns into Remove at a quantity of 1.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
sale | ReturnType<typeof useSale> | required | The sale from useSale |
taxLabel | (ratePpm: number) => string | (ratePpm: number) => `Tax ${ratePpm / 10000}%` | Formats each tax row's label from its rate in parts per million |
taxClasses | ReadonlyArray<{ id: string; label: string }> | --- | Tax class choices passed to the charge form |
canEditPrice | boolean | false | Shows a Price action on each line; pass the till's price-edit permission |
onPriceChange | (change: { lineId: string; fromMinor: number; toMinor: number; reason?: string }) => void | --- | Called after a price is applied for the app's audit log; the reason is kept only in this callback |
quickDiscounts | readonly number[] | --- | Quick-discount keys on each line's PriceForm, e.g. the app's cart.quickDiscounts setting (default [5, 10, 15]); needs canEditPrice |
lineEditor | 'inline' | 'popover' | 'inline' | popover: tapping a line's quantity or price opens a LinePopover keypad, the price one with quickDiscounts and only with canEditPrice, showing the regular price struck through when the line is on sale. The line is one row with no buttons under it: Discount, Price (only when the Price column folds) and Remove are in the quantity popover, and Discount in the price popover. inline keeps the − / + buttons and the Price form only |
lineCommit | 'apply' | 'close' | 'apply' | With lineEditor="popover": close gives both popovers LinePopover's commit="close" (Done; Escape discards and any other close writes what was typed, a refused price showing under the line). The quantity popover also gets − and + steppers, with Remove at 1 in place of the Remove action |
orderActions | boolean | true | Shows Cart's own Order discount button and Add charge control; pass false when the app hosts them in its own menu |
orderDiscountChips | boolean | true | Draws applied order discounts as removable chips under the lines; pass false when the app draws them itself, e.g. in afterSubtotal |
checkout | { onCheckout: () => void; actions?: readonly CartFootAction[] } | --- | Swaps the Cash and Card terminal buttons for CartFoot's Checkout button and ⋮ menu |
noteSheet | { label?: string } | --- | With checkout: puts "Order details" first in the ⋮ menu and draws the note row from the sale's note; both open OrderNoteSheet, which writes through sale.setNote |
showTotal | boolean | true | Draws the totals' Total row; pass false for v2's cart, where the total is on the CartFoot Checkout button |
tenderLedger | { methods?: PaymentMethodDescriptor[]; confirmVoid?: boolean } | --- | WCPOS v2's checkout cart: during the tender stage, a Payments section under the totals lists each leg with its status, its time as on Tender and Cancel payment, then Total, Paid and Remaining, in place of the foot. methods names the legs, as on Tender; pair it with <Tender ledger={false} />. confirmVoid asks WCPOS v2's "Cancel this payment?" before a leg is voided, as on Tender (default false) |
picker | { picked: Readonly<Record<string, number>>; paid: Readonly<Record<string, number>>; unitMinor: (lineId: string, units: number) => number; onPick: (lineId: string, units: number) => void } | --- | WCPOS v2's split-by-item bill: the cart is read-only, and each line whose quantity is a positive whole number, whose total is not negative and that has units left unpaid shows this payment's − n of unpaid + stepper in its quantity cell, with what the picked units add under it. picked is this payment's units per line id, paid the units earlier live payments took, unitMinor(lineId, units) the minor units that many more units of the line add after the paid ones, and onPick(lineId, units) sets this payment's units |
columns | CartColumnSettings | — | WCPOS v2's Cart Settings › Columns: which columns show and in what order (order), the on-sale strike (price.onSale), a read-only Regular Price column, Split under a quantity above 1 (quantity.split) and the SKU under the name (name.sku); see CartColumnHeads |
chargeTaxSwitch | boolean | true | Shows ChargeForm's Amount Includes Tax switch on fees and shipping; pass false to hide it, so a new charge takes the store's tax mode. An existing charge keeps the flag it already has |
The totals and the foot sit 8 px inside the cart's edge and 8 px apart, WCPOS v2's cart foot inset.