If we want to override a 3rd party module other than magento’s default.
We need to create a di.xml with the same folder layout in the code folder.
Try out the code in the di.xml
<?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="Invoicing\Moloni\Libraries\MoloniLibrary\Controllers\Products" type="[Vendor]\[Module]\Libraries\Products" />
</config>
And in the php file just map the location as per the code folder structure
<?php
namespace [Vendor]\[Module]\Libraries;
use Invoicing\Moloni\Libraries\MoloniLibrary\Controllers\Products as vendormoloni
class Products extends vendormoloni
{
// Enter your custom code here
}
Here, [Vendor] and [Module] is your custom/existing module/plugin.
Note:
To override vendormoloni not extends/inherit private variable and function you redefine it.
Thanks