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
Dyld: Library Not Loaded: /Usr/Local/Lib/Libjpeg.8.Dylib - Homebrew PHP
Have Trouble Installing PHPmyadmin on PHP7 Apache/2.4.7 (Ubuntu)
PHP Error: "The Zip Extension and Unzip Command Are Both Missing, Skipping."
Securing a Rest API Accessible from Android
Codeigniter Back Button After Logout
How to Force Formrequest Return JSON in Laravel 5.1
Tracking Email with PHP and Image
How to Remove a Key and Its Value from an Associative Array
Get Code Line and File That's Executing the Current Function in PHP