1

I am about to add a "Structured Data Snippet" to my Magento packing slip emails, which should include a future date.

The snippet looks like this (example data):

<script type="application/json+trustpilot">
{
  "recipientName": "Name MacNameson",
  "recipientEmail": "[email protected]",
  "referenceId": "1234abcd",
  "preferredSendTime": "2016-02-29T13:37:00"
}
</script>

...and the preferredSendTime should be set to 7 days from now. Time could be 18:00 on them all..

So for instance; if the packing slip is created 2018-03-14 in the morning some time, the value should show "2018-03-21T18:00:00" (which is 18:00 the evening 7 days later)

How can I achieve this? Any help appreciated.

1 Answer 1

1

In your email template (via editor at Magento admin -> System -> Transactional emails), do;

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

Make new file in your template folder, app/design/frontend/[your theme]/default/email/custom/trustpilot.phtml

Here's how I do it, I define different for UK and Worldwide, but you can change as you wish (trustpilot.phtml);

<?php $order = $this->getOrder(); ?>
<?php if ($order) { ?>
<?php $country = $order->getShippingAddress()->getCountryModel()->getName(); ?>
<?php $date = $order->getCreatedAtStoreDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); ?>
<?php
  if ($country == "United Kingdom") {
    $nextDate =  Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime($date." +10 days"));
  } else {
    $nextDate =  Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime($date." +21 days"));
  }

  $nextDate = str_replace(' ', 'T', $nextDate); ?>

<script type="application/json+trustpilot">
{
  "recipientName": "<?php echo $order->getBillingAddress()->getFirstname(); ?>",
  "referenceId": "<?php echo $order->getIncrementId(); ?>",
  "preferredSendTime": "<?php echo $nextDate; ?>",
}
</script>

<?php } ?>
7
  • Thanks a lot, I'll try that. But don't you add customer email address, if not.. how will Trustpilot be able to send to them? Or will they perhaps fetch the email address from the email itself?
    – Espen
    Commented Mar 15, 2018 at 8:09
  • Sorry, you just BCC the trustpilot AFS service in on emails, it gets the email from the recipient @espen Commented Mar 15, 2018 at 9:50
  • Sure, that´s what I was thinking about. Can I ask where in the email template to put the {{block type... code? In between the html-tags, or somewhere else? Thanks. Btw.. I think there is a misspell in the template-folder above, should be a folder "template" after /default/ (just to make the answer 100% correct).
    – Espen
    Commented Mar 15, 2018 at 18:57
  • Magento admin -> System -> Transactional emails Commented Mar 16, 2018 at 12:24
  • 1
    Nevermind, my fault.. seemed like the templates in Magento admin -> System -> Transactional emails didn´t work at all, and that the ones in app/locale/nb_NO/template/email/sales/ was used instead. Added my changes there instead, and all good. Thank you for your help! -Espen
    – Espen
    Commented Apr 9, 2018 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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