magento - add totals block in shipment email

magento - add totals block in shipment email

September 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento - add totals block in shipment email

Solving Magento Shipment Email Total Display Issue

Hello there! I hope this post finds you well and helps solve your Magento totals display issue for shipment emails. Let’s dive right into the problem.

Current Approach: sales.xml and Template Modification

You’ve already taken a good initial step by modifying the sales_email_order_shipment_items block in your sales.xml layout file:

<block type="sales/order_invoice_totals" name="invoice_totals" template="sales/order/totals.phtml">
    <action method="setLabelProperties"><value>colspan="3" align="right" style="padding:3px 9px"</value></action>
    <action method="setValueProperties"><value>align="right" style="padding:3px 9px"</value></action>
    <block type="tax/sales_order_tax" name="tax" template="tax/order/tax.phtml"/>
</block>

And you’ve also added the totals block to your items.phtml template:

<tfoot>
    <?php echo $this->getChildHtml('invoice_totals'); ?>
</tfoot>

These changes seem logically sound, as they should pull in the invoice totals and display them in the shipment email.

The Missing Piece: Template Context

The key issue here lies in the context of the email template. Magento handles shipment emails differently than invoice emails, which is why your current setup isn’t working.

When you create a new shipment in the admin panel, Magento doesn’t actually send an immediate email. Instead, it creates an email record and waits for the sales_order_shipment_save_after event to trigger the actual email sending process.

This is likely where your totals block is being overlooked during this asynchronous processing stage.

The Solution: Event Observers

To ensure that your totals block appears in shipment emails, you need to create an event observer that triggers after a new shipment has been saved. This will allow Magento to properly handle the email rendering process with your modifications included.

Here’s a basic example of how you can set this up:

  1. Create a new module if you don’t have one already. Let’s call it Laravel_Email_Totals.

  2. In your etc/events.xml, define the observer for the sales_order_shipment_save_after event:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/config.xsd">
    <event name="sales_order_shipment_save_after">
        <observer name="laravel_email_totals_observer" instance="Laravel\EmailTotals\Observer\ShipmentSaveAfterObserver"/>
    </event>
</config>
  1. Create the observer class ShipmentSaveAfterObserver in your module’s Observer directory:
namespace Laravel\EmailTotals\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\Order\ShipmentRepository;

class ShipmentSaveAfterObserver implements ObserverInterface
{
    private $shipmentRepository;

    public function __construct(ShipmentRepository $shipmentRepository)
    {
        $this->shipmentRepository = $shipmentRepository;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        // TODO: Add your totals block rendering logic here
    }
}
  1. In the execute method of your observer, you can now add the logic to render the totals block for the shipment email using the provided $shipmentRepository.

Remember to clear your cache after making these changes.

Conclusion

Debugging Magento layout and template issues can often involve understanding the underlying event-driven architecture. In this case, the asynchronous nature of shipment email processing was the key factor preventing your totals block from appearing as expected.

By creating an event observer that triggers after a new shipment is saved, you can ensure that your custom totals display logic is properly applied during the actual email rendering process.

I hope this solution helps resolve your issue! If you have any questions or need further assistance with Magento development or other technical topics, feel free to check out our resources at Laravel Company.

Happy coding!

Themes Admin Email Orders

Our network