0

This question already has an answer here:

I add this link in sales order history section when I click on this link popup open but blank shown I add this link.

 <block class="Magento\Shipping\Block\Tracking\Link" name="tracking-info-link" template="Magento_Shipping::tracking/link.phtml">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Track your order</argument>
            </arguments>
        </block>

enter image description here

marked as duplicate by Sumit, Jai, Mohit Kumar Arora, Manashvi Birla, Shoaib Munir Sep 24 at 11:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Edited: Just realized that you're on order history page. This block Magento\Shipping\Block\Tracking\Link generates a window url via order which is retrieved from registry.

File: vendor/magento/module-shipping/view/frontend/templates/tracking/link.phtml

<?php /** @var $block \Magento\Shipping\Block\Tracking\Link */ ?>
<?php $order = $block->getOrder() ?>

File: vendor/magento/module-shipping/Block/Tracking/Link.php Line: 61
public function getOrder()
{
    return $this->_coreRegistry->registry('current_order');
}

The order is set in registry at the time you click on View Order on history page. Since you do not view a specific order there is no order in registry saved. Or possibly a wrong one from a former view.

Possible solution based on Magento 2.3.2:

app/code/Order/Tracking/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Order_Tracking"/>
</config>

app/code/Order/Tracking/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Order_Tracking',
    __DIR__
);

app/code/Order/Tracking/view/frontend/layout/sales_order_history.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="sales.order.history">
            <arguments>
                <argument name="tracking_view_model" xsi:type="object">Order\Tracking\ViewModel\Tracking</argument>
            </arguments>
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Order_Tracking::order/history.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

app/code/Order/Tracking/view/frontend/templates/order/history.phtml

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

// @codingStandardsIgnoreFile

/** @var \Magento\Sales\Block\Order\History $block */
/** @var \Order\Tracking\ViewModel\Tracking $trackingModel */

?>
<?php $_orders = $block->getOrders(); ?>
<?php $trackingModel = $block->getData('tracking_view_model'); ?>
<?= $block->getChildHtml('info') ?>
<?php if ($_orders && count($_orders)): ?>
    <div class="table-wrapper orders-history">
        <table class="data table table-order-items history" id="my-orders-table">
            <caption class="table-caption"><?= /* @escapeNotVerified */ __('Orders') ?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Order #') ?></th>
                    <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                    <?= /* @noEscape */ $block->getChildHtml('extra.column.header') ?>
                    <th scope="col" class="col shipping"><?= /* @escapeNotVerified */ __('Ship To') ?></th>
                    <th scope="col" class="col total"><?= /* @escapeNotVerified */ __('Order Total') ?></th>
                    <th scope="col" class="col status"><?= /* @escapeNotVerified */ __('Status') ?></th>
                    <th scope="col" class="col actions"><?= /* @escapeNotVerified */ __('Action') ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($_orders as $_order): ?>
                    <tr>
                        <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id"><?= /* @escapeNotVerified */ $_order->getRealOrderId() ?></td>
                        <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_order->getCreatedAt()) ?></td>
                        <?php $extra = $block->getChildBlock('extra.container'); ?>
                        <?php if ($extra): ?>
                            <?php $extra->setOrder($_order); ?>
                            <?= /* @noEscape */ $extra->getChildHtml() ?>
                        <?php endif; ?>
                        <td data-th="<?= $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?= $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
                        <td data-th="<?= $block->escapeHtml(__('Order Total')) ?>" class="col total"><?= /* @escapeNotVerified */ $_order->formatPrice($_order->getGrandTotal()) ?></td>
                        <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?= /* @escapeNotVerified */ $_order->getStatusLabel() ?></td>
                        <td data-th="<?= $block->escapeHtml(__('Actions')) ?>" class="col actions">
                            <a href="<?= /* @escapeNotVerified */ $block->getViewUrl($_order) ?>" class="action view">
                                <span><?= /* @escapeNotVerified */ __('View Order') ?></span>
                            </a>
                            <?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
                                <a href="#" data-post='<?php /* @escapeNotVerified */ echo
                                $this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
                                    ->getPostData($block->getReorderUrl($_order))
                                ?>' class="action order">
                                    <span><?= /* @escapeNotVerified */ __('Reorder') ?></span>
                                </a>
                            <?php endif ?>
                            <?php if ($_order->getShipmentsCollection()->getSize()): ?>
                                <a href="#"
                                   class="action order"
                                   data-mage-init='{"popupWindow": {"windowURL":"<?= /* @escapeNotVerified */ $trackingModel->getTrackingPopupUrlBySalesModel($_order) ?>","windowName":"trackorder","width":800,"height":600,"left":0,"top":0,"resizable":1,"scrollbars":1}}'>
                                    <span><?= /* @escapeNotVerified */ __('Track your order') ?></span>
                                </a>
                            <?php endif ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getPagerHtml()): ?>
        <div class="order-products-toolbar toolbar bottom"><?= $block->getPagerHtml() ?></div>
    <?php endif ?>
<?php else: ?>
    <div class="message info empty"><span><?= /* @escapeNotVerified */ __('You have placed no orders.') ?></span></div>

app/code/Order/Tracking/ViewModel/Tracking.php

<?php

namespace Order\Tracking\ViewModel;

use Magento\Framework\View\Element\Block\ArgumentInterface;

class Tracking implements ArgumentInterface
{
    /**
     * @var \Magento\Shipping\Helper\Data
     */
    private $shippingHelper;

    /**
     * Tracking constructor.
     * @param \Magento\Shipping\Helper\Data $shippingHelper
     */
    public function __construct(\Magento\Shipping\Helper\Data $shippingHelper)
    {
        $this->shippingHelper = $shippingHelper;
    }

    public function getTrackingPopupUrlBySalesModel($order)
    {
        return $this->shippingHelper->getTrackingPopupUrlBySalesModel($order);
    }
}
  • thanks for answer i just add this in history.phtml file and its work for m – imtiazau Sep 25 at 5:01
  • <a href="#" id="linkId" data-mage-init='{"popupWindow": {"windowURL":"<?= $this->helper('Magento\Shipping\Helper\Data')->getTrackingPopupUrlBySalesModel($_order) ?>","windowName":"trackorder","width":800,"height":600,"left":0,"top":0,"resizable":1,"scrollbars":1}}' title="<?= /* @escapeNotVerified */ __('Track Your Order') ?>"> – imtiazau Sep 25 at 5:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.