0

I am trying to override/rewrite Magento\Fedex\Model\Source\Generic by using preference but to no avail.

Is there some other way that is used to override source models in Magento 2?

1 Answer 1

1

You can do it via plugin. First of all you must create di.xml

<config>
    <type name="Magento\Fedex\Model\Source\Generic">
      <plugin name="your_plugin_name" type="YourVendor\YourModule\Plugin\GenericPlugin" sortOrder="10" />
    </type>
</config>

Then you must create GenericPlugin.php and use after method.

namespace YourVendor\YourModule\Plugin;

class GenericPlugin
{
    public function afterToOptionArray(\Magento\Fedex\Model\Source\Generic $subject, $result)
    {
        // here you change the result
        return $anotherResult;
    }
}

More information here.

2
  • Thankyou for reply. The thing is that I have to pass different params to __construct that current params being sent. So I think that would not be possible with plugin Commented Mar 27, 2018 at 10:22
  • May I ask what you're trying to inject, and why? @Vivek Kumar Commented Mar 28, 2018 at 1:34

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.