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

Fix stock policy propagation on product combination #29132

Merged

Conversation

FabienPapet
Copy link
Member

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.

@FabienPapet FabienPapet requested a review from a team as a code owner July 21, 2022 16:01
@prestonBot prestonBot added 8.0.x Branch Bug fix Type: Bug fix labels Jul 21, 2022
@FabienPapet FabienPapet changed the title Fix update stock on product combination Fix stock policy propagation on product combination Jul 21, 2022
@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch from 963841b to 58b5ef7 Compare July 21, 2022 16:20
@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch from 58b5ef7 to 581f279 Compare July 21, 2022 16:23
marsaldev
marsaldev previously approved these changes Jul 21, 2022
@marsaldev
Copy link
Contributor

Seems ok to me 😉

@matks matks added the migration symfony migration project label Jul 22, 2022
@FabienPapet
Copy link
Member Author

FabienPapet commented Jul 22, 2022

Following this ADR, changes should be OK with BC premise, can another one confirm ?

I'll have an look on failing tests

@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch 2 times, most recently from c496c9b to eb2bcba Compare July 25, 2022 12:06
->setParameter('productId', $productId->getValue())
;

if ($shopConstraint !== null && $shopConstraint->getShopId() !== null) {
Copy link
Contributor

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:

Suggested change
if ($shopConstraint !== null && $shopConstraint->getShopId() !== null) {
if ($shopConstraint && $shopConstraint->getShopId()) {

Copy link
Contributor

@zuk3975 zuk3975 Jul 26, 2022

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)

Copy link
Member Author

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.

@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch 2 times, most recently from c1523f9 to b6d9cd2 Compare August 5, 2022 14:09

if ($shopConstraint->getShopId() !== null) {
$queryBuilder
->andWhere($shopColumnName . ' = :shop')
Copy link
Contributor

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 🤔

Copy link
Member Author

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

Copy link
Contributor

@zuk3975 zuk3975 left a 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)

@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch 3 times, most recently from 3792d14 to 993dc92 Compare August 8, 2022 08:09
@FabienPapet
Copy link
Member Author

Code is now corrected and ready for review

@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch from 993dc92 to 976e9fe Compare August 8, 2022 13:40
@FabienPapet
Copy link
Member Author

Fixed

@jolelievre jolelievre dismissed kpodemski’s stale review November 3, 2022 11:29

Tests have been added

@FabienPapet FabienPapet force-pushed the fix-product-combination-stock branch 2 times, most recently from 705f5ba to efabb27 Compare November 3, 2022 11:31
@jolelievre jolelievre removed the Waiting for author Status: action required, waiting for author feedback label Nov 3, 2022
Copy link
Contributor

@florine2623 florine2623 left a 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:
Screenshot 2022-11-09 at 15 33 59
Screenshot 2022-11-09 at 15 34 17

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!

@florine2623 florine2623 added Waiting for author Status: action required, waiting for author feedback and removed Waiting for QA Status: action required, waiting for test feedback labels Nov 9, 2022
@florine2623 florine2623 removed their assignment Nov 9, 2022
Copy link
Contributor

@florine2623 florine2623 left a 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 !

@florine2623 florine2623 added QA ✔️ Status: check done, code approved and removed Waiting for author Status: action required, waiting for author feedback labels Nov 16, 2022
@prestonBot
Copy link
Collaborator

QA approved, well done! Message to the maintainers: do not forget to milestone it before the merge.

@jolelievre
Copy link
Contributor

Thanks @FabienPapet and @florine2623

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.0.x Branch Bug fix Type: Bug fix migration symfony migration project QA ✔️ Status: check done, code approved
Projects
None yet
9 participants