2016-04-27 14 views
0

こんにちは私は、プリスタショップWebサービスを使って製品に関連するすべての "属性"をリモートで更新したいと考えています。私はそのカテゴリーを数日失敗して更新しようとしていました。私はprestashop_1.6.1.5を使用しています。続き docあなたはprestashop Webサービスを使用して製品カテゴリを更新するにはどうすればよいですか?

$resources->reference = "NEW REFERENCE"; 

を行う場合は、次にこの

$xml = $this->webService->get(array('url' => 'http://prestashop.localhost/api/products/2')); 

var_dump($xml); 

$resources = $xml->children()->children(); 

のような製品のXMLを取得することができますし、例えば、参照を変更することができます。

あなたが製品に関連するカテゴリIDの配列を取得します

$resources->associations->categories->categories 

によって、そのカテゴリを表示することが可能です。しかし、あなたがしなければ:

$resources->associations->categories->categories[2] = 8 

あなたは、私もそれを文字列をASSINGしようとしてい 0のようにそれは残る8に、製品に関連する第3のカテゴリは更新されません。私はカテゴリ全体のノードを設定解除しようとしましたが、使用するのと同じフォーマットの自分のノードを作成してから、再度それを取ります。私もSimpleXMlElementを作成して、変更したい各IDに対してaddChild()を追加してみました。しかし何も働かなかった。

カテゴリを更新する方法を知っている人はいますか?

また、別の質問があります。これらのカテゴリIDと、product xmlに表示されるdefault_category_idの違いは何ですか? Prestashop DDBBが表示されている場合、default_category_idは中間テーブルに表示されません。つまり、default_category_idが9の場合、prestashopの使用を開始したときのサンプル製品の2,3,4,7のIDが残ります。

おかげで、事前に

答えて

3

カテゴリーは次のように更新することができます。

$id_product = 102; 
$new_product_categories = array(29,30,31); // List of categories to be linked to product 

$xml = $this->webservice->get(array('resource' => 'products', 'id' => $id_product)); 

$product = $xml->children()->children(); 

// Unset fields that may not be updated 
unset($product->manufacturer_name); 
unset($product->quantity); 

// Remove current categories 
unset($product->associations->categories); 

// Create new categories 
$categories = $product->associations->addChild('categories'); 

foreach ($new_product_categories as $id_category) { 
    $category = $categories->addChild('category'); 
    $category->addChild('id', $id_category); 
} 

$xml_response = $this->webservice->edit(array('resource' => 'products', 'id' => $id_product, 'putXml' => $xml->asXML())); 
+0

それworsを!ありがとう、あなたは私を救った! –

関連する問題