I have added the attributes to select. But it gives all the attributes always. I only need selected atributes to display.

$productModel = Mage::getModel('catalog/product');
//Category id predifined
$categoryId = 132;
$collection = $productModel
             ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
             ->setOrder('entity_id', 'asc')
             ->addAttributeToFilter('category_id', array('in' => array($categoryId))); 

foreach($collection as $product){
    $data[] = $product->getData(); 
  • select Attribute means
    – Amit Bera
    Nov 16 '15 at 12:19
  • @AmitBera I need to get only few attributes. Like entity_id,device_case_id etc. But this gives all the attributes of a product plus these selected attributes
    – Dushan
    Nov 16 '15 at 12:24
  • No use getData(), use getter method for getting aata
    – Amit Bera
    Nov 16 '15 at 12:40

if you are using the flat products, Magento will always read the attributes that are transformed to columns in the flat table.
To these attributes it adds the ones that are not in the flat table but you specifically tell it to load.
If you have the flat catalog disabled it will only select what you tell it to select and the attributes from the catalog_product_entity table (sku, created_at, ...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.