我在Magento 2上使用"/all/V1/products "休息呼叫來創建產品。 我使用這段代碼來創建所有的設定,如下:
$data = [
"product" => [
"sku" => $sku,
"name" => $name,
"attribute_set_id" => 4,
"price" => $price,
"status" => 1,
"visibility" => 4,
"type_id" => "簡單"。
"weight" => "1"。
"extension_attributes" => [
"category_links" => [
[
"position" => 0,
"category_id" => $cat_id.
]
],
"stock_item" => [
"qty" => $qty。
"is_in_stock" => true.
]
],
"custom_attributes" => [
[
"attribute_code" => "special_price",
"value" => $sale_price.
],
[
"attribute_code" => "special_from_date"。
"value" => "2021-02-07 00:00:00".
],
[
" attribute_code" => "special_to_date",
"value" => "2091-02-07 00:00:00".
],
[
"attribute_code" => "cost"。
"value" => $sale_price.
],
[
"attribute_code" => "description"。
"value" => $desc.
],
[
"attribute_code" => "short_description"。
"value" => $short_desc.
],
[
"attribute_code" => "制造商"。
"value" => $brand.
],
]
]
];
我使用這段代碼來創建并將產品與自定義制造商聯系起來
[
"attribute_code" => "制造商"。
"value" => $brand.
],
但是我得到這個錯誤。在 "custom_attributes "處理程序中發生錯誤。屬性 "制造商 "有無效的值。品牌名稱 "值的型別是無效的。
uj5u.com熱心網友回復:
Magento中的manufacturer屬性是一個選擇屬性。你不能只發送下拉值,而必須發送該值的選項ID。
因此,呼叫終端rest/all/V1/products的有效負載如下:
{}。
"product": {
"sku": "sku12345678" ,
"name": "產品的名稱",
"attribute_set_id": 1,
"price": 9.95,
"status": 1,
"可見性": 4,
"type_id": "simple",
"weight": "100",
"custom_attributes": [
{>
"attribute_code": " manufacturer",
"value": "123"/span>
}
]
}
}
其中123是選項ID。
要獲得帶有制造商屬性的選項ID的選項值,你可以對端點rest/all/V1/products/attributes/manufacturer/options做一個GET請求。
你可以通過使用一個POST請求到端點rest/all/V1/products/attributes/manufacture/options來添加一個選擇選項,其有效載荷如下:
{}。
"option": {
"標簽": "ManufacturerX",
"value": "ManufacturerX",
"sort_order"/span>: 100
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/320571.html
標籤:
上一篇:同樣的查詢,不同的行為

