Skip to content

Fix auction bid-to-order link, bid currency, stuck auctions and buy-it-now - #1178

Open
grandnode-dev wants to merge 8 commits into
developfrom
fix/auction-bugs
Open

grandnode-dev wants to merge 8 commits into
developfrom
fix/auction-bugs

Conversation

@grandnode-dev

@grandnode-dev grandnode-dev commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Type: bugfix

Issue

Five bugs in auction products (ProductType.Auction):

  1. The winning bid is never linked to its order. PlaceOrderCommandHandler.UpdateBids looked bids up with GetBidsByProductId(sc.Id), the cart item id instead of the product id, so Bid.OrderId stayed empty for every auction win. Cancelling or deleting that order left the bid untouched, staff could delete the winning bid of a placed order (BidDelete only blocks bids with an order), and My auctions showed no order. When it did run, CancelBidByOrder set the highest bid to 0 although other bids remained, and re-opened an auction whose end date had already passed, so the next task run handed the item to the next-highest bidder without anyone deciding that.
  2. Bids ignore the customer's currency. The product page shows the current bid in the working currency, but the bid input started from primary-currency amounts and AddBid stored the typed amount without conversion. With EUR selected and USD as the primary currency, a bid of 950 EUR was stored as 950 USD.
  3. An auction whose highest bid cannot win never ends. When the customer of the highest bid no longer exists, or the bid cannot be added to their cart (e.g. the product was unpublished), EndAuctionsTask logged and moved on without ending the auction. GetAuctionsToEnd returned it again on every run, forever.
  4. Buy-it-now ignores the bidding. Buy-it-now stayed available on the product page, in listings and in the cart after the highest bid had reached or passed its price, so the item could be bought for less than a customer had already bid.
  5. Concurrent bids can lower the highest bid. Two bids checked against the same product state both passed validation, and the later write won even when it was lower. The whole product was written back from a cached copy, which could also undo changes made since it was read.

Solution

  1. UpdateBids looks up the product's bids and takes the customer's winning bid that has no order yet. CancelBidByOrder deletes every bid of the order (one order can hold several auction items) and publishes EntityDeleted for each, recomputes the highest bid from the remaining bids of other customers and leaves the auction ended with no bidder named; the store owner decides whether to list it again (the existing order-cancelled message already tells them).
  2. AddBid converts the bid from the working currency to the primary store currency before it is validated and saved, and rounds it to 2 decimals after the conversion. The product page converts the start price and highest bid for auctions only. The bid input and the after-bid popup show amounts in the working currency.
  3. EndAuctionsTask ends such an auction without a winner, clears the highest bidder and logs a warning with the reason. It sends the existing AuctionExpired.StoreOwnerNotification (seeded inactive, as before for auctions without bids).
  4. New Product.IsBuyNowOutbid() (auction with a highest bid at or above the price). The product page and listings hide buy-it-now, and ShoppingCartStandardValidator refuses it with ShoppingCart.BuyingDisabled. An auction without bids behaves as before. The other bidders are already told by the existing buy-it-now message (AuctionEnded.CustomerNotificationBin).
  5. NewBid writes the highest bid only forward (a filter on the stored amount), and UpdateHighestBid / UpdateAuctionEnded write their fields instead of the whole product. GetLatestBid reads one sorted row instead of loading every bid.

Breaking changes

  • Behavior: cancelling or deleting the order of a won auction no longer re-opens the auction or hands it to the next bidder.
  • GetAddToCartHandler (Grand.Web) takes ICurrencyService in its constructor. It is resolved by DI; only a class deriving from it would need a change.

No other public signatures change; no settings, resources or migrations.

Testing

  1. Unit tests: dotnet test src/Tests/Grand.Business.Checkout.Tests --filter "PlaceOrderCommandHandlerAuctionTests|AuctionBuyNow", dotnet test src/Tests/Grand.Business.Catalog.Tests --filter AuctionServiceTests, dotnet test src/Tests/Grand.Modules.Tests --filter EndAuctionsTaskTests, dotnet test src/Tests/Grand.Web.Tests --filter ActionCartControllerAddBidTests. Each new test fails without its fix.
  2. With sample data, make two products auctions (Admin → product → type Auction): A with buy-it-now price 600 and start price 450, B with buy-it-now disabled and an end date a few minutes ahead.
  3. As a registered customer switch the currency to EUR (rate 0.95) and bid 700 EUR on A. The bid list in Admin → product → Bids shows 736.84 (USD).
  4. As a second customer, open A: buy-it-now is gone from the product page and from search results (the button reads "Bids"); posting add-to-cart answers "Buying is disabled for this product".
  5. Bid on B, unpublish B after its end date and run the "End of the auctions" task (Admin → Schedule tasks → Run now): B is ended with no highest bidder, and the log shows "the highest bid cannot be added to the cart, the auction ends without a winner".
  6. Bid on another auction, let it end and run the task: the winner finds it in the cart; after checkout the winning bid shows the order. Cancel that order in Admin: the auction stays ended and the bid is gone.
  7. Full suite: dotnet test GrandNode.slnx -m:1 passes (all 23 test projects). Run in parallel, some reservation, report and SCIM tests fail intermittently; they pass on their own and do not touch this code.

support added 6 commits December 3, 2026 12:52
The bid was looked up by the cart item id, so an auction win never got its order id: cancelling or deleting that order left the bid untouched, staff could delete the winning bid, and My auctions showed no order. A cancelled win now leaves the auction ended and recomputes the highest bid from the remaining bids without naming a bidder.
A bid typed in a non-primary working currency was stored as if it were in the primary store currency, and the bid input and the after-bid popup started from primary amounts. The bid is now converted to the primary store currency before it is validated and saved, and both show amounts in the working currency.
When the customer of the highest bid no longer exists, or the bid cannot be added to their cart, the task logged and left the auction open, so it was picked up again on every run and never ended. It now ends without a winner, clears the highest bidder and tells the store owner the auction expired.
Buy-it-now stayed available after the highest bid had reached or passed the buy-it-now price, so the item could be bought for less than a customer had already bid. It is now hidden on the product page and refused by the cart. After a buy-it-now, the other bidders get the auction-lost message.
…price

Catalog and search listings still offered add-to-cart for an auction whose bidding had reached the buy-it-now price; the cart refused it. Listings now show the bid button instead, like the product page.
The buy-it-now message already goes to every other bidder (AuctionEnded.CustomerNotificationBin), so the auction-lost message added for them sent each bidder two mails for one sale. Found in E2E.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

support added 2 commits December 3, 2026 17:13
- CancelBidByOrder removes every bid linked to the order, publishes
  EntityDeleted for each, and leaves the cancelling customer's earlier
  bids out of the recomputed highest bid
- UpdateBids links only a winning bid that has no order yet
- A bid converted to the primary currency is rounded to 2 decimals
- The product page converts the start price and highest bid for
  auctions only
Two bids checked against the same product state both passed validation, and the later write won even when it was lower. The highest bid is now written only forward, with a filter on the stored amount. The highest bid and the auction-ended flag are written as single fields instead of the whole product, which came from the cache and could undo changes made since it was read. The latest bid is read with one sorted query instead of loading every bid.
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