我在使用日期过滤器时遇到了类似的问题 :)
日期时间以这样的形式实例化的方式
第一步:-
在块形式类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();
}
所以你需要更改->setFormat('%m/%d/%y')行中日历的日期格式
然后在下面的方法中使用它来生成块
$block = $this->getLayout()->createBlock('core/html_date');
$this->setData('_select_block', $block);
在那个块类中Mage_Core_Block_Html_Date
Line 40: $displayFormat = Varien_Date::convertZendToStrFtime($this->getFormat(), true, (bool)$this->getTime());
.......
Line53: ifFormat : "' . $displayFormat . '",
第二步:-
在高级搜索集合类Mage_CatalogSearch_Model_Resource_Advanced_Collection
您需要修改此方法以允许您需要新的语言环境或新的数据时间格式!
Line43: public function addFieldsToFilter($fields) {
.......
.......
.......
.......
Line96: if (!Zend_Date::isDate($conditionValue['from'])) {
.......
Line109:if (!Zend_Date::isDate($conditionValue['to'])) {
.......
}
现在您需要使用新的日期时间格式修改这两行,您更改搜索块以允许验证此方法
例如,我将 Javascript 日历格式修改为 %d-%m-%Y,这将在日历中生成日期,例如 (25-12-2014)
然后我把上面集合类中的方法修改成这样
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
第三步:-
将Mage_CatalogSearch_Model_Resource_Advanced_Collection 类中的日期输入值更改为任何格式或语言环境。
一切正常。
我制作了一个小模块,可以根据您需要的语言环境重写您需要修改的 2 个类
看看https://github.com/Meabed/magento-advanced-search-datetime-field
问候!