从prestashop webservice获取产品及其属性

时间:2013-09-19 18:25:20

标签: web-services prestashop-1.5

我将使用Prestashop 1.5.4网络服务来获取所有产品的属性,如描述,名称等。我的问题是,每当我调用网络服务时,它只返回产品ID。我怎样才能得到属性?

编辑:

代码:

class ShopApi
{
    public $client;

    public function __construct()
    {
        $this->getClient();
    }

    public function getClient()
    {
        try {
            // creating web service access
            $this->client = new PrestaShopWebservice('http://wikibazaar.ir/', 'A38L095W0RHRXE8PM9CM01CZW7KIU4PX', false);
        } catch (PrestaShopWebserviceException $ex) {
            // Shows a message related to the error
            echo 'error: <br />' . $ex->getMessage();
        }
    }
}

class ProductApi extends ShopApi
{
    public function findAll()
    {
        $products = array();
        /// The key-value array
        $opt['resource'] = 'products';
        $opt['display'] = '[description]';
        $opt['limit'] = 1;
        $xml = $this->client->get($opt);
        $resources = $xml->products->children();
        foreach ($resources as $resource)
            $products[] = $resource->attributes();
        return $products;
    }
}

编辑:
我发现webservice的响应没问题。但在使用simplexml_load_string()函数解析xml时出现问题。任何的想法? 这是$ product var_dump:

SimpleXMLElement#1 ( [products] => SimpleXMLElement#2 ( [product] => SimpleXMLElement#3 ( [description] => SimpleXMLElement#4 ( [language] => SimpleXMLElement#5 ( [@attributes] => array ( 'id' => '1' ) ) ) ) ) )

1 个答案:

答案 0 :(得分:4)

我认为$opt['display'] = 'full';可以胜任这项工作 您也可以只选择某些特定属性,例如

$opt['display'] = '[id,name]';

看看official documentation,你可能会发现它很有趣