Repository navigation
Count a bundle component across every cart line - #1179
Merged
Merged
Conversation
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.
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.
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.
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.ClaimStockreserves 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
ShoppingCartInventoryProductValidatoradds what the customer's other lines of the same cart type take of the product: its own lines, plus everyManageStockByBundleProductsline holding it, times the component quantity. This applies to:ManageStock), which already summed its own lines and now also counts the bundles holding it;The cart check now follows the rules the order reserves with:
LimitPerStore, like the order does. WithSharedCartBetweenStoresthe lines added in another store count too.UseMultipleWarehouses). A product kept in one warehouse is checked against its own stock, the same rule asInventoryManageService.StockWarehouse. Before, the line's warehouse was passed toCheckStock, 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.ActionCartController.AddProductCatalogchecks 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:
InventoryManageService.IsAvailableneeds 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
dotnet test src/Tests/Grand.Business.Checkout.Tests --filter ShoppingCartInventoryProductValidatorTestsanddotnet 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.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).