1

I have create new custom attribute on Sales_order table name "QR_Code". How to insert this field into my new order email template?

Thanks kllee

1
  • You need to first save into order table using sales order place before event then you will get into email Jul 14, 2017 at 16:35

3 Answers 3

0

Please Orverride the following file

/var/www/html/app/code/core/Mage/Sales/Model/order.php

and and your custom variable value here near by 1336 line number.

$mailer->setTemplateParams(array(
     'order'        => $this,
     'billing'      => $this->getBillingAddress(),
     'payment_html' => $paymentBlockHtml,
     'custom_var' => 'custom_value'
));

After this add this variable in your new_order template.

app\locale\en_US\template\email\sales\order_new_guest.html 

and add like this {{var custom_var}}

Happy Coding. :)

3
  • Sorry, I follow up on Magento 2.
    – Kllee
    Apr 13, 2016 at 7:45
  • it's working fine? Nov 17, 2019 at 19:51
  • I tested in M1 not sure about M2
    – Ajay Patel
    Nov 19, 2019 at 4:33
0

To send extra field in order email you need to do the following,

  1. Over ride the email template file in custom extension like this.

    app\code\Vendor\Extension\view\frontend\layout\sales_email_order_items.xml

Add following code in above file.

    <?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">
    <body>
        <referenceBlock name="items">
            <action method="setTemplate">
               <argument name="template" xsi:type="string">Vendor_Extension::email/items.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  1. Create a new template file items.phtml in your template folder as this.

    app\code\Vendor\Extension\view\frontend\templates\email\items.phtml
    
    <?php $_order = $block->getOrder() ?>
    <h3><?= $_order->getYOURFIELD(); ?></h3>    
    
    <?php if ($_order): ?>
        <?php $_items = $_order->getAllItems(); ?>
    <table class="email-items">
        <thead>
            <tr>
                <th class="item-info">
                    <?= /* @escapeNotVerified */  __('Items'); ?>
                </th>
                <th class="item-qty">
                    <?= /* @escapeNotVerified */  __('Qty'); ?>
                </th>
                <th class="item-price">
                    <?= /* @escapeNotVerified */  __('Price'); ?>
                </th>
            </tr>
        </thead>
        <?php foreach ($_items as $_item): ?>
            <?php
                if ($_item->getParentItem()) {
                    continue;
                }
            ?>
            <tbody>
                <?= $block->getItemHtml($_item) ?>
            </tbody>
        <?php endforeach; ?>
        <tfoot class="order-totals">
            <?= $block->getChildHtml('order_totals') ?>
        </tfoot>
    </table>
    <?php if ($this->helper('Magento\GiftMessage\Helper\Message')->isMessagesAllowed('order', $_order, $_order->getStore()) && $_order->getGiftMessageId()): ?>
        <?php $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_order->getGiftMessageId()); ?>
        <?php if ($_giftMessage): ?>
            <br />
            <table class="message-gift">
                <tr>
                    <td>
                        <h3><?= /* @escapeNotVerified */  __('Gift Message for this Order') ?></h3>
                        <strong><?= /* @escapeNotVerified */  __('From:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
                        <br /><strong><?= /* @escapeNotVerified */  __('To:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
                        <br /><strong><?= /* @escapeNotVerified */  __('Message:'); ?></strong>
                        <br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
                    </td>
                </tr>
            </table>
        <?php endif; ?>
    <?php endif; ?>
    
0

You can echo your custom attribute like this way i was call on switch condition, you can use according to your requirements.

<?php echo $_product->getAttributeText('brand'); ?>

OR

<?php
 $brandname = $_product->getAttributeText('brand');
 if (trim($brandname)) {
   echo "" .$this->htmlEscape($brandname);
 }
?>

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.