0

How can I Override a Third Party Extension? The Path for the Extension is: app/code/extension_company/extension/model/file.php

Can I Override this php File by my custom Theme?

1
  • Please provide additional information about the exact circumstances and exactly what you are trying to accomplish. Without specifics, it's hard to solve your exact problem and ensure you're using the best approach. cf. meta.stackexchange.com/a/66378
    – Ryan Hoerr
    Commented May 8, 2017 at 18:37

2 Answers 2

1

Yes,You can use plugin at here.

<?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="extension_company/extension/model/file">
        <plugin disabled="false" name="overrider_the_third_part_file" sortOrder="10" type="[VendorName]\[ModuleName]\Plugin\FILE"/>
    </type>
</config>

Use after,before,around method basic of your requirement.

1
  • Ok, and where must i save the custom di.xml file? Commented May 8, 2017 at 17:45
0

You can override the php file in your own custom module. You can create your module and override the php file like this:

app/code/Vendor/module_name/model/classname.php

You also need to create di.xml file at the following location wherein you will set the preference for your Class in classname.php

app/code/Vendor/module_name/etc/di.xml

di.xml example

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\ModuleName\Model\Classname" type="Vendor\ModuleName\Model\Classname" />
</config>

classname.php example

<?php
namespace Vendor\ModuleName\Model;

class Classname extends \Magento\ModuleName\Model\Classname
{
   //your code goes here.
}
1

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.