Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Mark volume pricing implemented, and record what the build taught

Damian Legawieca3b079eca8e5
diff --git a/docs/plans/6.0-volume-pricing.md b/docs/plans/6.0-volume-pricing.md
index 23c4b49b4d..e18add18ba 100644
--- a/docs/plans/6.0-volume-pricing.md
+++ b/docs/plans/6.0-volume-pricing.md
@@ -1,6 +1,7 @@
# Volume Pricing (Quantity Breaks + Banded Adjustments)
-**Status:** In progress — design finalized 2026-09-07; implementation started 2026-09-07
+**Status:** Implemented — schema, resolver, banded adjustment, Admin API and
+both dashboard tier editors shipped 2026-09-07 (spree/spree#14589)
**Target:** Spree 6.0 — fully (2026-09-07: first the schema/resolver phases were pulled into the major because `min_quantity` changes the row identity of the released `spree_prices` table; then the whole plan followed — shipping the feature in one release is faster than splitting the UI off by a release boundary)
**Depends on:** Catalog Agreement Rework (6.0-catalog-agreement-rework.md — implemented; owned lists + contextual rules), Price List Automatic Pricing (6.0-price-list-automatic-pricing.md — implemented; the ±% machinery this extends), B2B Quantity Rules (6.0-b2b-quantity-rules.md — the separate ordering axis)
**Author:** Damian + Claude
@@ -174,6 +175,31 @@ volume-discount promotion pair (`LineQuantity` rule + quantity-tiered
percent calculator); per-tier `kind: percent` on price rows (rejected —
bands on the adjustment cover it with the implemented semantics).
+## Notes from the build (2026-09-07)
+
+- **Adding a dimension to a table changes what its existing readers mean.**
+ `min_quantity` gave `spree_prices` a second row per variant per list, and
+ several readers were counting every row a variant had:
+ `Product#price_varies?` and `#lowest_price` quoted the cheapest *price-list*
+ row as the product's shop price, so a catalogue with any agreement attached
+ advertised a private contract price to every shopper (reproduced on sample
+ data: a toaster listing "from $23.99" against a $39.99 shop price). The leak
+ predated this plan — any price-list row already caused it — but ladders
+ deepen it, and the fix belongs here. `Product#shop_prices`,
+ `Variant.for_currency_and_available_price_amount`, `Products.with_currency`
+ and the line-item currency swap now all read base prices only. **The general
+ rule for the next such change: a column that changes row identity is not
+ finished at the writers and the resolver — the readers that never asked the
+ resolver are where it leaks.**
+- The break cap lives in `Prices::BulkUpsert` rather than in a controller,
+ because three write paths reach that service and none of them run model
+ validations. Counted the same way in the model and the service: breaks above
+ the ordinary price, placeholder rows not counted.
+- A band of exactly 0% is refused rather than stored: a factor of 1 makes the
+ list decline to price the line at all, so a band meaning "no further
+ discount here" would fall through to the next list. Removing the band is how
+ a ladder stops.
+
## References
- Merchant feedback, 2026-09 (fixed + percentage tiers; catalog
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index d1cf688d06..6b7c71b4f3 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -4854,6 +4854,38 @@ core use a symbol and parameters, never a preformatted string; nothing in the
dashboard prints an API `label`/`name`/`description` directly; shared admin copy
goes in `dashboard-core` locales, never in `packages/seller-dashboard`.
+## 2026-09-07 — A column that changes row identity is not finished at the writers
+
+Building volume pricing (`6.0-volume-pricing.md`) added `min_quantity` to
+`spree_prices`, giving a variant several rows per price list where it had
+one. The writers and the resolver were updated; the readers that never
+ask the resolver were not, and that is where it showed.
+
+`Spree::Product#price_varies?` and `#lowest_price` iterate the product's
+`prices` — a `has_many through: variants` covering every row, price-list
+rows included. On sample data a toaster with a B2B agreement attached
+advertised "from $23.99" — a private contract rung — against a $39.99
+shop price, and reported its price as varying when it does not. The same
+shape sat in `Products.with_currency`,
+`Variant.for_currency_and_available_price_amount` and the line-item
+currency swap, which picked `prices.where(currency:).first` with no list
+filter and could now land on an arbitrary rung.
+
+**The leak predates the column.** Any price-list row already caused it,
+since none of those readers filtered `price_list_id`. What
+`min_quantity` changed is the odds: one stray row became a ladder of
+them, and the cheapest is the one a "lowest price" reader finds. Fixed by
+giving `Product` a `shop_prices` reader and scoping the three others to
+base prices.
+
+**The reusable part:** when a migration adds a dimension to a table,
+grep every reader that counts, joins to, or picks from that table without
+going through the thing that owns its semantics — here the pricing
+resolver. Updating the writers and the one canonical reader is the half
+of the job that is easy to see. Pricing paths were fine throughout:
+`Pricing::Context` carries quantity everywhere it matters and the cache
+key includes it.
+
## 2026-09-07 — Volume pricing implementation: CSV deferred, the cap is a validation, and a ladder needs no quantity-1 rung
Settled before building `6.0-volume-pricing.md`. Three of the four are