8

Im editing custom transaction email templates within magento2. But some of them are not opening and referring me back to the log files with the following message

Attention
The template did not load. Please review the log for details.

The ones i try to open are for example

  • New Order
  • New Order for guest

for aswell as the general ones as the admin/luma ones.

The error in exception.log are

main.CRITICAL: Zend_Json_Exception: Decoding failed: Syntax error in /home/forge/domain.com/vendor/magento/zendframework1/library/Zend/Json.php:97
Stack trace:
#0 /home/forge/domain.com/app/code/Magento/Email/Model/Template.php(306): Zend_Json::decode('{"var formatted...')
#1 /home/forge/domain.com/app/code/Magento/Email/Model/Template.php(320): Magento\Email\Model\Template->_parseVariablesString('{"var formatted...')
#2 /home/forge/domain.com/app/code/Magento/Email/Controller/Adminhtml/Email/Template/DefaultTemplate.php(52): Magento\Email\Model\Template->getVariablesOptionArray(true)
#3 /home/forge/domain.com/lib/internal/Magento/Framework/App/Action/Action.php(102): Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate->execute()
#4 /home/forge/domain.com/app/code/Magento/Backend/App/AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#5 [internal function]: Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#6 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#7 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Chain/Chain.php(70): Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor->___callParent('dispatch', Array)
#8 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Email\\C...', 'dispatch', Object(Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor), Array, 'adminAuthentica...')
#9 /home/forge/domain.com/app/code/Magento/Backend/App/Action/Plugin/Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#10 [internal function]: Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#11 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#12 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Email\\C...', 'dispatch', Object(Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor), Array, 'adminMassaction...')
#13 /home/forge/domain.com/app/code/Magento/Backend/App/Action/Plugin/MassactionKey.php(33): Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#14 [internal function]: Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Interceptor.php(142): call_user_func_array(Array, Array)
#16 /home/forge/domain.com/var/generation/Magento/Email/Controller/Adminhtml/Email/Template/DefaultTemplate/Interceptor.php(27): Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor->___callPlugins('dispatch', Array, Array)
#17 /home/forge/domain.com/lib/internal/Magento/Framework/App/FrontController.php(55): Magento\Email\Controller\Adminhtml\Email\Template\DefaultTemplate\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#18 [internal function]: Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#19 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#20 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#21 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#22 /home/forge/domain.com/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#23 [internal function]: Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#24 /home/forge/domain.com/lib/internal/Magento/Framework/Interception/Interceptor.php(142): call_user_func_array(Array, Array)
#25 /home/forge/domain.com/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#26 /home/forge/domain.com/lib/internal/Magento/Framework/App/Http.php(115): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#27 /home/forge/domain.com/lib/internal/Magento/Framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#28 /home/forge/domain.com/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#29 {main} [] []

1 Answer 1

20

This is a bug in Magento 2 and here is the solution: https://github.com/magento/magento2/pull/5116/files

This will fixed the invalid json objects in the order email templates.

See this on vendor/magento/module-sales/view/frontend/email/order_new.html file.

<!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var order.getEmailCustomerNote()":"Email Order Note", "var order.increment_id":"Order Id", "layout handle=\"sales_email_order_items\" order=$order area=\"frontend\"":"Order Items Grid", "var payment_html|raw":"Payment Details", "var formattedShippingAddress|raw":"Shipping Address", "var order.getShippingDescription()":"Shipping Description" "var shipping_msg":"Shipping message" } @-->

Take a look at this line:

"var order.getShippingDescription()":"Shipping Description"

It needs comma (,) at the end of this line to make it work. So it goes with the other files or template files.

So it should be like this:

<!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var order.getEmailCustomerNote()":"Email Order Note", "var order.increment_id":"Order Id", "layout handle=\"sales_email_order_items\" order=$order area=\"frontend\"":"Order Items Grid", "var payment_html|raw":"Payment Details", "var formattedShippingAddress|raw":"Shipping Address", "var order.getShippingDescription()":"Shipping Description", "var shipping_msg":"Shipping message" } @-->

3
  • This fixes the invalid json objects in the order email templates.
    – nhinzky
    Commented Aug 4, 2016 at 9:00
  • 1
    I edited my answer.
    – nhinzky
    Commented Aug 4, 2016 at 9:06
  • I was facing the same issue because I enabled the profiler, When I disabled it the issue gone.
    – Arunendra
    Commented Jul 5, 2021 at 12:50

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.