0

Is their any way we can override email/shipment/track.phtml ? in module ?

created layout file

view/frontend/layout/sales_email_order_shipment_track.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="tracking">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Mod_Sales::email/shipment/track.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

created template file

view/frontend/templates/email/shipment/track.phtml

Any thoughts what can be the issue ?

New contributor
devhs is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • I have added this layout file but its not working – devhs Feb 22 at 6:28
  • any thoughts ?? – devhs Feb 22 at 6:45
  • I am checking for you. Please give me few mins. – ZealousWeb Feb 22 at 6:46
  • I have added correct answer for you. Please approve and upvote my answer. Thanks! Enjoy coding. – ZealousWeb Feb 22 at 6:52
1

I have checked your code , you have taken wrong referenceBlock.

Please use below code in your xml file (sales_email_order_shipment_track.xml)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="sales.order.email.shipment.track">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">PackageName_Module::email/shipment/track.phtml</argument>
        </action>
    </referenceBlock>
</page>

Please create file track.phtml under path PackageName/Module/view/frontend/templates/email/shipment/

Put below code :-

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php /* @var \Magento\Framework\View\Element\Template $block */ ?>
<?php $_shipment = $block->getShipment() ?>
<?php
/* @var \Magento\Sales\Model\Order $_order */
$_order = $block->getOrder() ?>
<?php if ($_shipment && $_order) : ?>
    <?php $trackCollection = $_order->getTracksCollection($_shipment->getId()) ?>
    <?php if ($trackCollection) : ?>
        <br />
        <table class="shipment-track">
            <thead>
            <tr>
                <th><?= $block->escapeHtml(__('Shipped By dhwani')) ?></th>
                <th><?= $block->escapeHtml(__('Tracking Number')) ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($trackCollection as $_item) : ?>
                <tr>
                    <td><?= $block->escapeHtml($_item->getTitle()) ?>:</td>
                    <td>
                        <a href="<?= $block->escapeUrl($block->getTrackingUrl()->getUrl($_item)) ?>" target="_blank">
                            <?= $block->escapeHtml($_item->getNumber()) ?>
                        </a>
                    </td>
                </tr>
            <?php endforeach ?>
            </tbody>
        </table>
    <?php endif; ?>
<?php endif; ?>

In above code i have changed title like below to check it is working or not.

<th><?= $block->escapeHtml(__('Shipped By dhwani')) ?>

And i have got below output in email:-

https://prnt.sc/103grlp

12
  • I have checked this its not working, the module phtml is not getting called – devhs Feb 22 at 7:05
  • I have checked it practically and it is working. – ZealousWeb Feb 22 at 7:07
  • can you please send me that module ? – devhs Feb 22 at 7:09
  • Sure, Also i have updated my code here. Please check once. If still it does not work for you, i will send a module. – ZealousWeb Feb 22 at 7:11
  • Sure thanks, let me check – devhs Feb 22 at 7:11

Your Answer

devhs is a new contributor. Be nice, and check out our Code of Conduct.

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.