cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Attribute not selecting by resource model

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Custom Attribute not selecting by resource model

Hi All,

 

I am not able to select / fetch my custom attribute popular_product using resource model

 

$productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('popular_product')
    ->addAttributeToSelect('*')
    ->setStoreId($storeId)
	->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
         ->addAttributeToFilter('category_id', array('in' => $catIds))
          ->addAttributeToFilter('status', array('eq' => 1))
     ->addAttributeToFilter('dis_continue', array('eq' => 0))

Although I can fetch it using following

 

 

 $collection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('sku')
            ->addAttributeToSelect('name')
			->addAttributeToSelect('seller_id')
			->addAttributeToSelect('manufacturer')
                    ->addAttributeToSelect('popular_product')
            ->addAttributeToSelect('attribute_set_id')
            ->addAttributeToSelect('type_id');

 

Please help

 

 

1 REPLY 1

Re: Custom Attribute not selecting by resource model

Hi vikas,

Please check below code:- 

 $storeId = Mage::app()->getStore()->getId();
$collection = Mage::getResourceModel('reports/product_collection') ->addAttributeToSelect('*') ->setStoreId($storeId) ->addStoreFilter($storeId) ->addAttributeToFilter('visibility', $visibility) ->addAttributeToFilter('popular_product', true) ->setOrder('updated_at', 'desc') ->addAttributeToSelect('status') ->setPageSize($productCount); Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection); $collection->addFieldToFilter(array(array('attribute' => 'popular_product', 'eq' => 1))); /* To display product by category id */ if($categoryId=$this->getData('category_id')){ $category = Mage::getModel('catalog/category')->load($categoryId); $collection->addCategoryFilter($category); } foreach ($collection as $_product){ echo $_product->getId(); }