I am using Magento 2.3.1 CE. My English is not perfect sorry. Admin > Marketing > Email Templates > Shipment Email Template When I click preview template, I see this error.

Fatal error: Uncaught Error: Call to a member function getTracksCollection() on null in /var/www/html/var/view_preprocessed/pub/static/vendor/magento/module-sales/view/frontend/templates/email/shipment/track.phtml:1

I added a picture. https://prnt.sc/nyyeei

enter image description here


You can create a template file in your theme this core file :


and add condition before this function


you can add condition like this

<?php if ($_shipment && $_order): ?>

So that issue will fixed for magento 2.3.1


We had the same issue in Magento 2.2.8. The reason is, when you try to review mail template there is not available order object.

I have fixed it in this way.

Created a template file in the custom theme: Magento_Sales/templates/email/shipment/track.phtml

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

// @codingStandardsIgnoreFile

<?php $_shipment = $block->getShipment() ?>
<?php $_order = $block->getOrder() ?>
<?php if ($_shipment && $_order): ?>
    <?php $trackCollection = $_order->getTracksCollection($_shipment->getId()) ?>
    <br />
    <table class="shipment-track">
            <th><?= /* @escapeNotVerified */  __('Shipped By') ?></th>
            <th><?= /* @escapeNotVerified */  __('Tracking Number') ?></th>
        <?php if ($trackCollection): ?>
            <?php foreach ($trackCollection as $_item): ?>
                    <td><?= $block->escapeHtml($_item->getTitle()) ?>:</td>
                    <td><?= $block->escapeHtml($_item->getNumber()) ?></td>
            <?php endforeach ?>
        <?php endif; ?>
<?php endif; ?>

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.