【发布时间】:2021-10-13 20:16:15
【问题描述】:
我使用“/all/V1/products”休息调用在 Magento 2 上创建产品。 我正在使用此代码创建所有设置,如下所示:
$data = [
"product" => [
"sku" => $sku,
"name" => $name,
"attribute_set_id" => 4,
"price" => $price,
"status" => 1,
"visibility" => 4,
"type_id" => "simple",
"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" => "manufacturer",
"value" => $brand
],
]
]
];
我使用此代码创建产品并将其关联到自定义制造商
[
"attribute_code" => "manufacturer",
"value" => $brand
],
但我收到此错误:“custom_attributes”处理期间发生错误。属性“制造商”具有无效值。 “品牌名称”值的类型无效。
【问题讨论】: