My locale is set to France but the advanced search only works in US format. I've made a custom attribute (date type) and add it to the advanced search. And there are 3 problems:
- The datepicker (default) works in US format no matter which locale I set (the Datepicker translation is ok)
- The advanced search only works in US format. If I modify the format (url values) from mm/dd/yy to dd/mm/yy I get no results
- The date validation seems to pick the locale from browser. My default locale is de_DE, so a US date "03/13/14" is not valid and I cannot run the search. If I change the browser locale to en_US everything works. (but with US locale)
Questions: How to force Magento to work with the specified locale settings (fr_FR) in the advanced search and validator and to ignore the browser locale?
I work with the community edition. The problem is the same for version 1.7 and 1.8.
UPDATE:
I found the place where the browser locale is detected:
app/code/core/Mage/CatalogSearch/Model/Resource/Advanced/Collection.php
if (!Zend_Date::isDate($conditionValue['from'])) {
Mage::throwException($invalidDateMessage);
}
app/code/core/Zend/Date.php
$locale = Zend_Locale::findLocale($locale);
If I change it to the following I can force the locale to en_US for example:
if (!Zend_Date::isDate($conditionValue['from'], null, 'en_US')) {
Mage::throwException($invalidDateMessage);
}
The next problematic code where the date format is hardcoded is in:
app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php
->setFormat('%m/%d/%y')
The only thing I cannot find is where the search query is build for the date type. It seems that the date format is harcoded to en_US in multiple places throughout the code or the setted locale is totally ignored which really sucks!
Best Answer
I have had similar issue with Date filter :)
The way date time instantiated in the form like that
Step 1:-
In Block Form class
Mage_CatalogSearch_Block_Advanced_Form
So you need to change the Date format for the calendar in the line
->setFormat('%m/%d/%y')
! Take look about the supported datetime format here http://www.dynarch.com/jscal/#sec34
Then its used in the method below to generate the block
and in that block class
Mage_Core_Block_Html_Date
Step 2:-
In the advanced search collection class
Mage_CatalogSearch_Model_Resource_Advanced_Collection
You need to modify this method to allow the new locale or the new datatime format you needed !
Now You need to modify those 2 lines with the new datetime format you change the search block to allow this method to be validated
For instance i modified the Javascript calendar format to be %d-%m-%Y which will produce Date in the calendar like ( 25-12-2014 )
Then i modified The method in the above collection class to be like this
step 3:-
Change those value of date inputs in the class
Mage_CatalogSearch_Model_Resource_Advanced_Collection
to whatever format or locale.Everything works fine with that.
I have made small module that rewrite the 2 classes you need to modify based on the locale you need
Check it out https://github.com/Meabed/magento-advanced-search-datetime-field
Regards !