Magento addFieldToFilter常用过滤条件

//等于 Equals: eq  
$_products->addAttributeToFilter('status', array('eq' => 1));  
   
//不等于 Not Equals - neq  
$_products->addAttributeToFilter('sku', array('neq' => 'test-product'));  
   
//Like - like  
$_products->addAttributeToFilter('sku', array('like' => 'UX%'));  
   
//Not Like - nlike  
$_products->addAttributeToFilter('sku', array('nlike' => 'err-prod%'));  
   
//In - in  
$_products->addAttributeToFilter('id', array('in' => array(1,4,98)));  
   
//Not In - nin  
$_products->addAttributeToFilter('id', array('nin' => array(1,4,98)));  
   
//NULL - null  
$_products->addAttributeToFilter('description', 'null');  
   
//Not NULL - notnull  
$_products->addAttributeToFilter('description', 'notnull');  
   
//大于 Greater Than - gt  
$_products->addAttributeToFilter('id', array('gt' => 5));  
   
//小于 Less Than - lt  
$_products->addAttributeToFilter('id', array('lt' => 5));  
   
//大于等于 Greater Than or Equals To- gteq  
$_products->addAttributeToFilter('id', array('gteq' => 5));  
   
//小于等于 Less Than or Equals To - lteq  
$_products->addAttributeToFilter('id', array('lteq' => 5));  

实例

$us_local_time = strtotime(Mage::getModel('core/date')->date());        
$banners = Mage::getModel('bannerslider/banner')->getCollection()
            ->addFieldToFilter('bannerslider_id', $id)
            ->addFieldToFilter('status', 0)
            ->addFieldToFilter('start_time', array('lteq' => $us_local_time))
            ->addFieldToFilter('end_time', array('gteq' => $us_local_time))
            ->setOrder('sort', "ASC");
        $banners->getSelect()->columns(array($randomise ? 'Rand() as order' : ''))->limit(5);

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论