-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Call RemoveItem on cart instead of ItemRepository #40248
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
base: 2.4-develop
Are you sure you want to change the base?
Conversation
|
Hi @indykoning. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
@magento create issue |
|
@magento run all tests |
engcom-Hotel
left a comment
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 @indykoning,
Thank you for the collaboration!
The PR changes seems like a backward incompatible change for the below reasons:
- Plugins may be registered on
CartItemRepositoryInterface::deleteById() - Calling $cart->removeItem() bypasses all plugins on the repository method
- This can break third-party extensions that rely on intercepting cart item deletions
|
Correct, how should we deal with these breaking changes? magento2/app/code/Magento/Quote/Model/Quote.php Line 1585 in b5e99d2
Since the updateItems being called by Magento's controllers & apis execute this updateItems
|
engcom-Hotel
left a comment
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 @indykoning,
Thank you for your contribution!
Please add some automated test in accordance to the DOD.
|
|
||
| if ($quantity <= 0.0) { | ||
| $this->cartItemRepository->deleteById((int)$cart->getId(), $itemId); | ||
| $cart->removeItem($itemId); |
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.
After further analysis, your point is valid. The current GraphQL implementation using CartItemRepositoryInterface::deleteById() is inconsistent with the rest of Magento (REST API, Controllers) which all use Quote::removeItem().
But please add a comment explaining the fix.
Description (*)
This PR replaces the deleteById calls on the CartItemRepository with removeItem on the cart instance.
This makes sure expected observers are triggered and the item is actually updated on the cart object as well, instead of in the database only.
This fixes a case where if you mass remove items using updateCartItems only a single item is removed in the response.
Manual testing scenarios (*)
Contribution checklist (*)
Resolved issues: