3

I try to modify default New Order email template.

Currently, I get order datetime by {{var order.getCreatedAtFormated('short')}}. It results 6/18/2015 12:18 PM.

I want to include timezone following datetime, expected result is 6/18/2015 12:18 PM GMT+7.

I dive into Magento Core code to understand how it works, then I try

{{var order.getCreatedAtFormated('short')}} {{var order.getCreatedAtStoreDate().getTimezone()}}
but it doesn't work.

I know that if it works, getTimezone() may result Asisa/Saigon instead of GMT+7 as expected.

So, how to get order datetime including timezone?

4
  • You need to get the store timezone as GMT+7 Right? – MeenakshiSundaram R Jul 10 '15 at 14:20
  • @MeenakshiSundaramR: no, assume that my store locale is GMT+7, then I need to get the text GMT+7 appending to default datetime (only date and time) – Tran Dinh Khanh Jul 10 '15 at 14:40
  • ok i'll try the code and give the answer – MeenakshiSundaram R Jul 10 '15 at 14:52
  • 1
    check my answer. – MeenakshiSundaram R Jul 11 '15 at 11:21
1

There is no native function to get the GMT time value.

To get the GMT value of order created datatime.

I have rewrite the Mage_Sales_Model_Order and write new function to get the GMT.

(Refer magento model rewrite Tutorial)

public function getGmtValue()
{
    $timeZone = $this->getCreatedAtStoreDate()->getTimezone();
    $currentTimezone = date_default_timezone_get();
    date_default_timezone_set($timeZone);
    //Get GMT
    $value = date('P', strtotime($this->getCreatedAtStoreDate()));
    date_default_timezone_set($currentTimezone);
    return 'GMT'.$value;
}

Now you can get GMT value in email template by following code.

{{var order.getGmtValue()}}

I have refer these two links to get the GMT value

1.how do i get greenwich mean time in php

2.datetime to timestamp in php

1
  • Thank you. I've tested your modification and it worked. Anyway I will leave the question unanswered for a short time to get more attentions for other solutions without modifying the Core codes or requiring extensions. – Tran Dinh Khanh Jul 11 '15 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.