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

Why don't perform availability check when add item to cart #594

Open
kayue opened this issue Nov 1, 2019 · 18 comments
Open

Why don't perform availability check when add item to cart #594

kayue opened this issue Nov 1, 2019 · 18 comments

Comments

@kayue
Copy link
Contributor

kayue commented Nov 1, 2019

Right now PutVariantBasedConfigutableItemToCartRequest only perform very simple check

May I know is it intentional to leave it availability checking out?

@mamazu
Copy link
Member

mamazu commented Nov 1, 2019

Good question.

@kayue
Copy link
Contributor Author

kayue commented Nov 4, 2019

Actually there is no inventory check throughout the entire API checkout.

@lchrusciel lchrusciel added the Bug label Nov 4, 2019
@mamazu
Copy link
Member

mamazu commented Nov 4, 2019

At least in the checkout complete step there should be some kind of validation. Is it not caught by the Sylius internal logic that tries to reserve the items?

@kayue
Copy link
Contributor Author

kayue commented Nov 5, 2019

Nope that didn't happen.

@kayue
Copy link
Contributor Author

kayue commented Nov 6, 2019

Just noticed this duplicated with #509

@gomcodoctor
Copy link

gomcodoctor commented Dec 29, 2019

Any ETA for this bug fix?

@mamazu
Copy link
Member

mamazu commented Dec 30, 2019

If it is as easy as it seems then it is just adding a validation on some requests. But I want to get @lchrusciel opinion on it as I am not aware of all the ins and outs of Sylius and its stock tracking.

@gomcodoctor
Copy link

I already added validation on change quantity request, it working fine.

issue with adding new product to cart request validation - we can add validation like above but it will need EXTRA database query for searching products, I personally feel its not good idea, we should add validation on command to save DB query.

kindly give your suggestions, i may be wrong

@mamazu
Copy link
Member

mamazu commented Dec 30, 2019

I haven't considered this but I know that there is a validator for availability what about this one?

@mamazu
Copy link
Member

mamazu commented Dec 31, 2019

Sounds good. Maybe we can also reuse the validator.

@gomcodoctor
Copy link

ya we can reuse validator,

i think its better to add validator directly in

https://github.com/Sylius/ShopApiPlugin/blob/master/src/Handler/Cart/PutVariantBasedConfigurableItemToCartHandler.php

this is will save double queries

@mamazu
Copy link
Member

mamazu commented Jan 1, 2020

Well the usual behaviour is to double validate it. Once for the view layer so that the Controller can return a 400 when the product is not in stock and once in the actual logic, which doesn't need to be tied to the shop api using it.

@lchrusciel
Copy link
Member

As @mamazu said. Validation on request to show proper info + on command level an exception.

It should be a part of 1.1

@alexander-schranz
Copy link
Contributor

would #648 be the correct way to fix this issue?

@diimpp
Copy link
Member

diimpp commented May 25, 2020

No, it should be implemented as validator and return validation error instead of 500 critical error.

Case: Last item is bought by someone else within browsing session of current customer. He sees outdated catalog and tries to add out of stock item to cart and sees 500 error instead of 400 error

@alexander-schranz
Copy link
Contributor

@diimpp Ok if I look at ProductInCartChannel it seems there exist both a Validator:

<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\ProductInCartChannel" />

and a check in the Handler:

Assert::true($this->channelChecker->isProductInCartChannel($product, $cart), 'Product is not in same channel as cart');

Think then we should do also both in this cases or?

@diimpp
Copy link
Member

diimpp commented May 25, 2020

@alexander-schranz Yes, that would be correct to put check both in handler and in validator. Sorry, I've misread originally, thought it was in Action itself.

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

Successfully merging a pull request may close this issue.

6 participants