QuoteRepository and API quote requests do not return items or extension attributes for quotes that are not active. More specifically, QuoteRepository and API quote requests return all quote information except items and extension attributes, for quotes that are not active. The data should be returned whether the quote is active or not.
Verified on Magento 2.1.15; all versions 2.1.0 - 2.3.0 affected.
Steps to reproduce:
select * from quote where is_active=0 limit 1;GET https://example.com/rest/V1/carts/2924{
"id": 2924,
"created_at": "2018-10-17 01:13:23",
"updated_at": "2018-12-17 16:34:24",
"is_active": false,
"is_virtual": false,
"items_count": 1,
"items_qty": 1,
"customer": {
...
{
"id": 2924,
"created_at": "2018-10-17 01:13:23",
"updated_at": "2018-12-17 16:34:24",
"is_active": true,
"is_virtual": false,
"items": [
{
"item_id": 4749,
"sku": "ADDONS-USER-LICENSE-SUB",
"qty": 1,
"name": "Additional User License",
"price": 500,
"product_type": "simple",
"quote_id": "2924"
}
],
"items_count": 1,
"items_qty": 1,
"customer": {
...
The issue is caused by this check in MagentoQuoteModelQuoteRepositoryLoadHandler->load():
public function load(CartInterface $quote)
{
if (!$quote->getIsActive()) {
return $quote;
}
I suggest removing this if() statement entirely. The quote in question is already loaded and behaves normally otherwise, whether it is active or not. This active check and return only prevent the quote items and extension attributes from being assigned properly and returned with QuoteRepository and API requests. This results in unexpected behavior for inactive quotes compared to active ones.
Hi @rhoerr. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento-engcom-team give me $VERSION instance
where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.
@rhoerr do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Verify that the issue is reproducible on 2.2-develop branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x
[ ] 6. Add label Issue: Confirmed once verification is complete.
[ ] 7. Make sure that automatic system confirms that report has been added to the backlog.
@ishakhsuvarov do you maybe remember why it was implemented this way? https://github.com/magento/magento2/blame/2.3/app/code/Magento/Quote/Model/QuoteRepository/LoadHandler.php#L42
Hi @rhoerr thank you for you report, this is expected behavior, if you remove this condition it will brake performance.
Uh, could you clarify? In what way would it 'break performance'?
As far as I can tell it would only affect loading of individual inactive quotes, which core does not even do on its own. Am I mistaken?
I have found myself needing to get the items on a cart so I can get a specific CartItem, since the repository does not offer a way to do so.
I need this functionality to work in the admin panel, where carts are not "active"
Hi @ProcessEight. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[x] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[x] 4. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Verify that the issue is reproducible on 2.2-develop branch. Details
- Add the comment @magento give me 2.2-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x
[x] 6. Add label Issue: Confirmed once verification is complete.
[x] 7. Make sure that automatic system confirms that report has been added to the backlog.
@magento give me 2.3-develop instance
Hi @ProcessEight. Thank you for your request. I'm working on Magento 2.3-develop instance for you
Hi @ProcessEight, here is your Magento instance.
Admin access: https://i-19846-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.
:white_check_mark: Confirmed by @ProcessEight
Thank you for verifying the issue. Based on the provided information internal tickets MC-17568 were created
Issue Available: @ProcessEight, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._
@navarr,
I need this functionality to work in the admin panel, where carts are not "active"
Admin panel by itself already works, probably directly via resource models. I still see no reason to change behavior of existing API.
What is the reason for the behavior? When fetching a quote by it's id using the service layer, why is it impossible to use the same service layer to fetch the items on the quote?
I have code that operates in the admin panel and I want to fetch information about a quote item using the item ID. The service layer seems like the appropriate way to do this, but this deficiency prevents it. I now have to work around it by pulling it and manually code in loading any extension attributes or other pieces loaded onto them
Of particular harshness is that I need access to the Custom Options of a Cart Item for a quote in the admin panel while it is being placed.
As far as I can tell, these are only instantiated in the CartItemOptionsProcessor, which is not API and is only used by the QuoteItemRepository, of which the only way to get cart items is if the quote is active.
To work around this will require me to depend on the patch version of Magento.
@orlangur Do you know if a PR modifying this functionality would be accepted? This ticket was originally closed for "works as expected" but its forcing Vertex to depend on non-API methods.
(CartItemOptionsProcessor only applies on CartItemRepository, so when I use get the CartItem model I have to call it myself, and it is not API)