I want to minimize the number of Api calls for a mobile application which connects to Magento based shop to display products. right now we have to call catalog_product_attribute_media.list
method for each product in order to get image Urls and it really slows down the app.
I found out in this answer that it is possible to extend the result of an Api Call by editing certain scripts. I tried to use the same approach to include images in product list by editing app/code/core/Mage/Catalog/Model/Category/Api.php line 440:
$storeId = $this->_getStoreId($store);
$collection = $category->setStoreId($storeId)->getProductCollection()
->addAttributeToSelect('brand')
->addAttributeToSelect('media_gallery_images');
($storeId == 0)? $collection->addOrder('position', 'asc') : $collection->setOrder('position', 'asc');;
$result = array();
foreach ($collection as $product) {
$result[] = array(
'product_id' => $product->getId(),
'type' => $product->getTypeId(),
'set' => $product->getAttributeSetId(),
'sku' => $product->getSku(),
'position' => $product->getCatIndexPosition(),
'brand' => $product->getData('brand'),
'media' => $product->getMediaGalleryImages()
);
}
return $result;
I also edited html/app/code/core/Mage/Catalog/etc/wsdl.xml to include the new 'media' property line: 255
<complexType name="catalogAssignedProduct">
<all>
<element name="product_id" type="xsd:int"/>
<element name="type" type="xsd:string"/>
<element name="set" type="xsd:int"/>
<element name="sku" type="xsd:string"/>
<element name="position" type="xsd:int"/>
<element name="brand" type="xsd:string"/>
<element name="media" type="typens:catalogProductImageEntityArray"/>
</all>
</complexType>
but when I call the catalog_category.assignedProducts
it always returns null for the 'media' property, I wonder why this doesn't work? is it the xml type or something else?
Go to app/code/core/Mage/Catalog/Model/Product/Api.php and replace the below function
Code: http://chandreshrana.blogspot.in/2015/05/add-image-in-product-list-api-magento.html
Thanks to this answer I figured out how to include images in the results: here's how I modified the assignedProducts method in app/code/core/Mage/Catalog/Model/Category/Api.php and it worked: