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

available quantity not checked on PUT item to cart #720

Open
DennisdeBest opened this issue Aug 27, 2021 · 1 comment
Open

available quantity not checked on PUT item to cart #720

DennisdeBest opened this issue Aug 27, 2021 · 1 comment
Labels

Comments

@DennisdeBest
Copy link
Contributor

Hello,

When I try to add a product with a bigger quantity than is available (POST ​/carts​/{token}​/items) I get the following response :

{"code":500,"message":"Not enough stock for product variant: my_product"}

That is great but when I update the quantity of the product, PUT /carts/{token}/items/{identifier} it always passes even if the quantity is much higher than the available stock.

Looking into vendor/sylius/shop-api-plugin/src/Controller/Cart/ChangeItemQuantityAction.php I can see tht it is the validate function fron the DefaultCommandProvider that is called. There are no constraints passed to this function. What could we do to check the inventory when the quantity gets changed ?

@mamazu mamazu added the Bug label Sep 7, 2021
@mamazu
Copy link
Member

mamazu commented Sep 7, 2021

Hello,
I have checked the error out. Neither endpoints have any validation on those properties. This is the reason you are getting a 500 error from this endpoint. (Which is not optimal in the first place.) But the reason the add fails is that it uses the OrderModifier that we created in the ShopApiPlugin (here)

$this->checkCartQuantity($productVariant, $targetQuantity);

This checks that the cart has sufficient stock and asserts otherwise. However, the logic in the ChangeItemQuantityHandler just calls the Sylius core method (that does not check the stock) and is done with it.

$this->orderItemModifier->modify($orderItem, $changeItemQuantity->quantity());

So the easy solution would be to add validation on both cases (one validator and then just add the constraint everywhere). Otherwise we could also try to unify the logic with the cart modification so that it can be used in both instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants