如何在mangeo集合中为created_at和updated_at日期添加OR条件?

时间:2014-01-27 06:16:32

标签: magento magento-1.7

我有以下代码

$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)));

我想在 updated_at created_at 中添加OR条件

->addAttributeToFilter('updated_at', array('from'=>date("Y-m-d", time()-86400)));           
->addAttributeToFilter('created_at', array('from'=>date("Y-m-d", time()-86400)));

因此,无论是创建还是更新产品,我的收藏都应加载。

我该怎么做?

2 个答案:

答案 0 :(得分:2)

在EAV集合上为ONE属性添加OR过滤器:属性代码是第一个参数,条件是第二个。

$col->addAttributeToFilter(‘name’, array(array(‘like’ => ‘M%’), array(‘like’ => ‘%O’))); (get items whose name starts with M OR ends with O)

在EAV集合上为DIFFERENT属性添加OR过滤器:只传递一个参数,一个带属性的条件数组。

$col->addAttributeToFilter(array(array(‘attribute’ => ‘weight’, ‘in’ => array(1,3)), array(‘attribute’ => ‘name’, ‘like’ => ‘M%’)));

这将获得权重为1或3或其名称以M开头的所有项目。

答案 1 :(得分:0)

将Or或条件添加到集合

   $arrtibuteToFilter =  array(array(
                        'attribute' => $attributeCode,
                        'eq' =>  $attributeValue,
                         ),
        array('attribute' => $attributeCode,
              'eq' =>  $attributeValue,
               ));

->addAttributeToFilter($arrtibuteToFilter);