Multiple Select
API を介して属性を持つ商品を作成/更新するにはどうすればよいですか? 製品を挿入するための API ファイル (catalog_product.create) のパスは?
ありがとう
Magento ショップで商品を入力するために SOAP API を使用しています。ここに完全なコードがあります
複数選択カスタム属性の場合。
$arrProductTime = explode(',', '136,139');
$result = $client->catalogProductCreate($session, 'simple', $attributeSet->set_id, 'product_sku1234', array(
'categories' => array(36),
'websites' => array(1),
'name' => 'my_pdt1008',
'description' => 'my_pdt1',
'short_description' => 'my_pdt1000',
'weight' => '11',
'status' => '1',
'url_key' => 'product-url-key1',
'url_path' => 'product-url-path1',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title1',
'meta_keyword' => 'Product meta keyword1',
'meta_description' => 'Product meta description1',
'stock_data' => array('qty'=>'100','is_in_stock'=>1,'manage_stock'=>1),
'additional_attributes' => array('multi_data' => array(array('key' => 'product_time', 'value' => $arrProductTime)))
));
SOAP V1
$client = new SoapClient('http://magentohost/api/soap/?wsdl');
// If some stuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
// get attribute set
$attributeSets = $client->call($session, 'product_attribute_set.list');
$attributeSet = current($attributeSets);
$result = $client->call($session, 'catalog_product.create', array('simple', $attributeSet['set_id'], 'product_sku', array(
'categories' => array(2),
'websites' => array(1),
'name' => 'Product name',
'description' => 'Product description',
'short_description' => 'Product short description',
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description'
)));
var_dump ($result);
SOAP V2
$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
// If some stuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
// get attribute set
$attributeSets = $client->catalogProductAttributeSetList($session);
$attributeSet = current($attributeSets);
$result = $client->catalogProductCreate($session, 'simple', $attributeSet->set_id, 'product_sku', array(
'categories' => array(2),
'websites' => array(1),
'name' => 'Product name',
'description' => 'Product description',
'short_description' => 'Product short description',
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description'
));
var_dump ($result);
次のコマンドを使用して、追加の属性のリストを取得できます。
SOAP V1
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$listAttributes = $proxy->call(
$sessionId,
'product.listOfAdditionalAttributes',
array(
'simple',
13
)
);
SOAP V2
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary
$result = $proxy->catalogProductListOfAdditionalAttributes($sessionId, 'simple', '13');
var_dump($result);
そして、応答は次のようになります
array
0 =>
array
'attribute_id' => string '89' (length=2)
'code' => string 'old_id' (length=6)
'type' => string 'text' (length=4)
'required' => string '0' (length=1)
'scope' => string 'global' (length=6)
1 =>
array
'attribute_id' => string '93' (length=2)
'code' => string 'news_from_date' (length=14)
'type' => string 'date' (length=4)
'required' => string '0' (length=1)
'scope' => string 'website' (length=7)
2 =>
array
...
問題の解決に役立つことを願っています。
ソース