Magento 2 track order issue (track order link not working when an order has more than one shipment)

Magento 2 track order issue (track order link not working when an order has more than one shipment)
This blogpost has a fix for core magento issue i.e, track order not working when more than one shipment is placed. Below is the screen you will get when you will place more than one shipment for a single order.

This issue is because in popup.phtml we have called child block to show every shipment details but if you check below code

'shipping.tracking.details.' . $counter 

Above code only has counter which is index of an array of track details and for every shipment it will take counter as 0, thus we will get an issue that block already called or exist. To fix this we have to make it unique so I have added ship id to this. You need to override popup.phtml in your code and replace it with below code:-

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

use Magento\Framework\View\Element\Template;

// @codingStandardsIgnoreFile

/** @var $block \Magento\Shipping\Block\Tracking\Popup */

$results = $block->getTrackingInfo();
?>
<div class="page tracking">
    <?php if (!empty($results)): ?>
        <?php foreach ($results as $shipId => $result): ?>
            <?php if ($shipId): ?>
                <div class="order subtitle caption"><?php /* @noEscape */ echo $block->escapeHtml(__('Shipment #')) . $shipId; ?></div>
            <?php endif; ?>
            <?php if (!empty($result)): ?>
                <?php foreach ($result as $counter => $track): 
                if(!is_array($track)) {
                ?>
                    <div class="table-wrapper">
                        <?php
                            $block->addChild('shipping.tracking.details.' . $counter . $shipId, Template::class, [
                                'track' => $track,
                                'template' => 'Magento_Shipping::tracking/details.phtml',
                                'storeSupportEmail' => $block->getStoreSupportEmail()
                            ]
                        );
                        ?>
                        <?php /* @noEscape */ echo $block->getChildHtml('shipping.tracking.details.' . $counter. $shipId); ?>
                    </div>
                    <?php if (!empty($track->getProgressdetail())): ?>
                        <?php
                            $block->addChild('shipping.tracking.progress.'. $counter, Template::class, [
                                'track' => $track,
                                'template' => 'Magento_Shipping::tracking/progress.phtml'
                            ]);
                        ?>
                        <?php /* @noEscape */ echo $block->getChildHtml('shipping.tracking.progress.' . $counter); ?>
                    <?php endif; 

                }
                    ?>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="message info empty">
                    <div><?php echo $block->escapeHtml(__('There is no tracking available for this shipment.')); ?></div>
                </div>
            <?php endif; ?>
        <?php endforeach; ?>
    <?php else: ?>
        <div class="message info empty">
            <div><?php echo $block->escapeHtml(__('There is no tracking available.')); ?></div>
        </div>
    <?php endif; ?>
    <div class="actions">
        <button type="button"
                title="<?php echo $block->escapeHtml(__('Close Window')); ?>"
                class="action close"
                onclick="window.close(); window.opener.focus();">
            <span><?php echo $block->escapeHtml(__('Close Window')); ?></span>
        </button>
    </div>
</div>

1 Comments

Leave a Comment.