5

All I found so far is from the User Guide in Step 4 under 2.:

The Quantity is determined by the product variations, so you can leave it blank for now.

The Stock Status of a configurable product is determined by each associated configuration. Because the product was saved without entering a quantity, the Stock Status is now set to “Out of Stock.”

According to this the Quantity is determined by the product variations but how about the Stock Status? If you have variations that are "In Stock" shouldn't be the configurable "In Stock" too?

My background:
Our products are created via rest api like this:

  1. All simples
  2. The configurables with the simple ids that belong to them in configurable_product_links

In our case all configurables are set to "Out of Stock". Even when I reindex the Stock Status is not getting updated. Is this expected behavior?

I've already tried:

  • Clearing cache
  • Reindexing

Here an example json we post to create a configurable:

{
  "product": {
    "typeId": "configurable",
    "sku": "sku",
    "status": 1,
    "attributeSetId": 44,
    "name": "Configurable product name",
    "extensionAttributes": {
      "configurable_product_options": [
        {
          "attribute_id": 861,
          "label": "Some Label",
          "values": [
            {
              "value_index": 15929
            },
            {
              "value_index": 15945
            },
            {
              "value_index": 15967
            }
          ]
        }
      ],
      "configurable_product_links": [
        18449,
        18450,
        18451
      ],
      "category_links": [
        {
          "position": 0,
          "category_id": 899
        }
      ]
    },
    "customAttributes": [
      {
        "attributeCode": "description",
        "value": "Our description"
      }
    ]
  }
}
7
  • 1
    did you check child products? they are on stock? 18449,18450,18451 ??? May 3, 2019 at 11:25
  • for them Manage Stock is disabled could that be the reason?
    – Daniel
    May 3, 2019 at 11:34
  • of course yes, because configurable products don`t show individually, they are depends on child products stocks May 3, 2019 at 11:53
  • makes sense I didn't take that into account
    – Daniel
    May 3, 2019 at 12:04
  • do it, it will help you , I`ll be happy! May 3, 2019 at 12:10

2 Answers 2

1

Try to create the configurable product with manage_stock=false it will works as expected!

4
  • 1
    This works indeed. I just think that this is a little inconsistent from Magento because if the Manage Stock is false it doesn't mean it is Out of Stock especially when the variants have a Quantity >0
    – Daniel
    May 3, 2019 at 13:41
  • Can you describe how you added the parameters manage_stock=false to the payload? I can not find the documentation.
    – Azngeek
    Mar 25, 2020 at 9:18
  • I mean to the API-Payload. However i found it.
    – Azngeek
    Mar 27, 2020 at 10:13
0

1) Pass 2 params in headers:

a) Content-Type:application/json b) Authorization: Bearer {token}

2) Create the simple product ============= Payload ==== POST Method = /rest/default/V1/products

{ "product": { "sku": "tester-rj-sm", "name": "Tester Rj Small", "attribute_set_id": 4, "price": 25, "status": 1, "visibility": 1, "type_id": "simple", "weight": "0.5", "extension_attributes": {
"stock_item": { "qty": "10", "is_in_stock": true } }, "custom_attributes": [ { "attribute_code": "description", "value": "Long description......." }, { "attribute_code": "tax_class_id", "value": "2" }, { "attribute_code": "size", "value": "507" } ] } }

3) Create the configurable product ============= Payload ==== POST Method = /rest/default/V1/products

{ "product": { "sku": "tester-rj1", "name": "Tester Rj", "attribute_set_id": 4, "status": 1, "visibility": 4, "type_id": "configurable", "weight": "0.5", "extension_attributes": { "stock_item": {"itemId":null,"productId":0,"stockId":1,"qty":0,"isInStock":true,"isQtyDecimal":true,"showDefaultNotificationMessage":false, "useConfigMinQty":true,"minQty":1,"useConfigMinSaleQty":1,"minSaleQty":1,"useConfigMaxSaleQty":false,"maxSaleQty":0,"useConfigBackorders":true, "backorders":0,"useConfigNotifyStockQty":true,"notifyStockQty":1,"useConfigQtyIncrements":true,"qtyIncrements":1,"useConfigEnableQtyInc":true,"enableQtyIncrements":true,"useConfigManageStock":true,"manageStock":true, "lowStockDate":null,"isDecimalDivided":true,"stockStatusChangedAuto":0,"extensionAttributes":null} },
"custom_attributes": [ { "attribute_code": "description", "value": "Long description....." }, { "attribute_code": "tax_class_id", "value": "2" } ] } }

4) Define configurable product options ======= Payload ====== POST Method = /rest/default/V1/configurable-products/tester-rj1/options

{ "option": { "attribute_id": "180", "label": "Size", "position": 0, "is_use_default": true, "values": [ { "value_index": 507 } ] } }

5) Link the simple products to the configurable product === Payload ==== POST Method = /rest/default/V1/configurable-products/tester-rj1/child

{ "childSku": "tester-rj-sm" }

Above are the steps to create configurable product using Magento 2.X.X rest API. This way configurable product will be In Stock and will be available for purchase automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.