Skip to content

fix(cart): price option values on every basket mutation; keep shared option groups apart - #54

Merged
mekedron merged 9 commits into
mainfrom
fix/basket-option-prices
Oct 12, 2026
Merged

mekedron merged 9 commits into
mainfrom
fix/basket-option-prices

Conversation

@mekedron

Copy link
Copy Markdown
Owner

Follow-up to #52 and #53 (both by @zom-2018). Merge order: #52 → #53 → this PR. Until #52 and #53 are merged, this diff also shows their commits; after that only the five commits below remain.

What

  1. Basket mutations price option values from the catalog (c34b136). Wolt's basket responses list selected option values without a price, and every mutation resends the whole venue basket. With fix(checkout): recover option value prices from the catalog #53 alone, checkout works, but once a basket holds a line with options, wolt cart add and wolt cart remove (and MCP wolt_cart_add / wolt_cart_remove) fail for any item in that venue with option ... value ... has no current price. Reproduced live. New basketprices.Fill reads the venue assortment first, then the item endpoint for lines the assortment does not price. It fails closed when a value has no price anywhere. fix(checkout): recover option value prices from the catalog #53's price helpers move to payloadutil so checkout and mutations share one implementation.
  2. Option groups that share one library group stay separate (4e5bf63). Real dishes reuse one library group for several item-level groups (live example: Sultan Shish Kebab "Vegan Choice", 4 × "Täytteet Fantasialle" with different min/max). fix(cart): send item-level option group ids in basket options #52 merged them into one group that carried the last item-level id. Now each item-level group is its own basket group, and an ambiguous library id is rejected with the item-level ids listed.
  3. E2E tests in test/e2e/cli_cart_options_test.go (run by Go CI). They cover cart add --option writes library option ids; Wolt app shows default choices #50, checkout preview fails with 'has no current price' for baskets with options #51 and (1) through the real CLI commands with Wolt's payload shapes. All fail on main; the add and remove cases also fail with only fix(cart): send item-level option group ids in basket options #52 and fix(checkout): recover option value prices from the catalog #53 applied.
  4. Live smoke option-groups leg. It adds a dish with a paid option using the menu's library id, then asserts the item-level id and the line price base + option, previews checkout, does a partial removal and cleans up.
  5. Docs for option group ids and line prices.

Verification

  • go build, go test ./..., go test -race ./..., shellcheck are green. golangci-lint reports only the existing SA5011 in root_and_common_test.go, which this PR does not touch.
  • Live on the real API (Espoo, FIN), with the account basket empty before and after:
    • Library-id add and item-level-id add both work. The basket stores item-level ids.
    • Lines cost 18.40 and 2 × 18.90. Checkout "Item subtotal" is 56.20.
    • Partial remove and full remove work.
  • scripts/live-smoke.sh with WOLT_SMOKE_CART=1: 26 passed, 0 failed. Run against a main binary, it fails at options cart line.

OlegXXL and others added 9 commits October 12, 2026 16:02
Wolt keys a dish's options by an item-level "id" and references the shared
option-library group through "option_id". buildItemPayloadFromAssortment
replaced the item-level group with the library group, so the basket was
written with library ids. The basket API accepts that, but the Wolt app only
recognises item-level ids and silently shows the default choices instead.

Rewrite the resolved group to carry the item-level id (keeping the library id
as option_id) and let --option accept either id.
Wolt's basket response lists chosen option values by id and count only, so
BuildBasketUpsertItem rejected any basket with options as having no current
price, and checkout preview failed. Fill missing value prices from the catalog
payloads Build already loads; values with no known price are still rejected.
The basket line price was saved as the dish's base price only, so a basket with
paid option values (for example a +4.50 protein) showed and previewed the base
price while the dish costs more. Save base price plus the selected option
values, which also keeps cart and checkout preview consistent. Weighted lines
keep their weight-based pricing.
…e-prices

Both branches add a test to internal/cli/cart_helpers_test.go at the same
spot; the resolution keeps TestBuildBasketOptionsUsesItemLevelOptionGroupID
from #52 and TestBasketOptionsTotalSumsPaidValues from #53. With this merge
#53 applies cleanly on main once #52 is merged.
…asket

Wolt's basket responses list selected option values by id and count only,
while BuildBasketUpsertItem requires a price for every value. #53 fills
those prices for the checkout preview, but every basket mutation also
rebuilds and resends all lines of the venue basket: once a basket held one
line with options, `wolt cart add` and `wolt cart remove` (and the MCP
wolt_cart_add / wolt_cart_remove tools) failed for any item in that venue
with "option ... value ... has no current price".

basketprices.Fill restores the missing prices from the venue assortment and,
for lines the assortment does not price, from the item endpoint. A basket
without unpriced values makes no extra requests, and a value priced nowhere
stays unpriced, so the mutation still fails closed instead of guessing.

The option value price index and line filling from #53 move to payloadutil
(OptionValuePriceIndex, UnpricedOptionValueIDs, WithOptionValuePrices) so
checkout and the basket mutations share one implementation.

Verified live (Espoo, FIN): a basket with a priced option line could not be
changed by main; with this change add, partial remove, remove and checkout
preview all succeed.
A dish can use one library option group for several of its own groups,
e.g. "pick 1 / 2 / 3 toppings" (seen live on Sultan Shish Kebab's "Vegan
Choice"). buildItemPayloadFromAssortment collapsed them into one group
carrying the last item-level id, so only that group could be selected.

Every item-level group now becomes its own basket group with the library
values. A library id that backs several groups no longer names a single
group: --option rejects it and lists the item-level ids to choose from.
Runs `wolt cart add`, `wolt cart remove` and `wolt checkout` against Wolt's
real payload shapes for restaurant options (item-level group ids next to
library ids, basket values without prices):

- cart add with a library id, an item-level id or names stores the
  item-level id, prices the line as base + paid option, and resends the
  basket's existing option line with its catalog price (#50, #51);
- cart remove prices the remaining lines from the assortment, asking the
  item endpoint only for what the assortment lacks, and refuses a value
  priced nowhere without mutating;
- checkout previews unpriced option values with catalog prices and still
  fails closed without one.

All of them fail on main; the cart add and remove cases also fail with
only #52 and #53 applied.
Finds an open restaurant dish with one optional option group and a paid
value, adds two units with the menu's library group id, and asserts the
basket line keeps the dish's item-level group id and is priced base + paid
value, previews checkout, removes one unit (which rebuilds the remaining
line) and checks the remainder. Cleanup removes only the line it added.

Run locally against the live API: passes with this branch; with main it
fails at "options cart line" (line price without the option).
@mekedron
mekedron merged commit 2011f0a into main Oct 12, 2026
4 checks passed
@mekedron
mekedron deleted the fix/basket-option-prices branch October 12, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants