I am developing a module and I need to instantiate a helper of another module only if this module exists (is installed).

use \Magento\CatalogSearch\Helper\Data as CatalogSearch;
use \Magento\Framework\App\Helper\AbstractHelper as DoofinderSearch;

class Doofinder extends Base

    protected $_catalogSearchHelper;
    protected $_doofinderShearch;

    public function __construct(CatalogSearch $catalogSearchHelper, DoofinderSearch $doofinderSearch) {

        $this->_catalogSearchHelper = $catalogSearchHelper;
        $this->_doofinderShearch = $doofinderSearch;


My di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="My\Module\Helper\Search\Doofinder">
            <argument name="doofinderSearch" xsi:type="object">Doofinder\Feed\Helper\Search</argument>

Doofinder\Feed\Helper\Search inherit AbstractHelper and that throw exception that the abstract class cannot obviously be instantiated.

any ideas to fix this? Can Helper be instantiated in constructor only if class exists? thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.