我正在尝试创建一个名为“ Kudos Configurable”的可配置产品,其中的选项供用户从小绿色,大绿色,小橙色和大橙色中选择。
我已经到了通过对/ rest / V1 / products / KudosConfig的PUT请求中使用以下JSON通过API创建可配置产品的阶段。
    {
      "product":{
        "sku":"KudosConfig",
        "name":"Kudos Configurable",
        "price":30.00,
        "status":4,
        "type_id":"configurable",
        "attribute_set_id":4,
        "weight":1,
        "extension_attributes":{
          "stock_item":{
            "qty":10,
            "is_in_stock":true
           }
         }
       }
     }子产品是使用API使用以下JSON创建的,用于以下4个项目中的每个项目,并通过相同的方法设置了尺寸和颜色属性。
    {
      "product":{
        "sku":"KudosConfigGreenSmall ",
        "name":"Kudos Configurable Green Small",
        "price":30.00,
        "status":0,
        "type_id":"virtual",
        "visibility":1,
        "attribute_set_id":4,
        "weight":1,
        "extension_attributes":{
          "stock_item":{
            "qty":10,
            "is_in_stock":true
          }
        },
        "custom_attributes":[
          {
            "attribute_code":"kudos_colour",
            "value":"328"
          },
          {
            "attribute_code":"kudos_size",
            "value":"330"
          }
        ]
      }
    }这工作正常,并且使用正确设置的属性创建了产品。
我以为最后一步是使用configurableProductLinkManagementV1服务来链接子产品,但是使用POST请求到/ rest / V1 / configurable-products / KudosConfig / child并使用以下JSON返回HTTP 400错误请求错误。
    {
      "childSku":"KudosConfigGreenSmall"
    }我认为母产品可能还需要做些其他事情,但是我正在努力找出要解决的问题。在catalogProductRepositoryV1服务中,您可以添加configurable_product_options数组,我尝试过使用此方法,但仅返回了错误的请求错误。
任何人都可以从中找到任何亮点,我们将不胜感激,因为已经花了太长时间。
编辑:
现在尝试将configurable_product_options添加到可配置产品PUT请求中,现在看起来像这样。
    {
      "product":{
        "sku":"KudosConfig",
        "name":"Kudos Configurable",
        "price":30.00,
        "status":4,
        "type_id":"configurable",
        "attribute_set_id":4,
        "weight":1,
        "extension_attributes":{
          "stock_item":{
            "qty":10,
            "is_in_stock":true
          },
          "configurable_product_options":[
            {
              "attribute__id":"kudos_colour",
              "label":"Colour",
              "values":[
                {
                  "value_index":340
                },
                {
                  "value_index":341
                }
              ]
            },
            {
              "attribute__id":"kudos_size",
              "label":"Size",
              "values":[
                {
                  "value_index":343
                },
                {
                  "value_index":342
                }
              ]
            }
          ]
        }
      }
    }当我尝试此操作时,我收到一条消息400:
保存选项时出了点问题。
没有特别的帮助...
快速搜索表明这是问题https://github.com/magento/magento2/issues/5580。
下一步是查看客户是否愿意对configurable.php文件进行破解。
编辑:现在尝试更改configurable.php文件,但似乎没有什么不同,仍然得到相同的错误,因此再次被绊倒。