如何使用prestashop webservice api在产品中添加tags
?
我需要这样一个函数:
function addTagToProduct((int)$ProductId, (string)$tagname){}
attachment document
的情况相同:我应该将哪些内容传递给webservice进行添加?
答案 0 :(得分:0)
我使用此功能为我的产品添加标签:
public function getTagId($Tag){
//if tag exists
$xml = $this->get(array('url' => $this->url . '/api/tags?filter[name]='.$Tag.'&limit=1'));
$resources = $xml -> children() -> children();
if(!empty($resources)){
$attributes = $resources->tag->attributes();
return $attributes['id'];
}
//if not exists, add it
$xml = $this->get(array('url' => $this->url . '/api/tags?schema=synopsis'));
$resources = $xml -> children() -> children();
unset($resources->id);
$resources->name = $Tag;
$resources->id_lang = $this->getIdLang();
$opt = array(
'resource' => 'tags',
'postXml' => $xml->asXML()
);
$xml = $this->add($opt);
return $xml->tag->id;
}
希望有所帮助。