问题
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