题
我正在尝试在产品特价上设定时间/从日期设定(即特价价格) 3/20/2013 11am EST
至 4/20/2013 10:59am EST
),但是我没有时间出现或保存。
当我在管理员中输入时间时(例如, 03/20/2013 11:00:00
),它总是显示 00:00:00
在数据库中。我真的不需要更新管理员即可在日历小部件中显示时间;相反,如果我放了一段时间,我只需要保存即可。
解决方案
我认为这是一个严重的Magento错误。special_price_from
有一个后端模型 Mage_Catalog_Model_Product_Attribute_Backend_Startdate
(扩展 Mage_Eav_Model_Entity_Attribute_Backend_Datetime
) 和 special_price_to
具有后端模型 Mage_Eav_Model_Entity_Attribute_Backend_Datetime
.
现在,每次保存以下属性之一,此方法称为 Mage_Eav_Model_Entity_Attribute_Backend_Datetime::beforeSave($object)
。而且由于日历未以国际格式发送日期 Mage_Eav_Model_Entity_Attribute_Backend_Datetime::formatDate($date)
:
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
这会剥离时间部分。围绕的工作将是将此代码更改为
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT. ' HH:mm:ss'),
null, false
);
(在本地文件夹中复制文件。没有其他方法可以覆盖此类,因为还有其他类扩展程序)这也可以节省数据库中的时间,但是还有其他问题。即使在编辑产品时正确保存在数据库中,日期仍然没有时间出现,并且在其他任何节省时间上再次消失了。
为此,您需要修改DateTime属性的渲染器。
这是我卡住的地方。也许您对如何做有任何想法。如果我找到一个,我将编辑答案并描述它。
总而言之,做您想做的事情并不是直接的,这是一个严重的问题,应该提出给Magento。
编辑
好吧,我找到了 这个链接. 。我认为这涉及核心变化,我不建议这样做。但是您可以将修改所需的文件复制到 local
文件夹。
其他提示
哇,在这个问题上损失了近一个星期!但是,这篇文章指的是解决方案,也就是说,在发现您可以简单地进入“ eav_attribute”表并将“ frontend_input”值从“ date”更改为“ dateTime”,然后将后端的日历小部件更改为“日期”。显示小时和分钟(以及输入字段以接受值)。
但是后来Magento并没有节省一天中的时间,所以...
我在我的本地文件夹(app/code/local/mage/eav/model/entity/attend/backend)中复制了文件app/code/cod/cod/cod/cod/cod/eav/mode/entity/entity/entity/atterity/atterity/atterity/backend/backend/dateTime.php)和修改如下:
在第44行附近替换:
try {
$value = $this->formatDate($object->getData($attributeName), $attributeFrontendInput);
这个:
try {
$attributeFrontendInput = $this->getAttribute()->getFrontendInput();
$value = $this->formatDate($object->getData($attributeName), $attributeFrontendInput);
(在这里,我们获得属性frontend_input模型,即“日期”或“ dateTime”或其他任何内容,然后将其传递给格式化函数)
然后以稍后的格式函数在代码中以接受新的第二个参数添加到函数标题中的参数列表the varible $ feinput中的参数列表
public function formatDate($date, $feInput)
然后在第87行附近代替:
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
这个:
if ($feInput == 'datetime') {
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
} else {
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
}
在这里,我们测试$ FEINPUT变量,并在Magento Core Codebase中使用GetDateTimeFormat函数,如果输入模型等于“ DateTime”。
我希望有人可以为此节省几个工作日。感谢Stack Exchange上的所有男孩和女孩!
编辑:
这仅仅是为了能够从Magento Backend中正确输入和存储DateTime值。正确检查了DateTime值在前端处理的各个点上正确检查和处理的是另一个故事...
除了他的朋友马里乌斯(Marius)发布以返回小时内HTML价值以进行以下更改还必须:
更改此:
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
这就是为什么:
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->_escape($this->getValue($outputFormat)), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
也就是说 $outputFormat
这 getValue
功能。
这效果很好。希望这可以帮助。
只是花了5个小时才能与此合作(Marius答案的结合)
文件: lib varien data form 元素元素 data.php
仅对于我的语言环境,将其更改为您自己添加功能:
public function getRawMysqlDateFormat ($value) {
if (empty($this->_value)) {
return null;
}
$new_date = explode(" ", $value);
//2017年4月1日 下午4:16:16
$str_to_replace1 = array("年","月");
$str_to_replace2 = "日";
$new_date_part1 = str_replace($str_to_replace1, "-", $new_date[0]);
$new_date_part1 = str_replace($str_to_replace2, "", $new_date_part1);
$new_date_part2 = explode(":", $new_date[1]);
$hour = "";
$min = $new_date_part2[1];
$sec = $new_date_part2[2];
if (stripos($new_date_part2[0], "下午") !== false) {
$temp = str_replace("下午", "", $new_date_part2[0]);
$hour = $temp+12;
} else {
$temp = str_replace("上午", "", $new_date_part2[0]);
$hour = $new_date_part2[0];
}
return $new_date_part1.' '.$hour.':'.$min.':'.$sec;
}
改变:
public function getElementHtml()
{
$this->addClass('input-text');
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->getRawMysqlDateFormat($this->_value), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
$outputFormat = $this->getFormat();
if (empty($outputFormat)) {
throw new Exception('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().');
}
$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime());
$test = $this->getRawMysqlDateFormat($this->_value);
$html .= sprintf('
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField: "%s",
ifFormat: "%s",
showsTime: "true",
button: "%s_trig",
align: "Bl",
singleClick : true
});
//]]>
</script>',
$this->getHtmlId(), "%Y-%m-%d %H:%M:%S",
$this->getTime() ? 'true' : 'false', $this->getHtmlId()
);
$html .= $this->getAfterElementHtml();
return $html;
}