Getting product collection
Adding AND query condition
Filtering collection to select only those products whose sku is like ‘ch’ AND status is equal to 1 (i.e. enabled status).
Adding OR query condition
Filtering collection to select only those products whose sku is like ‘ch’ OR status is equal to 1 (i.e. enabled status).
You may check the query statement with the following code
Thanks.
// PRODUCT COLLECTION |
$collection = Mage::getModel('catalog/product')->getCollection(); |
Filtering collection to select only those products whose sku is like ‘ch’ AND status is equal to 1 (i.e. enabled status).
// AND QUERY |
$collection->addAttributeToFilter('sku', array('like' => '%ch%')); |
$collection->addAttributeToFilter('status', array('eq' => '1')); |
Filtering collection to select only those products whose sku is like ‘ch’ OR status is equal to 1 (i.e. enabled status).
// OR QUERY |
$collection->addAttributeToFilter(array( |
array( |
'attribute' => 'sku', |
'like' => '%ch%'), |
array( |
'attribute' => 'status', |
'eq' => '1') |
)); |
$collection->printLogQuery(true); |
No comments:
Post a Comment