Quantcast
Channel: Insane in the Main Frame
Viewing all articles
Browse latest Browse all 310

Magento: problem with addFieldToFilter

$
0
0

After updating magento 1.9.0.1 with some patches, an extension from a third party suddenly created problems. When calling the page, magento reported the following error:

  1. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CAST(CONCAT(year, "-", month, "-01") AS DATE)' in 'where clause'

This worked perfectly before and so I searched and found the problem in lib/Varien/Data/Collection/Db.php. In the third party extension there was the following code:

  1. $entry->addFieldToFilter('CAST(CONCAT(year, "-", month, "-01") AS DATE)', array('from' => $fromDate, 'to' => $toDate));

Since the patch addFieldToFilter has changed, and all values are now put in quotes, which made the query look like this:

  1. SELECT * FROM table WHERE `CAST(CONCAT(year, "-", month, "-01") AS DATE)` ...

This doesn’t work, of course. So it’s necessary to make Magento not quote this specific value and what I found was a function named addFilterToMap which I used to achieve what I needed:

  1. $entry->addFilterToMap('CAST(CONCAT(year, "-", month, "-01") AS DATE)', 'CAST(CONCAT(year, "-", month, "-01") AS DATE) '); //mit einem leerzeichen danach
  2. $entry->addFieldToFilter('CAST(CONCAT(year, "-", month, "-01") AS DATE)', array('from' => $fromDate, 'to' => $toDate));

And it works. I’m sure this is not ideal but it helped me temporarily.


Viewing all articles
Browse latest Browse all 310

Trending Articles