Extend product_media.list Api to retrieve images always from configurable product

March 18, 2014  |  No Comments  |  by Raj (MagePsycho)  |  Latest, Magento, Web Service

Don’t you think updating same contents like media images and other attributes in all simple products of a configurable products is an overhead? For an easier management, it’s better to update frontend visible data only in configurable product. But this may led missing of data if someone makes an API call for simple product, for example: product_media.list

But we have a solution i.e. to retrieve the data (ex. images) always from the configurable product.
1. Define XML Rewrite


2. Extend Mage_Catalog_Model_Product_Attribute_Media_Api


 * @category   MagePsycho
 * @package    MagePsycho_Apiextender
 * @author     magepsycho@gmail.com
 * @website    http://www.magepsycho.com
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
class MagePsycho_Apiextender_Model_Catalog_Product_Attribute_Media_Api extends Mage_Catalog_Model_Product_Attribute_Media_Api

     * Retrieve product
     * @param int|string $productId
     * @param string|int $store
     * @param  string $identifierType
     * @return Mage_Catalog_Model_Product
    protected function _initProduct($productId, $store = null, $identifierType = null)
        $product = Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), $identifierType);

        //tweak $product if product is simple and part of configurable product
        if ($product && $product->getId()) {
            if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
                $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
                if (isset($parentIds[0])) {
                    $product = Mage::helper('catalog/product')->getProduct($parentIds[0], $this->_getStoreId($store), $identifierType);

        if (!$product->getId()) {

        return $product;

3. And you can test the API (using XML-RPC) as:

$mageFilename = '/path/to/app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);

    $client = new Zend_XmlRpc_Client('http://your-store.com/api/xmlrpc/');
    $session = $client->call('login', array('apiUser', 'apiPass'));

    $images = $client->call('call', array($session, 'product_media.list', array('some-sku')));

    $client->call('endSession', array($session));
} catch (Exception $e) {
    echo 'API Error:: ' . $e->getMessage();

Hello world!

September 17, 2011  |  No Comments  |  by Raj (MagePsycho)  |  Javascript, jQuery, Latest, Linux, Magento, Mysql, PHP, Web Service

Dear All
I am trying to share my knowledge gained so far in web development fields from now onwards via this blog.
I will be sharing stuffs related to PHP/Mysql, Magento & more.
Well nothing more to say, just stay tuned with my blog 🙂

Lastly, your suggestion/feedback is always valuable and will make my blog alive.

This much for now.