cancel
Showing results for 
Search instead for 
Did you mean: 

Adding extra fields in catalog product list in SOAP API magento

Adding extra fields in catalog product list in SOAP API magento

I need to add extra fields such as description,weight,pirce,Special pirce How to add these fields in the catalog_product.info

Here is my api.php

public function items($filters = null, $store = null)
{
    $collection = Mage::getModel('catalog/product')->getCollection()
    ->addStoreFilter($this->_getStoreId($store))
    ->addAttributeToSelect('name');

/** @var $apiHelper Mage_Api_Helper_Data */
$apiHelper = Mage::helper('api');
$filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
try {
    foreach ($filters as $field => $value) {
        $collection->addFieldToFilter($field, $value);
    }
} catch (Mage_Core_Exception $e) {
    $this->_fault('filters_invalid', $e->getMessage());
}
$result = array();
foreach ($collection as $product) {
    $result[] = array(
        'product_id' => $product->getId(),
        'sku'        => $product->getSku(),
        'name'       => $product->getName(),
        'set'        => $product->getAttributeSetId(),
        'type'       => $product->getTypeId(),
        'category_ids' => $product->getCategoryIds(),
        'website_ids'  => $product->getWebsiteIds(),
        'description' => $product->getDescription(),
        'weight'    => $product->getWeight(),

    );
}
    return $result;

 }

But the description and weight are not in the result,so what i am missing here

4 REPLIES 4

Re: Adding extra fields in catalog product list in SOAP API magento

Hi Durai how are you?,

 

The easy way to include extra filed to you code and when $product is loaded the Data be there is:

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

 

As weight and description are attributes of the product, that information is not included on the query executed to get all the products ( see Mage_Eav_Model_Entity_Collection_Abstract  - > function load() ).

 

When you iterate a $collection load of the entity is called on the fly.

 

I'm not sure where you are including that api.php file if you are calling again or in placed on a custom module.

 

Best,

ALe.

Re: Adding extra fields in catalog product list in SOAP API magento

Hi Ale,

  I am fine. How about you, thanks for the reply , i have placed my api.php as custom module

 

so what should i have to do to include these attributes

 

here is what i have added

 

 

public function items($filters = null, $store = null)
{
    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addStoreFilter($this->_getStoreId($store))
->addAttributeToSelect(array('name', 'weight', 'price','description','thumb'));

    /** @var $apiHelper Mage_Api_Helper_Data */
    $apiHelper = Mage::helper('api');
    $filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
    try {
        foreach ($filters as $field => $value) {
            $collection->addFieldToFilter($field, $value);
        }
    } catch (Mage_Core_Exception $e) {
        $this->_fault('filters_invalid', $e->getMessage());
    }
    $result = array();
    foreach ($collection as $product) {
        $result[] = array(
            'product_id' => $product->getId(),
            'sku'        => $product->getSku(),
            'name'       => $product->getName(),
            'set'        => $product->getAttributeSetId(),
            'type'       => $product->getTypeId(),
            'category_ids' => $product->getCategoryIds(),
            'website_ids'  => $product->getWebsiteIds(),

         'description'   => $product->getDescription(),
              'weight'      => $product->getWeight(),

                 'pirce'        => Mage::helper('core')->currency($product->getPrice(), true, false), //." ".$currencyCode,
                'thumb'        => (string)Mage::helper('catalog/image')->init($product, 'thumbnail'),

            
        );
    }
   return $result;
       
}

 

but still i am not getting desired output

Re: Adding extra fields in catalog product list in SOAP API magento

Hi Durai sorry for my delay, but I didn't notify about you answer! I tested on my end and works fine, I'm not sure how and where you are using the api.php.

 

I'll check again with all that info you are adding.

 

Best,

ALe.

Re: Adding extra fields in catalog product list in SOAP API magento

Durai,

 

I just testede you code on my end and I got the information from the product.

 

see image As you can see using exactly you code I have the correct information.

 

Best,

ALe.