Skip to content

The only tool you need to know what is happening and how to fix it.

439 B
Raw Blame
// Cart and order totals. Prices are integer cents.
export function priceCart(lines) {
  const items = lines.map((l) => ({ id: l.id, name: l.name, qty: l.qty, lineCents: l.price_cents * l.qty }));
  const subtotalCents = items.reduce((s, i) => s + i.lineCents, 0);
  const shippingCents = subtotalCents >= 5000 || items.length === 0 ? 0 : 495;
  return { items, subtotalCents, shippingCents, totalCents: subtotalCents + shippingCents };
}