1

我将使用 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;
    }
}

编辑:
我发现来自网络服务的响应是好的。但是在使用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' ) ) ) ) ) )
4

1 回答 1

5

我认为这$opt['display'] = 'full';可以完成这项工作你也可以只选择一些特定的属性,例如

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

看看官方文档,你可能会觉得很有趣

于 2013-09-19T19:01:17.293 回答