0

I got to override Magento FedEx Carrier.php in Magento-fedex module which is seen in the screenshot below.

enter image description here

The structure of the overriden Fedex module under app/code in the project is as below. All the previous custom modules I created the same way are working,but none of them had any Model directory within it.

enter image description here

registration.php, modul.xml are all edited accordingly. Also ran the upgrade commands. The change doesn't seem to have taken place. Am I overriding the module the way it should be?

di.xml file is as below.

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Config\Model\Config\TypePool">
        <arguments>
            <argument name="sensitive" xsi:type="array">
                <item name="carriers/fedex/account" xsi:type="string">1</item>
                <item name="carriers/fedex/key" xsi:type="string">1</item>
                <item name="carriers/fedex/meter_number" xsi:type="string">1</item>
                <item name="carriers/fedex/password" xsi:type="string">1</item>
                <item name="carriers/fedex/production_webservices_url" xsi:type="string">1</item>
                <item name="carriers/fedex/sandbox_webservices_url" xsi:type="string">1</item>
                <item name="carriers/fedex/smartpost_hubid" xsi:type="string">1</item>
            </argument>
            <argument name="environment" xsi:type="array">
                <item name="carriers/fedex/sandbox_mode" xsi:type="string">1</item>
            </argument>
        </arguments>
    </type>
    <type name="Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle">
        <plugin name="update_delivery_date_title" type="Magento\Fedex\Plugin\Block\DataProviders\Tracking\ChangeTitle"/>
    </type>
    <type name="Magento\Shipping\Block\Tracking\Popup">
        <plugin name="update_delivery_date_value" type="Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate"/>
    </type>
</config>
2
  • Show your di.xml content.
    – Sohel Rana
    Commented Jun 20, 2021 at 10:17
  • Please see above di.xml Commented Jun 20, 2021 at 11:01

1 Answer 1

1

You can easily extend the class Carrier.php by using preference in di.xml file in you custom module by extending the core functionality.

e.g:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <preference for="Magento\Fedex\Model\Carrier" type="Namespace\YourModule\Model\Carrier"/>
</config> 
9
  • Nihal, nothing else is necessary? Commented Jun 20, 2021 at 11:48
  • as you already created a module use this in your di.xml to override the core class Commented Jun 20, 2021 at 11:52
  • Okay, after adding your solution in di.xml, I'm compiling now. Is there a need to have all folders that you see in the custom module PmmFedex? Commented Jun 20, 2021 at 11:58
  • 1
    yes, if you want to override only the carrier.php class you can just remove all folders from your module accept etc and model. Commented Jun 20, 2021 at 12:02
  • dont forget to change the paths that i have used in di.xml Commented Jun 20, 2021 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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