Magento Addfieldtofilter: Two Fields, Match as Or, Not And

How to compare two fields in a Magento query?

You can try this, thanks for Zyava!

On my case:

 ->addAttributeToFilter('price', ['gt' => new Zend_Db_Expr('final_price')])

addAttributeToFilter and OR condition in Magento's Collection

yes it is.

$collection->addAttributeToFilter(
array(
array('attribute' => 'someattribute', 'like' => 'value'),
array('attribute' => 'otherattribute', 'like' => 'value'),
array('attribute' => 'anotherattribute', 'like' => 'value'),
)
);

How do I compare 2 different fields in Magento in a collection

Try this:

->addAttributeToFilter('special_price', array ('gteq' => new Zend_Db_Expr('price') ) );

If it doesn't work, you can go for this:

->getSelect()->where("special_price >= price");

Filtering Magento Collections by COND1 AND (COND2 OR COND3)

Here is the solution that I would rather not use, which modifies the SELECT statement via Zend_Db methods.

$orderIds = Mage::getModel('sales/order')->getCollection()
->getSelect();
$adapter = $orderIds->getAdapter();
$quotedFrom = $adapter->quote(
$fromDate->toString('yyyy-MM-dd HH:mm:ss')
);
$quotedTo = $adapter->quote(
$toDate->toString('yyyy-MM-dd HH:mm:ss')
);
$orderIds
->where('status = ?', 'processing')
->where(
vsprintf(
'(created_at >= %s AND created_at <= %s)'
. ' OR (updated_at >= %s AND updated_at <= %s)',
array(
$quotedFrom, $quotedTo,
$quotedFrom, $quotedTo,
)
)
);


Related Topics



Leave a reply



Submit