phpmagentosoapmagento-1.9magento-soap-api

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


I am trying to fetch complete data of products from magento database using magento soap api using this link: http://devdocs.magento.com/guides/m1x/api/soap/catalog/catalogProduct/catalog_product.list.html

and using the following code:

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

I do get data of all the products in the inventory like this:

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 ) ) )

But I ALSO NEED THE IMAGE OF EACH PRODUCT SO I CAN DISPLAY IT IN MY APP! PLEASE HELP!


Solution

  • Now that you have all the products in your $result array could loop through this and get the images.

    As you can see in the official Magento docs you retrieve the images like so, adjusted to your current script:

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