Skip to content

Count a bundle component across every cart line - #1179

Merged
grandnode-dev merged 2 commits into
developfrom
fix/bundle-component-stock-across-cart
Dec 3, 2026
Merged

grandnode-dev merged 2 commits into
developfrom
fix/bundle-component-stock-across-cart

Conversation

@grandnode-dev

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

Copy link
Copy Markdown
Member

Type: bugfix

Issue

The cart checks stock of a bundle's component only for the bundle's own line, and a product's stock only against the other lines of the same product. A line of a bundle managed by its components (ManageStockByBundleProducts) never counts toward the stock of the products it holds.

Example: component X has 6 in stock. The cart holds a bundle with 1 × X at quantity 3 and X itself at quantity 5. The X line checks 5 ≤ 6, the bundle line checks 3 ≤ 6, so the cart shows no warning although the two together need 8. The same happens with two different bundles sharing a component.

Checkout does not oversell: CheckoutClaimService.ClaimStock reserves line by line and each reservation sees the earlier ones, so placing the order fails. The customer only learns it at that point, with no warning in the cart naming the product.

Solution

ShoppingCartInventoryProductValidator adds what the customer's other lines of the same cart type take of the product: its own lines, plus every ManageStockByBundleProducts line holding it, times the component quantity. This applies to:

  • a product managing its own stock (ManageStock), which already summed its own lines and now also counts the bundles holding it;
  • a bundle component managing its own stock, which was checked for this line only.

The cart check now follows the rules the order reserves with:

  • Stores: the other lines are taken with LimitPerStore, like the order does. With SharedCartBetweenStores the lines added in another store count too.
  • Warehouses: a line of another warehouse is counted only when the product keeps stock per warehouse (UseMultipleWarehouses). A product kept in one warehouse is checked against its own stock, the same rule as InventoryManageService.StockWarehouse. Before, the line's warehouse was passed to CheckStock, so a product whose warehouse differs from the store's default warehouse read as out of stock in the cart while the order would accept it.
  • Add from a product list: ActionCartController.AddProductCatalog checks the line's total quantity. The checked item now carries the existing line's id and the product id, so that line is not counted a second time.

Not changed:

  • Components managed by attributes are still checked per line. Summing them needs the combination of each line, including the component attributes held by a bundle line, and comes in a separate PR.
  • InventoryManageService.IsAvailable needs no change: it reads the stored reserved quantity, which already includes the lines reserved before it.

Bundle lines are loaded through the cached IProductService.GetProductById.

Breaking changes

None. No public signatures, settings, resources or migrations change. Behavior: a cart that was accepted before, and failed only at checkout, now shows the stock warning on the line. A product kept in a warehouse other than the store's default one is no longer refused in the cart when it is in stock.

Testing

  1. Unit tests: dotnet test src/Tests/Grand.Business.Checkout.Tests --filter ShoppingCartInventoryProductValidatorTests and dotnet test src/Tests/Grand.Web.Tests --filter ActionCartControllerAddProductCatalogTests. They cover a standalone product with a bundle holding it, two bundles sharing a component, lines within the stock, lines of another warehouse and another store, a product kept in another warehouse, and the add from a product list. The tests of the bugs fail without the fix.
  2. In Admin, give product X "Manage stock" with 6 in stock and "No backorders". Create a bundle product B with stock managed by its bundle products and add X with quantity 1.
  3. In the storefront, add X with quantity 5 to the cart, then add B with quantity 3: the cart refuses B with the out-of-stock message for X. Before the fix, both were accepted and checkout failed.
  4. Lower X in the cart to 3: B with quantity 3 is accepted.
  5. Give X 10 in stock and add it with quantity 5 from a category page, then once more from the same page: the second add is accepted (6 ≤ 10). Before the fix it redirected to the product page.
  6. Full suite: dotnet test GrandNode.slnx. Grand.Business.Checkout.Tests and Grand.Business.Catalog.Tests fail on unrelated tests when the whole solution runs in parallel, and pass when run alone (1209/1209, 1232/1233 with one skipped).

The cart checked a bundle's component only for its own line, and a
product's stock only against its own lines, so a bundle and the
component on its own (or two bundles sharing a component) could each
pass while together they need more than is in stock.

The demand now adds the customer's other lines of the same cart and
store: the product's own lines and every bundle managed by its
components that holds it, times the component quantity. A line of
another warehouse counts only when the product keeps stock per
warehouse. Components managed by attributes stay checked per line.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 16:55

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.

Adding from a product list checked a new item with no product and the
line's total quantity, so the line already in the cart was counted a
second time and a valid add was refused. The checked item now stands
for that line.

The other lines are taken from the stores one order takes them from,
so a cart shared between stores counts them all. A product kept in one
warehouse is checked against its own stock, as the order reserves it,
not against the store's default warehouse named by the line.
@grandnode-dev
grandnode-dev merged commit 1920b11 into develop Dec 3, 2026
9 checks passed
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