使用Prestashop网络服务获取产品图片


Get product Images with Prestashop webservice

我正在尝试在Prestashop Webservice中获取产品的图像。目前,我已经设法获得了描述,价格,标题等。但是当我尝试获取图像时,它只给了我图像的ID,而不是完整的URL。如果我去 http://your-url.com/...cts/XproductidX 我可以毫无问题地获取图像,但是通过网络服务执行此操作显然有点复杂。

这是我到目前为止的代码:

$opt = array(
        'resource' => 'products',
        'display' => 'full',
        'limit' => 5,
    );
    $xml = $webService->get($opt);
    $resources = $xml->children()->children();
    foreach($resources as $product){
        if($product->id[0] == 286){
            $title = $product->meta_title->language;
            $description = $product->meta_description->language;
            $description_short = $product->description_short;
            $quantity = $product->quantity;
            $price = $product->price;
            $wholesale_price = $product->wholesale_price;
            $images = $product->associations->images;
            print_r($images);
        }
    }

有了底部的print_r,我能够收到以下内容:

    SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [nodeType] => image
            [api] => images
        )
    [image] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [id] => 34
                )
            [1] => SimpleXMLElement Object
                (
                    [id] => 35
                )
            [2] => SimpleXMLElement Object
                (
                    [id] => 36
                )
            [3] => SimpleXMLElement Object
                (
                    [id] => 37
                )
            [4] => SimpleXMLElement Object
                (
                    [id] => 38
                )
            [5] => SimpleXMLElement Object
                (
                    [id] => 39
                )
            [6] => SimpleXMLElement Object
                (
                    [id] => 40
                )
        )
)

这给了我图像的 ID。有没有办法获取完整的网址,或者至少通过资源获取图像网址?也许我这样做的方式是错误的?:-)

问候,西蒙

您可以尝试添加

"显示" => OPT命令上的"满"。

这应该解析 Id 并为您提供完整的子对象。