magento2: REST API does not return items for inactive quotes

Summary (*)

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.

Examples (*)

Steps to reproduce:

  1. Find or create an inactive quote: select * from quote where is_active=0 limit 1;
  2. Query the API to fetch the inactive quote: GET https://example.com/rest/V1/carts/2924
  3. See that the results indicate an item but contain no actual items.
{
    "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": {
...
  1. Change the quote to active and repeat the API request. Note that it now contains the item(s):
{
    "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": {
...

Proposed solution

The issue is caused by this check in \Magento\Quote\Model\QuoteRepository\LoadHandler->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.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 1
  • Comments: 20 (13 by maintainers)

Commits related to this issue

Most upvoted comments

This is a dev experience issue, but still relevant, and so easily fixed by someone making the call. We just need a very silly if statement removed.

@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.

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?