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

时间:2016-05-10 13:47:34

标签: php web-services magento soap magento-1.9

我正在尝试使用magento soap api从magento数据库中获取完整的产品数据: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 ) ) )

但我也需要每种产品的图像,所以我可以在我的应用程序中显示它!请帮助!

1 个答案:

答案 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);
?>