Issue
I have following code
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('category_ids')
->addAttributeToSelect('manufacturer')
->addAttributeToSelect('price')
->addAttributeToSelect('special_price')
->addAttributeToSelect('regularprice')
->addAttributeToSelect('tier_price_for_bundle')
->addAttributeToSelect('special_from_date')
->addAttributeToSelect('special_to_date')
->addAttributeToFilter('type_id', array('in' => array('simple')))
->addAttributeToFilter('updated_at', array('from'=>date("Y-m-d", time()-86400)));
->addAttributeToFilter('created_at', array('from'=>date("Y-m-d", time()-86400)));
I want to add OR condition for updated_at and created_at in following
->addAttributeToFilter('updated_at', array('from'=>date("Y-m-d", time()-86400)));
->addAttributeToFilter('created_at', array('from'=>date("Y-m-d", time()-86400)));
So that whether a product is created or updated my collection should load.
How can I do this?
Solution
To add an OR filter for ONE attribute on EAV collections: the attribute code is the first argument and the conditions are the second.
$col->addAttributeToFilter(‘name’, array(array(‘like’ => ‘M%’), array(‘like’ => ‘%O’))); (get items whose name starts with M OR ends with O)
To add an OR filter for DIFFERENT attributes on EAV collections: only pass one argument, an array of conditions with attributes.
$col->addAttributeToFilter(array(array(‘attribute’ => ‘weight’, ‘in’ => array(1,3)), array(‘attribute’ => ‘name’, ‘like’ => ‘M%’)));
This gets all items whose weight is 1 or 3 OR whose name starts with M.
Answered By - Slimshadddyyy Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.