让Magento显示订单时间

Magento前端,客户订单列表中,只显示下单日期,而没有订单时间,在某些情况下,这有点不妥,客户希望看到下单时间。看了下Magento代码,修改起来很容易。

Magento有个日期时间格式化函数formatDate,位于app/code/core/Mage/Core/Helper/Data.php中。

/**
 * Date and time format codes
 */
const FORMAT_TYPE_FULL  = 'full';
const FORMAT_TYPE_LONG  = 'long';
const FORMAT_TYPE_MEDIUM= 'medium';
const FORMAT_TYPE_SHORT = 'short';

/**
 * Format date using current locale options
 *
 * @param   date|Zend_Date|null $date in GMT timezone
 * @param   string $format
 * @param   bool $showTime
 * @return  string
 */
public function formatDate($date=null, $format='short', $showTime=false)
{
    if (Mage_Core_Model_Locale::FORMAT_TYPE_FULL    !==$format &&
        Mage_Core_Model_Locale::FORMAT_TYPE_LONG    !==$format &&
        Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM  !==$format &&
        Mage_Core_Model_Locale::FORMAT_TYPE_SHORT   !==$format) {
        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);
    }
    elseif (!$date instanceof Zend_Date) {
        $date = Mage::app()->getLocale()->date(strtotime($date), null, null, $showTime);
    }

    if ($showTime) {
        $format = Mage::app()->getLocale()->getDateTimeFormat($format);
    }
    else {
        $format = Mage::app()->getLocale()->getDateFormat($format);
    }

    return $date->toString($format);
}


前端客户订单日期,是由模板文件template/sales/order/recent.phtml来控制的。只需要把:

echo $this->formatDate($_order->getCreatedAtStoreDate())


修改为:

echo $this->formatDate($_order->getCreatedAtStoreDate(), 'medium', true)


当然,你可以尝试下full或者long格式。

如果想在其他位置调用这个方法

Mage::helper('core')->formatDate($time,'medium',true);

转载至:http://www.sqlstudy.com/article/magento-order-time-show.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值