Skip to content

Cart quantity badge doesn't increment when same product is added with notes #16

Closed

Description

@khaira777

Description

When an item is added to cart with notes/special instructions, and then more of the same item (without notes, or with different notes) is added, the quantity badge on the product grid tile does not increment. It only reflects the quantity of the first matching cart item, not the total across all variants of the same product.

Steps to Reproduce

  1. Add "Latte" to cart (no notes) → grid badge shows 1 ✅
  2. Add "Latte" again with notes "no sugar" → grid badge still shows 1 ❌ (should be 2)
  3. Add "Latte" again without notes → grid badge still shows 1 ❌ (should be 3)

For items without notes, the badge increments correctly.

Root Cause

In frontend/src/store/cart.ts, the generateCartItemId function creates a unique cart item ID per product + addons + notes combination:

function generateCartItemId(productId, addons, specialInstructions) {
  const parts = [String(productId)];
  if (addons.length > 0) parts.push(addons.map(a => a.id).sort().join(','));
  if (specialInstructions) parts.push(specialInstructions);
  return parts.join('-');
}

So "Latte" (no notes) and "Latte with no sugar" become two separate cart items with different IDs — which is correct for order processing.

But in frontend/src/components/pos/ProductGrid.tsx, the badge uses find():

const inCart = cart.items.find((i) => i.product.id === product.id);
// ...
{inCart.quantity}  // only shows quantity of FIRST match

find() returns only the first cart item matching the product ID, so the badge only shows that one item's quantity instead of the total across all variants.

Expected Behavior

The quantity badge should show the sum of all cart items for that product ID, regardless of notes/addons differences.

Suggested Fix

Replace find() with a reduce() to sum quantities:

const inCartQty = cart.items
  .filter((i) => i.product.id === product.id)
  .reduce((sum, i) => sum + i.quantity, 0);

Then render {inCartQty > 0 && <span>{inCartQty}</span>}.

Environment

  • Affects all platforms (not Linux-specific)
  • Affects all POS grid views where product tiles show cart quantity badges

Activity

  1. added theissue type on Jul 6, 2026
  2. added a commit that references this issue on Jul 11, 2026
    7974aa4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions