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
public function getDateInput($attribute, $part = 'from')
{
$name = $attribute->getAttributeCode() . '[' . $part . ']';
$value = $this->getAttributeValue($attribute, $part);
return $this->_getDateBlock()
->setName($name)
->setId($attribute->getAttributeCode() . ($part == 'from' ? '' : '_' . $part))
->setTitle($this->getAttributeLabel($attribute))
->setValue($value)
->setImage($this->getSkinUrl('images/calendar.gif'))
->setFormat('%m/%d/%y') //So you need change the Format here !!!!!
->setClass('input-text')
->getHtml();
}
So you need to change the Date format for the calendar in the line ->setFormat('%m/%d/%y')
Then its used in the method below to generate the block
$block = $this->getLayout()->createBlock('core/html_date');
$this->setData('_select_block', $block);
and in that block class Mage_Core_Block_Html_Date
Line 40: $displayFormat = Varien_Date::convertZendToStrFtime($this->getFormat(), true, (bool)$this->getTime());
.......
Line53: ifFormat : "' . $displayFormat . '",
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 !
Line43: public function addFieldsToFilter($fields) {
.......
.......
.......
.......
Line96: if (!Zend_Date::isDate($conditionValue['from'])) {
.......
Line109:if (!Zend_Date::isDate($conditionValue['to'])) {
.......
}
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
if (!Zend_Date::isDate($conditionValue['from'], 'd-m-Y' )) { // I added the format for the validation
.......
.......
if (!Zend_Date::isDate($conditionValue['to'], 'd-m-Y' )) { // same as above one
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 !
The problem comes from a core bug.
See js/varien/js.js
around line 450:
...
} else if (!day || !month || !year) {
error = 'Please enter a valid full date.';
} else {
...
See the problem? It's the period .
, which does not appear in the CSV, so the translation is missed every time. The easiest solution is the edit this file directly, removing the period so that translation works again... but of course, modifying core is not best practice.
Long Solution
If you have a generic local
code pool module on your system, add or edit its jstranslator.xml
file, and add this:
<?xml version="1.0"?>
<jstranslator>
<!-- js.js -->
<validate-date-full-date translate="message" module="rootd">
<message>Please enter a valid full date.</message>
</validate-date-full-date>
<!-- end js.js -->
</jstranslator>
Here we should effectively overwrite the entry for this message that was originally defined in app/code/core/Mage/Core/etc/jstranslator.xml
, and include the period which core code expects according to js/varien/js.js
. Then, you can add an entry to your CSV:
"Please enter a valid date.","Your translation here"
Best Answer
Found the answer to my own question: