Magento How to Format Date in an Email Template

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 19:55:08

问题


I need to format the date in an email template. The date gets included in the plain .html email as follows:

Dispatch Date: {{var order.getShippingDate()}}

Is there any way I can format this date? I've tried just using the standard PHP date function to format it to no avail.


回答1:


strtotime any help? It can parse a data back to a unix timestamp, which is what date() expects as an input.

edit after comment:

You can try creating a custom version of app/code/core/Mage/Sales/Model/Order.php under the app/code/local folder (it goes here so magento updates don't overwrite it). It contains a method called getCreatedAtFormated - you could apply the same principle to the shipping data and see if that achieves what you need to do.




回答2:


You can add block directive with custom template

{{block type='core/template' area='frontend' template='email/order/shipment/date.phtml' shipment=$shipment order=$order}}

and there format date by helper.

OR rewrite Filter which uses for parsing of templates and add your directive

 /**
    * Setup callbacks for filters
    *
    */
    public function __construct()
    {
        $this->_modifiers['date'] = array($this, 'modifierDate');
    }

    public function modifierEscape($value, $format='d/m/Y')
    {
        return Mage::helper('core')->formatDate($value,$format);
    }

this is not tested code. just example.




回答3:


Dispatch Date: {{var order.getShippingDate()|formatDateTime:F j, Y}}



来源:https://stackoverflow.com/questions/1105474/magento-how-to-format-date-in-an-email-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!