Skip to content

Rest cart item update throws The requested qty is not available if quantity in cart and quantity to update to exceeds stock #38949

Open
@sanderjongsma

Description

@sanderjongsma

Preconditions and environment

  • 2.4.7-p1
  • Only for configurables
  • Based on default instance with sample data

Steps to reproduce

  1. Create guest cart with rest api:
    Post to https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering/rest/V1/guest-carts/ and use that masked id.

  2. Get the guest cart to determine quote id:
    Get to https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering/rest/V1/guest-carts/{{masked_id}}

  3. Add just 1 configurable to cart:
    Post to: https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering/rest/V1/guest-carts/{{masked_id}}/items with body:

{
  "cartItem": {
    "sku": "MH02",
    "qty": 1,
    "quote_id": "{{quote_id}}",
    "product_option": {
      "extension_attributes": {
        "configurable_item_options": [
          {
            "option_id": "93",
            "option_value": 49
          },
          {
            "option_id": "142",
            "option_value": 166
          }
        ]
      }
    },
    "extension_attributes": {}
  }
}

  1. Update the qty to 100 (default stock for a simple of a configurable product)
    image

Note: Use the item_id of the configurable type (not the simple)

PUT to https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering/rest/V1/guest-carts/{{masked_id}}/items/{{item_id}} with body:

{
  "cartItem": {
    "sku": "MH02",
    "qty": 100,
    "quote_id": "{{quote_id}}",
    "product_option": {
      "extension_attributes": {
        "configurable_item_options": [
          {
            "option_id": "93",
            "option_value": 49
          },
          {
            "option_id": "142",
            "option_value": 166
          }
        ]
      }
    },
    "extension_attributes": {}
  }
}

Now the response of the call is:

{
    "message": "The requested qty is not available"
}

Expected result

When doing step 4 the requested qty of 100 should be in the cart after the post request instead of an exception

Actual result

This exception is thrown in step 4:

{
    "message": "The requested qty is not available"
}

Additional information

while the actual stock is 100, so this should work. The error is thrown from this file: vendor/magento/module-inventory-sales/Model/IsProductSalableForRequestedQtyCondition/IsSalableWithReservationsCondition.php and after debugging it is because in this validator the $requestedQty is 101 instead of 100, so the requested quantity from the api call is added to the current quantity in the cart.

In \Magento\Quote\Model\Quote::updateItem on line 1805 there is a $buyRequest->setResetCount(true); to reset the actual counter, but when the reset_count is red in the request on line 94 here: \Magento\Quote\Model\Quote\Item\Processor::prepare there is another check: $item->getId() == $request->getId() which will be never true because the request does not have the id of the item.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Area: ProductComponent: GraphQLGraphQLIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressReported on 2.4.7-p1Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions