Would anyone know how we can change the order tracking URL on the order page (admin) to the shipping URL? (.../admin/order_shipment/view/shipment_id/xxxx) We have already managed to change the URL but we have not been able to set the shipping ID.
1 Answer
You have to do this via custom module.
Create block Info.php file Under the Vendor/Module/Block/Adminhtml/Order/View
<?php
/**
* Shipment view form
*
* @author Magento Core Team <[email protected]>
*/
namespace Vendor\Module\Block\Adminhtml\Order\View;
use Magento\Framework\View\Element\Template;
/**
* @api
* @since 100.0.2
*/
class Info extends Template
{
protected $_order;
public function __construct(
Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Sales\Model\Order $order,
array $data = []
) {
$this->_order = $registry->registry('current_order');
parent::__construct($context, $data);
}
public function getShipmentId()
{
$shipmentId = null;
if ($this->_order) {
foreach ($this->_order->getShipmentsCollection() as $shipment) {
$shipmentId = $shipment->getId();
break;
}
}
return $this->getUrl('admin/order_shipment/view', ['shipment_id' => $shipmentId]);
}
}
Create view file info.phtml under the Vendor/Module/view/adminhtml/templates/order/view
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* @var \Vendor\Module\Block\Adminhtml\Order\View\Info $block
*/
$shippingHelper = $block->getData('shippingHelper');
$taxHelper = $block->getData('taxHelper');
?>
<?php $order = $block->getOrder() ?>
<?php if ($order->getIsVirtual()):
return '';
endif; ?>
<?php
if ($order->hasShipments()) {
$shipment = $order->getShipmentsCollection()->getFirstItem();
$shipmentId = $shipment->getId();
}
$blockObj= $block->getLayout()->createBlock('Vendor\Module\Block\Adminhtml\Order\View\Info');
$customerUrl = $blockObj->getShipmentId();
?>
<?php /* Shipping Method */ ?>
<div class="admin__page-section-item order-shipping-method">
<div class="admin__page-section-item-title">
<span class="title"><?= $block->escapeHtml(__('Shipping & Handling Information')) ?></span>
</div>
<div class="admin__page-section-item-content">
<?php if ($order->getTracksCollection()->count()): ?>
<p>
<a href="<?= /* @noEscape */ $customerUrl ?>" id="linkId" title="<?= $block->escapeHtmlAttr(__('Track Order')) ?>">
<?= $block->escapeHtml(__('Track Order')) ?>
</a>
</p>
<?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
'onclick',
"popWin('" . $block->escapeJs($shippingHelper->getTrackingPopupUrlBySalesModel($order)) .
"','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')",
'a#linkId'
) ?>
<?php endif; ?>
<?php if ($order->getShippingDescription()): ?>
<strong><?= $block->escapeHtml($order->getShippingDescription()) ?></strong>
<?php if ($taxHelper->displayShippingPriceIncludingTax()): ?>
<?php $_excl = $block->displayShippingPriceInclTax($order); ?>
<?php else: ?>
<?php $_excl = $block->displayPriceAttribute('shipping_amount', false, ' '); ?>
<?php endif; ?>
<?php $_incl = $block->displayShippingPriceInclTax($order); ?>
<?= /** @noEscape */ $_excl ?>
<?php if ($taxHelper->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?= $block->escapeHtml(__('Incl. Tax')) ?> <?= /** @noEscape */ $_incl ?>)
<?php endif; ?>
<?php else: ?>
<?= $block->escapeHtml(__('No shipping information available')) ?>
<?php endif; ?>
</div>
</div>
Output look like: https://prnt.sc/HzZNfS1HRPHu