Prestashop webservice添加产品标签和附件文档

时间:2016-03-13 20:50:28

标签: web-services prestashop-1.6

如何使用prestashop webservice api在产品中添加tags? 我需要这样一个函数:

function addTagToProduct((int)$ProductId, (string)$tagname){}

attachment document的情况相同:我应该将哪些内容传递给webservice进行添加?

1 个答案:

答案 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;
}

希望有所帮助。