如何在创建产品时添加颜色和大小等自定义选项。有doc: https://github.com/bigcommerce/bigcommerce-api-php
这是我的代码:
public function addProduct($data)
{
$fields = array(
"name" => $data['name'],
"description" => $data['description']
);
return Bigcommerce_api::createProduct($fields);
}
我需要在产品选项中添加一些数据:$data['color'], $data['size']
怎么做?
答案 0 :(得分:2)
您需要创建一个选项集,向该集添加选项,然后将该选项集分配给该产品。
基本上它看起来像这样:
public function addProduct($data)
{
//create option set
$optionSet = Bigcommerce_api::createOptionsets(['name' => 'tshirts']);
//create option
$option = Bigcommerce_api::createOptions(['name' => 'color', 'display_name' => 'color', 'type' => 'S']);
//.. create option values
//assign option to option set
Bigcommerce_api::createOptionsets_Options(['option_id' => $option->id], $optionSet->id);
$fields = array(
"name" => $data['name'],
"description" => $data['description'],
"option_set_id" => $optionSet->id,
);
return Bigcommerce_api::createProduct($fields);
}