Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento getCollection() can we put where condition?

Tags:

magento

i am working on a magento project and i need to get the value according to country wise like select address where country ="Nepal"

can we send the where condition in getCollection() function

$collection = Mage::getModel('relocator/location')->getCollection();

any help will be appreciated

like image 929
jarus Avatar asked Mar 10 '10 08:03

jarus


2 Answers

got the solution ;P

Mage::getModel('relocator/location')
    ->getCollection()
    ->addFilter('country','Nepal');
like image 69
jarus Avatar answered Dec 18 '22 20:12

jarus


You can use diffrent condition like below reference from this.

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

Is Equal To

$collection->addAttributeToFilter('status', array('eq' => 1));

Greater Than

$collection->addAttributeToFilter('price', array('gt' => 3));

Contains – with % wildcards Is NULL

$collection->addAttributeToFilter('sku', array('like' => 'DVD%'));

$collection->addAttributeToFilter('entity_id', array('nin' => array(1,2,12)));

like image 45
Vikram Pote Avatar answered Dec 18 '22 18:12

Vikram Pote