【问题标题】:How to get product image from magento database using magento api in Magento 1.9.2.2?如何在 Magento 1.9.2.2 中使用 magento api 从 magento 数据库中获取产品图像?
【发布时间】:2016-05-10 13:47:34
【问题描述】:

我正在尝试使用以下链接使用 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 ) ) )

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

【问题讨论】:

  • 如果我可以返回数组中的所有产品,有用吗?
  • 是的,我需要所有产品的图像,这样我就可以在我的应用程序中显示它们。使用产品的 entity_id 与图像映射的关联数组会很棒!

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


【解决方案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);
?>

【讨论】:

  • 我正在尝试这个,请给我几分钟。
  • 我收到此错误:致命错误:无法使用 stdClass 类型的对象作为数组。在这一行: $productImages[] = $proxy->catalogProductAttributeMediaList($sessionId, $product['product_id']);
  • 你可以试试$product-&gt;productId .. 我编辑了我的示例代码
  • 它实际上是 $product->product_id。代码现在可以工作了,谢谢:)
猜你喜欢
  • 1970-01-01
  • 2016-02-25
  • 2011-01-29
  • 1970-01-01
  • 2011-12-14
  • 1970-01-01
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多