How to override core class which is already overrided by other custom module in Magento 2
Module ONE is overriding some core class, if you want to override same core class already used/override module ONE, override Module ONE class by using your module( Module Two )as below example.
Module ONE as Vendor/Module
Vendor/Module
is extending Magento\CatalogSearch\Block\Result
In di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogSearch\Block\Result" type="Vendor\Module\Block\Result"/>
</config>
In Block result.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\Module\Block;
/**
* Product search result block
*/
class Result extends \Magento\CatalogSearch\Block\Result
{
public function getSearchQueryText()
{
die('Module ONE');
// Some code
return parent::getSearchQueryText();
}
}
Module TWO as Vendor/Moduletwo
Vendor/Moduletwo
is extending Vendor\Module\Block\Result
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Vendor\Module\Block\Result" type="Vendor\Moduletwo\Block\Result"/>
</config>
In block result.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\Moduletwo\Block;
/**
* Product search result block
*/
class Result extends \Vendor\Module\Block\Result
{
public function getSearchQueryText()
{
die('TWO');
// Some code
return parent::getSearchQueryText();
}
}
In this case both extension functionalities will work.