Repository navigation
fix(cart): store whole-line basket prices and send them as end_amount - #60
Merged
Merged
Conversation
Wolt stores a basket line's price as the whole-line total, count x (unit price + paid option values), and sums line prices without multiplying by count. Its checkout purchase plan takes end_amount as that same total and base_price as one unit without options. Captured from wolt.com: two 3.50 drinks are saved as price 700 and planned as base_price 350, end_amount 700. The CLI stored the unit price and sent count x price as end_amount. A basket built by `cart add --count N` therefore showed a total that ignored the count in the Wolt app, and `checkout` counted lines from the Wolt app twice (a 37.80 basket previewed at 75.60). - cart add (CLI and MCP) saves count x unit price, options included. - BuildBasketUpsertItem rescales a count-based line's price whenever a merge or partial removal changes its count; weighted lines keep the price their weight builders compute. - cart show sums line prices and reports the unit price as price / count. - checkout sends the line price as end_amount and the per-unit price without options as base_price. Weighted lines are unchanged. - A line price that does not divide by its count is rejected with a hint to re-add the item instead of being rounded. Fixes #59
The cart round-trip now adds two units of the fixture item. It checks that the line total is count x unit price, that the basket total Wolt reports equals the CLI subtotal, and that the checkout item subtotal Wolt computes matches it. After removing one unit it checks the line again, and the cleanup removes every unit of the fixture item, which was absent before the run.
cart add saves count x (item price + paid option values) as the line price, the way the Wolt app does. The output contract explains price, line_total and subtotal in cart output.
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.
Summary
A basket built with
wolt cart add --count 2showed three different totals.The Wolt app counted each such line once,
wolt cartshowed its own number,and
wolt checkoutcounted lines added in the Wolt app twice. For example,a 37.80 basket previewed at 75.60.
Wolt stores a basket line's price as the total for the whole line. It reads
the checkout
end_amountas that same total. The CLI stored the price of oneunit and multiplied it by the count again for checkout. Now the CLI stores
and sends prices the same way the Wolt app does. All three totals match.
Baskets built by older CLI versions still hold one-unit prices. Wolt shows
them too low. Rebuild such a basket after upgrading. If a line's price cannot
be split evenly by its count, the CLI refuses it and asks you to add the item
again.
Fixes #59 — #59
What wolt.com sends
Captured from wolt.com network traffic at Sultan Shish Kebab, Espoo:
pricebase_priceend_amountWolt's "Item subtotal" for that plan was 37.80 = 7.00 + 30.80. Option values
keep their per-unit price and count (100, count 1).
This settles the open question in the issue.
end_amountis not a per-unitamount. Wolt only appeared to multiply by count because the CLI sent count x
price while the basket held a unit price. With whole-line prices on both
sides, the totals agree.
Changes
cart add(CLI and MCP) saves count x (unit price + paid option values).BuildBasketUpsertItemrescales a count-based line's price whenever a mergeor a partial removal changes its count. Weighted lines keep the price their
weight builders compute.
cart showsums line prices for the subtotal. It reportspriceas oneunit (line price / count) and
line_totalas the line price.checkoutsends the line price asend_amount. It sends one unit withoutoptions as
base_price. Weighted lines are unchanged.compares Wolt's own basket total with the CLI subtotal, and compares the
checkout item subtotal with both.
cart addtext describe the line priceas the whole-line total.
Testing
an indivisible price, weighted lines,
cart showtotals, the checkout planand MCP add/remove.
go build, the versionedbin/woltbuild and version check,golangci-lint run,go test ./...andgo test -race ./...all pass.mainpreviewed an item subtotal of 75.60;three totals matched at every step: Wolt's basket total, the CLI subtotal
and the checkout item subtotal. The last step was 69.10 for 1 x 15.40,
3 x 3.50 and 3 x 14.40.
WOLT_SMOKE_CART=1 ./scripts/live-smoke.shpassed 29 of 29 steps. The newtwo-unit checks passed. The weighted leg was skipped because no
sell-by-weight item was orderable at that hour.
checkout. The weighted code path is unchanged.