Advertisement
andhiirawan

Magento: addAttributeToFilter with Multi Conditional

Dec 2nd, 2014
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. //http://magento.stackexchange.com/questions/7908/multi-conditionals-or-and-and-inside-and-in-addattributetofilter
  2.  
  3. //Using AND and OR condition with addAttributeToFilter
  4.  
  5. $collection
  6.     //AND Condition
  7.     ->addAttributeToFilter('special_price', array('gt' => 0))
  8.     ->addAttributeToFilter('special_from_date', array('lteq' =>date('Y-m-d')))
  9.     //OR Condition
  10.     ->addAttributeToFilter(array(
  11.         array(
  12.                 'attribute' => 'special_to_date',
  13.                 'gteq' => date('Y-m-d'),
  14.                 ),
  15.         array(
  16.                 'attribute' => 'special_to_date',
  17.                 'null' => true,
  18.                 )
  19.         ));
  20.  
  21. //$collection->getSelect() with condition
  22.  
  23. $collection->getSelect()
  24.            ->where("((`e`.`special_from_date` < '".date('Y-m-d')."') OR (`e`.`special_to_date` > '".date('Y-m-d')."')) OR ((`e`.`news_from_date` IS NULL) OR (`e`.`news_to_date` IS NULL))");
  25.  
  26. //Add filters using addAttributeToFilter Conditionals
  27. //http://php.quicoto.com/add-filters-using-addattributetofilter-conditionals-magento/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement