2016-04-27 98 views
0

嗨我想要使用prestashop web服务远程更新与产品相关的所有“属性”。我一直试图更新其类别几天失败。我正在使用prestashop_1.6.1.5。 继doc你可以得到一个产品这样的XML如何使用prestashop web服务更新产品类别?

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

var_dump($xml); 

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

然后,如果你做

$resources->reference = "NEW REFERENCE"; 

,你可以修改的参考,例如。

有可能通过

$resources->associations->categories->categories 

,查看其类别您将获得与该产品相关类别ID的数组。但是,如果你这样做:

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

你将不会更新相关的产品8.第三类将保持像0 我也试图assing一个字符串。我试图取消设置整个类别节点,使用它使用的相同格式创建我自己的节点,然后重新进行分类。我已经尝试创建一个SimpleXMlElement,并为每个我想要修改的id添加它与addChild()。但没有任何工作。

有谁知道如何更新类别?

我还有另一个问题,这些类别ID和产品XML中出现的default_category_id有什么区别?如果您看到prestashop DDBB,则default_category_id不会出现在中间表中。我的意思是,如果default_category_id是9,则在开始使用prestashop时的示例产品中,其他ID为2,3,4和7。

在此先感谢

回答

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!非常感谢,你救了我! –