Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShoppingCartValidator incorrect validation when cart is set to AddProductsToBasketInSinglePositions #797

Closed
Algorithman opened this issue Aug 24, 2023 · 2 comments
Assignees
Milestone

Comments

@Algorithman
Copy link
Contributor

Describe the bug
Checkout is validating quantity wrong for Products which are set to ManageInventoryMethod.ManageStock, StockQuantity=1, BackorderMode.NoBackOrders (with cart set to AddProductsToBasketInSinglePositions).

It gets the quantityToValidate here but then adds the quantity again here which then adds the insufficient stock warning.

Why is the quantity added again to quantityToValidate? Shouldn't quantityToValidate just be set to the quantity of the sum?

To Reproduce
Steps to reproduce the behavior:
Create a product with these settings: ManageInventoryMethod.ManageStock, StockQuantity=1, BackorderMode.NoBackOrders.
Set the cart to single position adding.
Put the product into the shopping cart and try going to checkout.

Desktop (please complete the following information):

  • OS: Win10x64, Linux x64
  • Browser Chrome
@Algorithman
Copy link
Contributor Author

PS: please add also to 5.0.5.x

@Michael-Herzog Michael-Herzog self-assigned this Aug 24, 2023
@Algorithman Algorithman changed the title ShoppingCartValidator wrong validation when cart is set to AddProductsToBasketInSinglePositions ShoppingCartValidator incorrect validation when cart is set to AddProductsToBasketInSinglePositions Aug 24, 2023
@muratcakir muratcakir added this to the 5.1.0 milestone Aug 24, 2023
@Algorithman
Copy link
Contributor Author

I think the main problem here is that you don't check if the cartItem is already in the cart or not.
Extending the query to

quantityToValidate += cartItems
    .Select(x => x.Item)
    .Where(x => x.ProductId == p.Id && x.ParentItemId == null && x.Id != cartItem.Id)
    .Sum(x => x.Quantity);

should do the trick.
It adds the quantity if ValidateProductAsync is actually called to add a product and does not if it's called just to verify the cart.
I don't know if this also has to be done for the combination products (since we don't deal with them), but my guess is yes.

Michael-Herzog added a commit that referenced this issue Sep 13, 2023
…et to AddProductsToBasketInSinglePositions

(cherry picked from commit 0320dbe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants