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
Fix stock policy propagation on product combination #29132
Fix stock policy propagation on product combination #29132
Conversation
FabienPapet
commented
Jul 21, 2022
Questions | Answers |
---|---|
Branch? | 8.0.x |
Description? | Product out of stock policy is not propagated in product attributes |
Type? | bug fix |
Category? | BO |
BC breaks? | no |
Deprecations? | no |
Fixed ticket? | Fixes #28958 |
Related PRs | If theme, autoupgrade or other module change is needed, provide a link to related PRs here. |
963841b
to
58b5ef7
Compare
src/Adapter/Product/Stock/CommandHandler/UpdateProductStockInformationHandler.php
Outdated
Show resolved
Hide resolved
58b5ef7
to
581f279
Compare
Seems ok to me 😉 |
Uh oh, the tests needs update ^^" And I think there is also a BC break here: |
Following this ADR, changes should be OK with BC premise, can another one confirm ? I'll have an look on failing tests |
c496c9b
to
eb2bcba
Compare
->setParameter('productId', $productId->getValue()) | ||
; | ||
|
||
if ($shopConstraint !== null && $shopConstraint->getShopId() !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking strictly against null doesn't add any value, because arguments are already strictly typed, so i IMO its cleaner to read without null
checks:
if ($shopConstraint !== null && $shopConstraint->getShopId() !== null) { | |
if ($shopConstraint && $shopConstraint->getShopId()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also shouldn't we handle shopGroupId?
Lets say if $shop->constraint is ShopGroupId, then we probably need to check where id_shop IN (:shopIds)
(shop ids being the shops in group. You should explore more if thats the case, im just saying it without much exploration)? Or if shop group is not supported, then we should throw exception. Because I think in other productRep methods we load the product by shop constraint, which already handles the error case for shopGroup and then its impossible to pass shop constraint for group. (but in this case you can pass any shop constraint, so the ShopGroupId case isn't handled)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about shopGroupIds, I've aded code to handle them. Considering the 'short if' notation, I prefer keep it that way because I don't like the if($object)
notation and I prefer testing boolean results.
c1523f9
to
b6d9cd2
Compare
src/Adapter/Product/Stock/CommandHandler/UpdateProductStockInformationHandler.php
Show resolved
Hide resolved
|
||
if ($shopConstraint->getShopId() !== null) { | ||
$queryBuilder | ||
->andWhere($shopColumnName . ' = :shop') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a risk for sql injection 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the code as we don't need it yet and it may cause some issues like you mentioned.
Thank you for pointing that out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that I didn't see it earlier (and I know this causes PR to drag longer 😓 ), but it seems there is risk of sql injection in couple places 🤔 (left comments)
3792d14
to
993dc92
Compare
Code is now corrected and ready for review |
993dc92
to
976e9fe
Compare
Fixed |
...haviour/Features/Context/Domain/Product/Combination/UpdateCombinationStockFeatureContext.php
Outdated
Show resolved
Hide resolved
705f5ba
to
efabb27
Compare
efabb27
to
e85338a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @FabienPapet ,
Automated tests were launched and were successful.
Tested the basic case in PPV2, it is fixed ✅
Checkout process is working well.
Screen.Recording.2022-11-09.at.14.25.40.mov
Also checked for the parameters: ✅
- Tested with standard products and combination products
- Disable/enable option
Allow ordering of out-of-stock products
- In Product Page edition, checked with all the options of
When out of stock
Also checked with Product Page V1, it is not correct. ❌
Screen.Recording.2022-11-09.at.15.35.41.mov
I can always add product to cart + proceed to checkout, with these 2 options:
I should not be able to add my product to my cart when I have Deny orders
and Allow ordering of out-of-stock products
.
Could you check?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with @jolelievre ,
This PR is validated for Product Page V2 ✅
Another issue has been raised for the Product Page V1 mentioned in the previous comment : #30312
Thanks all !
QA approved, well done! Message to the maintainers: do not forget to milestone it before the merge. |
Thanks @FabienPapet and @florine2623 |