0

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.

Screenshot

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.

6
  • @mohitRana Use plugin instead of preference
    – user53909
    Feb 22, 2020 at 10:28
  • I've tried using a plugin but it shows only one module's output.
    – Mohit Rane
    Mar 4, 2020 at 8:35
  • Set different sort order of plugin. Mar 4, 2020 at 8:48
  • it gives me Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\Pricing\Price\PriceInterface in /var/www/html/magento_233/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50
    – Mohit Rane
    Mar 4, 2020 at 8:52
  • can you display code for this Vendor\Module2\Plugin\FinalPriceBox
    – user53909
    Mar 4, 2020 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.