讓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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章