andhiirawan

Magento: addAttributeToFilter with Multi Conditional

Dec 2nd, 2014
515
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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/
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×