cancel
Showing results for 
Search instead for 
Did you mean: 

Extend Block that already extend from another modul

Extend Block that already extend from another modul

hello, i have 2 custom modules and all is extend from core class module-checkout \Magento\Checkout\Block\Onepage\Success, the issue if i install two modules together only one modules that can show custom view success.phtml, the other one is always use default magento 2 success.phtml, please anyone give me advice

5 REPLIES 5

Re: Extend Block that already extend from another modul

You need to set a dependency on the module using an etc/module.xml file.

You can set dependency via <sequence> tag in module.xml file.

 

A second way, Extend block with module block class instead of Core Checkout Block and your changes will be display based on final module.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Extend Block that already extend from another modul

hello, i already try add <module name="myVendor_moduleB"/> in moduleA module.xml  and than i extends moduleA block at moduleB block with Success extends \myVendor\moduleA\Block\Checkout\Success but still not working, is this right approach?

Re: Extend Block that already extend from another modul

Hello @first_last8,

 

Please add your method/function on that third party class and also keep your override method on site so whenever that third-party extension will be disabled at that time that class is overridden by your module.

 

--
If my answer is useful, please Accept as Solution & give Kudos

Re: Extend Block that already extend from another modul

what mean third party class? should i make new module to extend core class?

i need all moduleA and moduleB enabled, if only one of moduleA or moduleB enabled they work normal, i think its because two block rewrites same core block, correct me if im wrong.

can you give me example? so i can figure out what you mean. thanks before

Re: Extend Block that already extend from another modul

Hello @first_last8,

 

Need to override class this Vendor\moduleA\Block\Checkout\Success
which is already override by Module_Abc which is third party 

 

Now, Please add your logic on Module_Abc's override class and also add logic for your class Module_Xyz also so for now your logic will work from third party class and working as excepted

 

In future, suppose Module_Abc will be disabled then that logic takes form Module_Xyz class so it's working as smoothly

 

--
If my answer is useful, please Accept as Solution & give Kudos