I'm overriding a Magento\Catalog\Pricing\Render\FinalPriceBox
in my two different modules.
Vendor\Module1\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\Module1\Block\FinalPriceBox" />
</config>
Vendor\Module2\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\Module2\Block\FinalPriceBox" />
</config>
Both Class Overrides the same method
wrapResult($html)
.
It only shows the output of Module2, not both modules output at the same time. I've installed the Conflict detector Extension to see the confliction which shows something like this.
What I've tried so far,
How to override core class which is already overrided by other custom module in Magento 2
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Vendor\Module1\Block\FinalPriceBox" type="Vendor\Module2\Block\FinalPriceBox" />
</config>
but it gives me the error as shown below,
1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Vendor\Module2\Block\FinalPriceBox\Interceptor
UPDATE
I've tried using a plugin but it shows only one module's output.
Vendor\Module1\etc\di.xml
<type name="\Magento\Catalog\Pricing\Render\FinalPriceBox">
<plugin name="vendor_module1_finalpricebox" type="Vendor\Module1\Plugin\FinalPriceBox" sortOrder="1"/>
</type>
Vendor\Module2\etc\di.xml
<type name="\Magento\Catalog\Pricing\Render\FinalPriceBox">
<plugin name="vendor_module2_finalpricebox" type="Vendor\Module2\Plugin\FinalPriceBox" sortOrder="1"/>
</type>
Let me know if anyone has a solution.