I am new to magento and I am customizing some changes to product, catagory and home pages. I have writen the following Code to show all categories on home page
public function getRandomCategory()
{
$categoryCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*');
$categoryCollection->getSelect()->order('RAND()');
return $categoryCollection;
}
How would i restrict the data by using a condition in case of * in ->addAttributeToSelect(‘*’); statement
A cool thing you can do to debug is to call
that will return the exact query that magento is generatingm now the addAttributeToSelect(‘*’) what it does is to generate the ‘Select * From …’ part of the query let’s say that you only need to retrieve the category name
In that case you only need to do ->addAttributeToSelect(‘name’) you_ can add multiple ->addAttributeToSelect(‘attribute’) to retrieve multiple values.
Now if by restrict data you meant to only retrieve the categories WHERE something = tosomething else then you need to use addAttributeToFilter(‘atttribute’, ”)value
Check using_collections_in_magento for more information on the
Hope my answer helps