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": "customer@email.com",
  "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

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 } ?>
  • 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 Mar 15 '18 at 8:09
  • Sorry, you just BCC the trustpilot AFS service in on emails, it gets the email from the recipient @espen – Ricky Odin Matthews Mar 15 '18 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 Mar 15 '18 at 18:57
  • Magento admin -> System -> Transactional emails – Ricky Odin Matthews Mar 16 '18 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 Apr 9 '18 at 19:51

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.