我正在尝试在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。有没有办法获得完整的网址,或者至少通过资源获取图片网址? 也许我这样做的方式不对? : - )
问候,西蒙
答案 0 :(得分:0)
您可以尝试添加
'显示' => '全'在你的选择命令上。
这应解决ID并为您提供完整的子对象。