0

I am trying to override a Model from a third Party vendor in a custom-theme. The original file was:

/vendor/3rdpartyompany/3rdpartymodule/Model/Formatter/BaseImage.php

I copied that file over to:

/vendor/customthemevendor/customtheme/Model/Formatter/BaseImage.php

and edited the namespace in that file:

namespace Customthemevendor\Customtheme\Model\Formatter;

Last I created a /etc/di.xml and set the preference:

<?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="3rdPartyCompany\3rdPartyModule\Model\Formatter\BaseImage" type="Customthemevendor\Customtheme\Model\Formatter\BaseImage" />
</config>

Magento2 doesn't seem to recognize my customization at all. (Basically, there is a resize image function with hardcoded values in the function, that I need to change).

Is the Overriding-process the same for themes and modules or am I missing something?

4
  • You can override module in your custom module not in theme. Commented Apr 14, 2021 at 7:33
  • So, there is no way to overriding it in the theme?
    – Mario
    Commented Apr 14, 2021 at 7:36
  • No, you can only override layout, templates, css, js, web templates under theme. Commented Apr 14, 2021 at 7:37
  • 1
    thank you. If you like, you can post that as an answer and I will mark it correct.
    – Mario
    Commented Apr 14, 2021 at 7:40

1 Answer 1

1

You can only override layout, templates, css, js, web templates under theme.

So in order to override third party module model use plugin or preference in your custom module.

Thanks!

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.