magento

Collections

Product Collection

$ProductCollection=Mage::getModel('catalog/product')->getCollection();

Selecting the specific Attribute

$ProductCollection->addAttributeToSelect(array('name', 'product_url', 'small_image'));

Selecting the All Attribute

$ProductCollection->addAttributeToSelect('*');

Add Filter on Collection

$ProductCollection->addFieldToFilter('is_active',1);

Add Product Attribute Filter on Collection

$ProductCollection->addAttributeToFilter('weight', array('gt' => 100));

Set Order

$ProductCollection->setOrder('id','ASC');

Set limit

$ProductCollection->setPageSize(10);

Set Current Page

$ProductCollection->setCurPage(1);

Category Collection of a specific store and specific level

$rootId     = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldToFilter('path', array('like'=> "1/$rootId/%"))
    ->addAttributeToFilter('level', 2)
    ->addAttributeToFilter('is_active', 1);

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow