Skip to main content
Tweeted twitter.com/StackMagento/status/1210757610627944448

Email Magento2 : Order Items Email Template Adjustment - Magento 2

added 3381 characters in body
Source Link
mysti
  • 103
  • 1
  • 6

I tried the below solution but the design is breaking. Here is my updated code :

<?php $_order = $block->getOrder() ?>
<?php if ($_order): ?>
    <?php $_items = $_order->getAllItems(); ?>
    <table class="email-items" cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
        <thead>
            <tr>
                <th class="item-info" align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px">
                    <?= /* @escapeNotVerified */  __('Items') ?>
                </th>
                <th class="item-qty" align="center" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px">
                    <?= /* @escapeNotVerified */  __('Qty') ?>
                </th>
                <th class="item-price" align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px">
                    <?= /* @escapeNotVerified */  __('Price') ?>
                </th>
            </tr>
        </thead>
        <?php foreach ($_items as $_item): ?>
            <?php if (!$_item->getParentItem()) : ?>
                <tbody>
                    <?= $block->getItemHtml($_item) ?>
                </tbody>
            <?php endif; ?>
        <?php endforeach; ?>
    <table align="right" cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
      <tr>
        <th style="padding-right:20px;" align="right"><?= /* @escapeNotVerified */  __('Subtotal') ?></th>
        <td>  <?= /* @escapeNotVerified */  $_order->getSubtotal() ?></td>
      </tr>
      <tr>
        <th style="padding-right:20px;" align="right"><?= /* @escapeNotVerified */  __('Shipping & Handling') ?></th>
        <td><?= /* @escapeNotVerified */  $_order->getShippingAmount() ?></td>
      </tr>
      <tr>
        <th style="padding-right:20px;" align="right"><?= /* @escapeNotVerified */  __('Grant total') ?></th>
        <td><?= /* @escapeNotVerified */  $_order->getGrandTotal() ?></td>
      </tr>
    </table>
    </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; ?>
<?php endif; ?>

enter image description here

I tried the below solution but the design is breaking. Here is my updated code :

<?php $_order = $block->getOrder() ?>
<?php if ($_order): ?>
    <?php $_items = $_order->getAllItems(); ?>
    <table class="email-items" cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
        <thead>
            <tr>
                <th class="item-info" align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px">
                    <?= /* @escapeNotVerified */  __('Items') ?>
                </th>
                <th class="item-qty" align="center" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px">
                    <?= /* @escapeNotVerified */  __('Qty') ?>
                </th>
                <th class="item-price" align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px">
                    <?= /* @escapeNotVerified */  __('Price') ?>
                </th>
            </tr>
        </thead>
        <?php foreach ($_items as $_item): ?>
            <?php if (!$_item->getParentItem()) : ?>
                <tbody>
                    <?= $block->getItemHtml($_item) ?>
                </tbody>
            <?php endif; ?>
        <?php endforeach; ?>
    <table align="right" cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
      <tr>
        <th style="padding-right:20px;" align="right"><?= /* @escapeNotVerified */  __('Subtotal') ?></th>
        <td>  <?= /* @escapeNotVerified */  $_order->getSubtotal() ?></td>
      </tr>
      <tr>
        <th style="padding-right:20px;" align="right"><?= /* @escapeNotVerified */  __('Shipping & Handling') ?></th>
        <td><?= /* @escapeNotVerified */  $_order->getShippingAmount() ?></td>
      </tr>
      <tr>
        <th style="padding-right:20px;" align="right"><?= /* @escapeNotVerified */  __('Grant total') ?></th>
        <td><?= /* @escapeNotVerified */  $_order->getGrandTotal() ?></td>
      </tr>
    </table>
    </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; ?>
<?php endif; ?>

enter image description here

Source Link
mysti
  • 103
  • 1
  • 6

Email Order Items Template Adjustment - Magento 2

I need to add align="right" in th(i.e Subtotal, Shipping & Handling, Grand Total) to align right on tfoot. I have found that its rendering from the below code under Magento_Sales/templates/email/items.phtml file.

<tfoot class="order-totals">
        <?= $block->getChildHtml('order_totals') ?>
</tfoot>

Can anyone let me know how to edit & modify and add align="right" in that?

enter image description here