Magento Api多选属性

时间:2012-08-09 10:13:55

标签: php api magento

如何通过API创建/更新具有Multiple Select属性的产品? 插入产品的API文件的路径是什么(catalog_product.create)?

感谢

2 个答案:

答案 0 :(得分:1)

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
      ...

我希望它可以帮助您解决问题。

消息来源

Create a new product

Get the list of additional attributes.

答案 1 :(得分:1)

我正在使用SOAP API在magento商店中输入产品。这是完整的代码

在多选自定义属性的情况下。

            $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)))
            ));
相关问题