Friday, May 8, 2015

Magento- Get product Collection

Magento-  Get product Collection

The following shows how to filter by a range of values (greater than AND less than)

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name');      
$collection->addAttributeToSelect('orig_price');        
//filter for products whose orig_price is greater than (gt) 100
$collection->addFieldToFilter(array(
        array('attribute'=>'orig_price','gt'=>'100'),
));     
//AND filter for products whose orig_price is greater than (lt) 130
$collection->addFieldToFilter(array(
        array('attribute'=>'orig_price','lt'=>'130'),
));

No comments :

Post a Comment