Search code examples
phpapimagentoxml-rpc

How to extend Magento API catalog_product.list to include more product information XML-RPC


Ok, here is my situation.

We are using Magento Store as a online catalog for an iPad App for a Clothing store.

There are multiple categories and a few hundred products.

From all the standard api calls available to us using XML-RPC we have managed to get our nice iPad application working.

It does how ever take way to long to load category listings. The reason for this is the catalog_product.list only returns basic information about a product e.g. id and sku. So we then have to make a new connection for every product on our list to get the other information we need. e.g. Name, Price, Thumb Images . Making a new XML-RPC connection for say 100 products is very time consuming. more than 30 seconds currently. Naturally after the first load we could store this info locally in the ipad but its importan the first load is fast as well.

Sample Return of current method: catelog_product.list

position = "";
    "product_id" = 805;
    set = 4;
    sku = 1901252;
    type = simple;
},
    {
    position = "";
    "product_id" = 807;
    set = 4;
    sku = 2143405;
    type = simple;
},

Question 1)

Is there a way to solve this problem with the existing standard Magento API?

Question 2)

If not then where do I need to be looking to update the catalog_product.list method so it includes the extra info we need.

Note: I'm pretty familiar with PHP but I'm not very familar with the exact structure of Magento and its framework.

Any help would be greatly appreciated.


Solution

  • Go to \app\code\core\Mage\Catalog\Model\Product\Api.php, find items method and look at next piece of code (line 80 in my CE 1.6)

            $result[] = array( // Basic product data
                'product_id' => $product->getId(),
                'sku'        => $product->getSku(),
                'name'       => $product->getName(),
                'set'        => $product->getAttributeSetId(),
                'type'       => $product->getTypeId(),
                'category_ids'       => $product->getCategoryIds()
            );
    

    Add needed attributes here or even write $result[] = $product->getData(); to fetch all standard attributes. If you need some custom attribute there, look at the code

        $collection = Mage::getModel('catalog/product')->getCollection()
            ->addStoreFilter($this->_getStoreId($store))
            ->addAttributeToSelect('name');
    

    above (line 58 in my CE 1.6) and add line ->addAttributeToSelect('<your_attribute_code>').