Repository navigation
fix(cart): price option values on every basket mutation; keep shared option groups apart - #54
Merged
Merged
Conversation
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.
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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 addandwolt cart remove(and MCPwolt_cart_add/wolt_cart_remove) fail for any item in that venue withoption ... value ... has no current price. Reproduced live. Newbasketprices.Fillreads 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 topayloadutilso checkout and mutations share one implementation.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.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.base + option, previews checkout, does a partial removal and cleans up.Verification
go build,go test ./...,go test -race ./...,shellcheckare green.golangci-lintreports only the existing SA5011 inroot_and_common_test.go, which this PR does not touch.scripts/live-smoke.shwithWOLT_SMOKE_CART=1: 26 passed, 0 failed. Run against amainbinary, it fails atoptions cart line.