0

I am trying to improve the look of "New Order" email template. I managed to get as far as adding the price of each item including and excluding tax.

Now, I want to add the "Tax Amount" to the totals section, how can I implement this? Please see the below image:

enter image description here

I know the totals are being rendered from /http/app/design/frontend/themevendor/theme/template/sales/order/totals.phtml in a foreach loop.:

<?php foreach ($this->getTotals() as $_code => $_total): ?>
    <?php if ($_total->getBlockName()): ?>
        <?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
    <?php else:?>
    <tr class="<?php echo $_code?>">
        <td colspan="6" <?php echo $this->getLabelProperties()?>>
            <?php if ($_total->getStrong()):?>
            <strong><?php echo $this->escapeHtml($_total->getLabel());?></strong>
            <?php else:?>
            <?php echo $this->escapeHtml($_total->getLabel());?>
            <?php endif?>
        </td>
        <td <?php echo $this->getValueProperties()?>>
            <?php if ($_total->getStrong()):?>
            <strong><?php echo $this->formatValue($_total) ?></strong>
            <?php else:?>
            <?php echo $this->formatValue($_total) ?>
            <?php endif?>
        </td>
    </tr>
    <?php endif?>
<?php endforeach?>

I am sure that I need to add the field in the /http/app/code/core/Mage/Sales/Block/Order/Totals.php file but having some difficult time trying.

0

Finally, I got somewhere. It might be not ideal but will do the trick for me. If anyone ever needs it.

Here is the updated /http/app/design/frontend/themevendor/theme/template/sales/order/totals.phtml file:

<?php
$totalTax = $this->getTotalTax();
?>
<?php foreach ($this->getTotals() as $_code => $_total): ?>
    <?php if ($_total->getBlockName()): ?>
        <?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
    <?php else:?>
    <tr class="<?php echo $_code?>">
        <td colspan="6" <?php echo $this->getLabelProperties()?>>
            <?php if ($_total->getStrong()):?>
            <strong><?php echo $this->escapeHtml($_total->getLabel());?></strong>
            <?php else:?>
            <?php echo $this->escapeHtml($_total->getLabel());?>
            <?php endif?>
        </td>
        <td <?php echo $this->getValueProperties()?>>
            <?php if ($_total->getStrong()):?>
            <strong><?php echo $this->formatValue($_total) ?></strong>
            <?php else:?>
            <?php echo $this->formatValue($_total) ?>
            <?php endif?>
        </td>
    </tr>

    <?php endif?>
      <?php if($_total->getLabel() == "Grand Total (Excl.Tax)"){ ?>
          <tr>
              <td colspan="6" <?php echo $this->getLabelProperties()?>>
                  <?php if ($_total->getStrong()):?>
                  <strong><?php echo $totalTax["code"];?></strong>
                  <?php else:?>
                  <?php echo $totalTax["code"];?>
                  <?php endif?>
              </td>
              <td <?php echo $this->getValueProperties()?>>
                  <?php if ($_total->getStrong()):?>
                  <strong><?php echo $totalTax["value"]; ?></strong>
                  <?php else:?>
                  <?php echo $totalTax["value"]; ?>
                  <?php endif?>
              </td>
          </tr>
        <?php } ?>
<?php endforeach?>

You also need to add this new function to the /http/app/code/core/Mage/Sales/Block/Order/Totals.php. It's never a good practise to overwrite the core files, so just copy this file to this /http/app/code/local/Mage/Sales/Block/Order/Totals.php path and add this function below the getTotals function:

public function getTotalTax(){
      $totals = $this->_totals;
      $grandtotal_include;
      $grandtotal_exclude;
     foreach($totals as $total){
       $totalData;
       $totalData = $total->getData();
       if($totalData["code"] == "grand_total_incl"){
         $grandtotal_include = $totalData["value"];
       }
       if($totalData["code"] == "grand_total"){
         $grandtotal_exclude = $totalData["value"];
       }
     }
     $tax = $grandtotal_include - $grandtotal_exclude;
     round($tax, 2);
     $formattedTax = Mage::helper('core')->currency($tax, true, false);
     $returnTax = array("code" => "Tax Amount", "value" => $formattedTax);
     return $returnTax;
    }

I hope someone will find this useful.

| improve this answer | |

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.