2011-11-11 14 views
1

私はMagento 1.5.1.0を使用しています。 PHPスクリプトを介して製品を追加したいと考えています。 私はカスタム属性を8つのカスタム属性で設定していますが、どのようにPHP経由でカスタム属性に値を追加しますか? product.createまたはproduct.updateとSOAP経由Magentoの製品属性を追加

答えて

2
$host = "127.0.0.1/magento/index.php"; //our online shop url 
    $client = new SoapClient('http://'.$host.'/api/soap/?wsdl'); //soap handle 
    $apiuser= "user"; //webservice user login 
    $apikey = "pw"; //webservice user pass 

    $sess_id= $client->login($apiuser, $apikey); //we do login 
    $attributeSets = $client->call($sess_id, 'product_attribute_set.list'); 
    $set = current($attributeSets); 

    $newProductData = array(
         'name'    => 'name' 
        // websites - Array of website ids to which you want to assign a new product 
        , 'websites'   => array(1) // array(1,2,3,...) 
        , 'short_description' => 'short' 
        , 'description'  => 'description' 
        , 'status'   => 'status' 
        , 'your_attributes' => $value 
        , 'your_attributes2' => $value 
        , 'your_attributes3' => $value 
         and so on 
       ); 

    try { 
    $client->call($sess_id, 'product.create', array('simple', $set['set_id'], 'sku_of_product', $newProductData)); 
    } 
    catch (Exception $e) { //while an error has occured 
    echo "==> Error: ".$e->getMessage(); //we print this 
    } 

のHf & GL:D

よろしくBoti

+0

ありがとうございます。唯一の問題は、自分のサーバーでSoapを有効にしていないことです。別の方法がありますか? –

1

それはすでに

$newProductData = array('name' => 'name', 
         'your_attribute' => $value 
         ,'your_attribute2' => $value 
         ); 

$proxy->call($sessionid, 'product.create', array('simple', $set['set_id'], sku, $newProductData)); 

その後の製品は、カスタム属性(複数可)を使用して作成されますが存在するなら。

よろしくboti

+0

すみません、ありがとうございました。すべてのPHPファイルがどのように表示されるべきかを教えてください。私はmagentoの例で$ proxy = new SoapClient( 'http:// magentohost/api/soap /?wsdl')を見た。 $ sessionId = $ proxy-> login( 'apiUser'、 'apiKey'); $ attributeSets = $ proxy-> call($ sessionId、 'product_attribute_set.list'); $ set =現在の($ attributeSets);よろしくお願いします –

+0

はい、これは私のためにうまくいきます。 V1 soap apiの場合にのみ有効です –

1

Iは、SOAP API V2の以降のバージョンで同じことを行うための私の検索では、この応答を見つけたので、私は最終的に思いついた解決策を追加しています。

V2 SOAP APIの場合、additional_attributesをmulti_dataまたはsingle_dataレイヤーにネストする必要があると思われますか?

アプリ/コード/コア/メイジ/カタログ/モデル/製品を見る/ API/V2.php#256私は、我々があることを

$manufacturer = new stdClass(); 
$manufacturer->key = "manufacturer"; 
$manufacturer->value = "20"; 
$additionalAttrs['single_data'][] = $manufacturer; 

または

$manufacturer = new stdClass(); 
$manufacturer->key = "manufacturer"; 
$manufacturer->value = "20"; 
$additionalAttrs['multi_data'][] = $manufacturer; 

を使用する必要があると思います以下のように使用されます:

$productData = new stdClass(); 
    $additionalAttrs = array(); 

      // manufacturer from one of the two above^

    $productData->name     = $data['name']; 
    $productData->description   = $data['description']; 
    $productData->short_description  = $data['short_description']; 
    $productData->weight     = 0; 
    $productData->status     = 2; // 1 = active 
    $productData->visibility    = 4; //visible in search/catalog 
    $productData->category_ids   = $data['categories']; 
    $productData->price     = $data['price']; 
    $productData->tax_class_id   = 2; // 2=standard 
    $productData->additional_attributes = $additionalAttrs; 

    // Create new product 
    try { 
     $proxy->catalogProductCreate($sessionId, 'virtual', 9, $sku, $productData); // 9 is courses 
    } catch (SoapFault $e) { 
     print $e->getMessage(); //Internal Error. Please see log for details. 
     exit(); 
    } 
関連する問題