Magento 2, override \lib\ classes
-
29-09-2020 - |
Question
Can you override the classes in \lib\internal\Magento\Framework
and if so how?
I know how to use plugins/preferences to override the classes in \code
but these methods do no seem to work with the lib classes. Thanks.
Solution
It's definitely feasible using preferences.
You can do something like this in a di.xml
file:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\Class\You\Want\To\Rewrite" type="Vendor\Module\Your\Class" />
</config>
This method is widely used in the Magento 2 original files, for example: https://github.com/magento/magento2/blob/develop/app/code/Magento/Backend/etc/di.xml
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange