Friday, 3 July 2015

Add image on product detail API magento


Add image on product detail API magento

Go to app/code/core/Mage/Catalog/Model/Product/Api.php and replace the below function

public function info($productId, $store = null, $attributes = null, $identifierType = null)
{
    // make sku flag case-insensitive
    if (!empty($identifierType)) {
        $identifierType = strtolower($identifierType);
    }

    $product = $this->_getProduct($productId, $store, $identifierType);
 
    /* Code by chand */
    $GalleryImages = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();
     if(count($GalleryImages)) {
       foreach($GalleryImages as $simplemediagalleryimage) {
           $image[] = $simplemediagalleryimage->url;
         }
     }
    /* End Code by chand */
 
    $result = array( // Basic product data
        'product_id' => $product->getId(),
        'sku'        => $product->getSku(),
        'set'        => $product->getAttributeSetId(),
        'type'       => $product->getTypeId(),
        'categories' => $product->getCategoryIds(),
        'image' => $image,
        'websites'   => $product->getWebsiteIds()
    );

    foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
        if ($this->_isAllowedAttribute($attribute, $attributes)) {
            $result[$attribute->getAttributeCode()] = $product->getData(
                                                            $attribute->getAttributeCode());
        }
    }

    return $result;
}

No comments: