0
私は、郵便はがきクライアントのREST APIを使ってバンドル製品を作成したいのですが、同じAPIを作成するための正しいAPIが見つからないようです。 REST APIを使ってバンドルオプションを追加することはできますが、これらのオプションを追加するにはバンドル製品を用意する必要があります。Magento 2でバンドル製品をREST APIで作成する方法は?
私は、郵便はがきクライアントのREST APIを使ってバンドル製品を作成したいのですが、同じAPIを作成するための正しいAPIが見つからないようです。 REST APIを使ってバンドルオプションを追加することはできますが、これらのオプションを追加するにはバンドル製品を用意する必要があります。Magento 2でバンドル製品をREST APIで作成する方法は?
REST APIによってMagentoの2のバンドル製品を作成するために、我々はいくつかのステップのは、以下を参照してください続きます:1まず私たちが構成(URLの、ユーザ名、パスワード)を書いてみましょう
STEPを
//設定データ
$url="http://www.example.com/index.php/";
$token_url=$url."rest/V1/integration/admin/token";
$product_url=$url. "rest/V1/products";
$username="your admin username";
$password="your admin password";
$product_links = array(
array("sku"=>"cpu1","qty"=>1)
);
STEP 2 -は、その後、私たちは
アクセストークンを取得してみましょう//認証のREST APIのmagento2、アクセストークンを取得し
$ch = curl_init();
$data = array("username" => $username, "password" => $password);
$data_string = json_encode($data);
$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);
$adminToken= json_decode($token);
STEP 3 -ありませんが、私たちは製品データ
//設定可能な製品を作成し
$configProductData = array(
'sku' => 'bundle'. uniqid(),
'name' => 'Bundle' . uniqid(),
'visibility' => 4, /*'catalog',*/
'type_id' => 'bundle',
'price' => 99.95,
'status' => 1,
'attribute_set_id' => 4,
'weight' => 1,
'custom_attributes' => array(
array('attribute_code' => 'category_ids', 'value' => ["42","41","32"]),
array('attribute_code' => 'description', 'value' => 'Description'),
array('attribute_code' => 'short_description', 'value' => 'Short Description'),
array('attribute_code' => 'price_view', 'value' => '0'),
array('attribute_code' => 'price_type', 'value' => '0'),
),
'extension_attributes' => array("bundle_product_options"=>array(
array("title"=>"CPU","type"=>"select","product_links"=>$product_links),
),
)
);
$productData = json_encode(array('product' => $configProductData));
STEPを準備しましょう4-最後に製品データをmagentoに送信して製品を作成します
$setHaders = array('Content-Type:application/json','Authorization:Bearer '.$adminToken);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $product_url);
curl_setopt($ch,CURLOPT_POSTFIELDS, $productData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $setHaders);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);