我有一点问题。我只想在我的订单邮件中显示没有时间的日期。
为此,我必须使用{{var order.getCreatedAtFormated(''short'')}}
afaik。但它仍然在显示时间。当然,我搜索了Magento源代码,我想知道为什么它不起作用。
当我查看app/code/core/Mage/Sales/Model/Order.php
时,我可以找到:
/**
* Get formated order created date in store timezone
*
* @param string $format date format type (short|medium|long|full)
* @return string
*/
public function getCreatedAtFormated($format)
{
return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);
}
进一步研究/app/code/core/Mage/Core/Helper/Data.php
表明:
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false)
{
if (!in_array($format, $this->_allowedFormats, true)) {
return $date;
}
if (!($date instanceof Zend_Date) && $date && !strtotime($date)) {
return '';
}
if (is_null($date)) {
$date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null);
} else if (!$date instanceof Zend_Date) {
$date = Mage::app()->getLocale()->date(strtotime($date), null, null);
}
if ($showTime) {
$format = Mage::app()->getLocale()->getDateTimeFormat($format);
} else {
$format = Mage::app()->getLocale()->getDateFormat($format);
}
return $date->toString($format);
}
那么它不应该已经隐藏了我将短参数传递给该函数的时间吗?
Mage::helper('core')->formatDate(null, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, false);
最后一个参数允许隐藏时间:
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false)
这真的非常烦人Magento,为方法提供包装器但不提供完全访问权限。为什么他们没有写下面这样的方法我不知道......
public function getCreatedAtFormated($format, $showTime = true)
{
return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, $showTime);
}
你必须覆盖/app/code/local/Mage/Sales/Model/Order.php,创建一个新函数
public function getCreatedAtFormatedHideTime($format)
{
return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, false);
}
因此,您可以从邮件模板调用它:
{{var order.getCreatedAtFormatedHideTime('short')}}
输出:
2000/1/1