如何在 Magento 1.9.2.2 中使用 magento api 从 magento 数据库中获取产品图片?

How to get product image from magento database using magento api in Magento 1.9.2.2?

我正在尝试使用 magento soap api 从 magento 数据库中获取完整的产品数据,使用这个 link: http://devdocs.magento.com/guides/m1x/api/soap/catalog/catalogProduct/catalog_product.list.html

并使用以下代码:

<?php
$proxy = new SoapClient('http://xxxxxxx.com/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('test_role', 'password'); // TODO : change login and pwd if necessary

$result = $proxy->catalogProductList($sessionId);
print_r($result);
?>

我是这样获取库存中所有产品的数据的:

Array ( [0] => stdClass Object ( [product_id] => 24 [sku] => 123445 [name] => Burger [set] => 4 [type] => simple [category_ids] => Array ( [0] => 59 ) [website_ids] => Array ( [0] => 1 ) ) [1] => stdClass Object ( [product_id] => 25 [sku] => MG1456 [name] => Massage [set] => 4 [type] => simple [category_ids] => Array ( [0] => 63 ) [website_ids] => Array ( [0] => 1 ) ) [2] => stdClass Object ( [product_id] => 26 [sku] => 345666 [name] => Chicken Chilly [set] => 4 [type] => simple [category_ids] => Array ( [0] => 59 ) [website_ids] => Array ( [0] => 1 ) ) [3] => stdClass Object ( [product_id] => 27 [sku] => 23424 [name] => Chicken Biryani [set] => 4 [type] => simple [category_ids] => Array ( [0] => 59 ) [website_ids] => Array ( [0] => 1 ) ) [4] => stdClass Object ( [product_id] => 28 [sku] => 45567 [name] => Panner Chilly [set] => 4 [type] => simple [category_ids] => Array ( [0] => 59 ) [website_ids] => Array ( [0] => 1 ) ) [5] => stdClass Object ( [product_id] => 31 [sku] => S5GH488 [name] => Pizza [set] => 4 [type] => simple [category_ids] => Array ( [0] => 59 ) [website_ids] => Array ( [0] => 1 ) ) )

但我还需要每个产品的图像,以便在我的应用程序中显示它!请帮忙!

既然您的 $result 数组中包含了所有产品,就可以遍历它并获取图像。

正如您在 official Magento docs 中看到的那样,您可以像这样检索图像,并根据您当前的脚本进行调整:

<?php
$proxy = new SoapClient('http://xxxxxxx.com/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('test_role', 'password'); // TODO : change login and pwd if necessary

$result = $proxy->catalogProductList($sessionId);
$productImages = array();

// Getting all the product images
foreach($result as $product) {
    $productImages[] = $proxy->catalogProductAttributeMediaList($sessionId, $product->productId);
}

print_r($result);

// Show the product images array
print_r($productImages);
?>