2

This is my observer file from where I am passing values to email_template.html

 foreach($items as $item) {
        $productIds[]= $item->getProductId();
        $productName[]= $item->getSku(); 
        $productPrice[] = $item->getPrice();
  //      $productQuantity[]= $item->getQty();
    }

$transport = $this->_transportBuilder->setTemplateIdentifier('order_template')
            ->setTemplateOptions($templateOptions)
            ->setTemplateVars($templateVars)
            ->setFrom($from)
            ->addTo($to)
            ->getTransport();
        $transport->sendMessage();
        $this->inlineTranslation->resume();

How can I get the values of $productName and $productPrice in my email template.
I tried but not working

email_template.html

 <table class="email-items">
                <thead>
                    <tr>
                        <th class="item-info">{{trans "Items"}}</th>
                        <th class="item-info">{{trans "Qty"}}</th>
                        <th class="item-info">{{trans "Sku"}}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>{{var $productName.getSku()}}</td>
                        <td>{{var myvar8|raw}}</td>
                        <td>{{var $productPrice.getPrice()}}</td>

                    </tr>
                </tbody>
            </table>
1

In email template html, we can add layout and pass the order object to this layout. For instance, in your layout:

email_template.html

{{layout handle="sales_custom_email_order_items" order=$order area="frontend"}}

Create your own layout:

view/frontend/layout/sales_custom_email_order_items.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Order Items List" design_abstraction="custom">

    <body>
        <block class="Vendor\Module\Block\Order\Email\Items" name="items" template="email/items.phtml" cacheable="false">
             <!--Add more stuff here-->
        </block>

    </body>
</page>

And then, create Vendor\Module\Block\Order\Email\Items and email/items.phtml.

We should take a look some default files:

--vendor/magento/module-sales/view/frontend/email/order_new.html
--vendor/magento/module-sales/view/frontend/layout/sales_email_order_items.xml
--vendor/magento/module-sales/view/frontend/layout/sales_email_order_renderers.xml
--vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php
--vendor/magento/module-sales/Block/Order/Email/Items.php
| improve this answer | |
  • hello @khoa i tried this but phtml file is not calling .. – Ramkishan Suthar Sep 21 '16 at 3:46
  • You should update your question with the block and phtml file. – Khoa TruongDinh Sep 21 '16 at 3:55
  • Error filtering template: Renderer list for block "items" is not defined. I am getting this error in mail. – Ramkishan Suthar Sep 21 '16 at 4:43
  • in core file of magento at endor/magento/module-sales/Block/Order/Email/Items.php there is not any single function ? what should i do ? – Ramkishan Suthar Sep 21 '16 at 4:45
  • i think phtml file is calling now ... – Ramkishan Suthar Sep 21 '16 at 4:45

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.