5

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

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

3 Answers 3

4

Following steps will be useful

step 1: override the items.phtml code

Path:app/design/frontend/Theme/Magento_Sales/templates/email/items.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php $_order = $block->getOrder() ?>
<?php if ($_order): ?>
    <?php $_items = $_order->getAllItems();
     ?>



    <table class="email-items" style="width: 650px; text-align="left"">

            <tr>
                <td style="background-color:#EAEAEA; width: 320px;  ">
                    <?= /* @escapeNotVerified */  __('Items') ?>
                </td>
                <td style="background-color:#EAEAEA; width: 100px; ">
                    <?= /* @escapeNotVerified */  __('Sku') ?>
                </td>
                <td style="background-color:#EAEAEA;width: 100px; ">
                    <?= /* @escapeNotVerified */  __('Qty') ?>
                </td>
                <td style="background-color:#EAEAEA; width: 120px;">
                    <?= /* @escapeNotVerified */  __('Subtotal') ?>
                </td>
            </tr>

        <?php foreach ($_items as $_item): ?>
            <?php if (!$_item->getParentItem()) : ?>
                <tbody>
                  <tr>
                <td class="item-info">
                    <?= /* @escapeNotVerified */  $_item->getName()?>
                   <table class="item-info">

            <?php 
            $options = $_item->getProductOptions();           
            $s="";
            $d="";
    if (isset($options['options']) ) {        
        foreach ($options['options'] as $option) {
            $s= $option['label'];
            $d= $option['value'];
        }
    }
            ?>

                       <tr class="item-price">
                           <td class="item-price"><?= /* @escapeNotVerified */ $s?></td>
                       </tr>
                       <tr class="item-price">
                           <td class="item-price"><?= /* @escapeNotVerified */ $d?></td>
                       </tr>
                   </table>
                </td>
                <td class="item-qty">
                    <?= /* @escapeNotVerified */  $_item->getSku() ?>
                </td>
                <td class="item-price">
                    <?= /* @escapeNotVerified */  $_item->getQtyOrdered() ?>
                </td>
                <td class="item-sku">
                    <?= /* @escapeNotVerified */  $_item->getPrice() ?>
                </td>
            </tr>
                </tbody>
            <?php endif; ?>
        <?php endforeach; ?></table>
           <table align="right" style="border-collapse: separate;
    border-spacing: 0 1em; width: 650px;">
  <tr>
    <td align="right"><?= /* @escapeNotVerified */  __('Subtotal') ?></td>
    <td align="right">  <?= /* @escapeNotVerified */  $_order->getSubtotal() ?></td>
  </tr>
  <tr>
    <td align="right"><?= /* @escapeNotVerified */  __('Shipping & Handling') ?></td>
    <td align="right"><?= /* @escapeNotVerified */  $_order->getShippingAmount() ?></td>
  </tr>
  <tr>
    <td align="right"><?= /* @escapeNotVerified */  __('Tax') ?></td>
    <td align="right"><?= /* @escapeNotVerified */  $_order->getTaxAmount() ?></td>
  </tr>
  <tr>
    <th align="right"><?= /* @escapeNotVerified */  __('Grant total') ?></th>
    <th align="right"><?= /* @escapeNotVerified */  $_order->getGrandTotal() ?></th>
  </tr>
</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; ?>

It will works like a charm.

4
  • Hi, I have tried this but the design is breaking. Please check my updated question
    – mysti
    Commented Mar 6, 2019 at 17:06
  • please close your first table before the second table. Commented Mar 7, 2019 at 6:36
  • Yes I already added this. Can you please let me know how add SKU in between Items and Qty as like Magento 1?
    – mysti
    Commented Mar 7, 2019 at 6:47
  • see my updated code. It will be useful Commented Mar 7, 2019 at 7:49
2

I have got this work, I have changed few things & now tis worked for me. Thanks @arun.

<?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; ?>
<tfoot class="order-totals">
  <tr class="subtotal">
        <th style="padding-right:20px;" align="right" colspan="2" scope="row">
            <?= /* @escapeNotVerified */  __('Subtotal') ?> 
        </th>
        <td>
           <span class="price">Rs: <?= /* @escapeNotVerified */  $_order->getSubtotal() ?></span> 
        </td>
  </tr>
  <tr class="shipping">
        <th style="padding-right:20px;" align="right" colspan="2" scope="row">
           <?= /* @escapeNotVerified */  __('Shipping & Handling') ?>                    
        </th>
        <td>
           <span class="price">Rs: <?= /* @escapeNotVerified */  $_order->getShippingAmount() ?></span> 
        </td>
   </tr>
   <tr class="grand_total">
        <th style="padding-right:20px;" align="right" colspan="2" scope="row">
            <strong><?= /* @escapeNotVerified */  __('Grant total') ?></strong>
        </th>
        <td>
            <strong><span class="price">Rs: <?= /* @escapeNotVerified */  $_order->getGrandTotal() ?></span></strong>
        </td>
    </tr>
</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; ?>
<?php endif; ?>
0

its work fine for me....

I modified the code to obtain 2 decimals for the price...

number_format($_order->getSubtotal(), '2', '.', ',')

0

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.