Skip to content

Fix negative quantity validation error on tiered products#1087

Merged
daveearley merged 1 commit intodevelopfrom
fix/tiered-product-negative-quantity-validation
Mar 15, 2026
Merged

Fix negative quantity validation error on tiered products#1087
daveearley merged 1 commit intodevelopfrom
fix/tiered-product-negative-quantity-validation

Conversation

@daveearley
Copy link
Contributor

Summary

  • Clamp quantity_available to 0 using GREATEST() in the availability SQL query to prevent negative values when initial_quantity_available is set below quantity_sold
  • Skip availability validation for tiers sent with quantity=0 (unselected tiers) — these are never used to create order items
  • Prevent admins from setting initial_quantity_available below quantity_sold on a product price
  • Backfill migration to fix any existing product prices where quantity_sold > initial_quantity_available

Test plan

  • Unit tests for zero-quantity tier skip (3 tests)
  • Unit tests for admin safeguard validation (4 tests)
  • Full unit test suite passes (343 tests)

When initial_quantity_available was set below quantity_sold, the
computed quantity_available went negative, causing incorrect validation
errors for unrelated tiers sent with quantity=0.
@daveearley daveearley merged commit 853162b into develop Mar 15, 2026
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant