I have installed my Shipping Tracker module in Magento 2.3.5p1, I have added a custom Shipping method which is showing in the dropdown in the backend on the Order shipment page as below,
Note: This issue is only on Magento 2.3.5p1, it's working fine for Magento 2.3.4
After selecting the custom shipping method, the carrier is showing Custom Value
instead of the Shiprocket1
, Although it is showing for default methods. Check below screenshot,
You can check the inspect element in the below screenshot so you can have more idea,
Here is the code for adding a custom shipping method to dropdown,
Vendor/Shippingtracker/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Shipping\Block\Adminhtml\Order\Tracking">
<plugin name="carrier_options_backend_shipment" type="Vendor\Shippingtracker\Plugin\Block\Adminhtml\Order\Tracking" sortOrder="5" />
</type>
</config>
Vendor/Shippingtracker/Plugin/Block/Adminhtml/Order/Tracking.php
<?php
namespace Vendor\Shippingtracker\Plugin\Block\Adminhtml\Order;
class Tracking
{
public function __construct(
\Vendor\Shippingtracker\Helper\Data $shippingTrackerHelper
) {
$this->shippingTrackerHelper = $shippingTrackerHelper;
}
public function afterGetCarriers(\Magento\Shipping\Block\Adminhtml\Order\Tracking $subject, $result)
{
$customCarrier = $this->shippingTrackerHelper->getCustomCarrierTitle();
if (!empty($customCarrier)) {
foreach ($customCarrier as $code => $carrierTitle) {
$result[$code] = $carrierTitle;
}
}
return $result;
}
}
Helper Method
getCustomCarrierTitle()
public function getCustomCarrierTitle()
{
$j = 15;
$customCarrier = [];
for ($i=1; $i <= $j; $i++) {
$enable = 'shippingtracker_section/custom_shippingtracker_'.$i.'/custom_shippingtracker_enable_'.$i;
$Title = 'shippingtracker_section/custom_shippingtracker_'.$i.'/custom_shippingtracker_title_'.$i;
$carrierEnable = $this->getConfigValue($enable);
$carrierTitle = $this->getConfigValue($Title);
if ($carrierEnable) {
if ($carrierTitle) {
$customCarrier['customcarrier'.$i] = $carrierTitle;
}
}
}
return $customCarrier;
}
System.xml for $enable and $Title
<group id="custom_shippingtracker_1" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Custom Shipping Tracker 1</label>
<field id="custom_shippingtracker_enable_1" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="custom_shippingtracker_title_1" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Method Title</label>
<validate>required-entry</validate>
<depends>
<field id="shippingtracker_section/custom_shippingtracker_1/custom_shippingtracker_enable_1">1</field>
</depends>
</field>
<field id="custom_shippingtracker_url_1" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Url</label>
<validate>required-entry</validate>
<comment>
<![CDATA[replace the TrackingNumber to {{tracking_code}},<br/> example:<br/><strong>"http://www.example.com?trackingNumber=#TRACKINGNUMBER#"</strong> To <br/><strong>"http://www.example.com?TrackingNumber={{tracking_code}}"</strong>]]>
</comment>
<depends>
<field id="shippingtracker_section/custom_shippingtracker_1/custom_shippingtracker_enable_1">1</field>
</depends>
</field>
</group>
I have also tried overriding the
\Magento\Shipping\Block\Adminhtml\Order\Tracking
class, but I don't see my custom shipping method in the dropdown so I don't think that's working as well.
Any help would be appreciated.