1

I am trying to call helper function on observer custom module in Magento2 but Unable to call helper in observer.

Please help me if anybody have this solution. I am waiting for all your positive response.

1
  • 1
    show us what you tried. normaly oyu just have to inject it into the constructor Jan 21, 2019 at 13:23

1 Answer 1

8

Try something like below in your observer file.

<?php

namespace Custom\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class SalableObserver implements ObserverInterface
{
    ...

    protected $dataHelper;

    ...

    public function __construct(
        ...
        \Custom\Module\Helper\Data $dataHelper
        ...
    ) {
        ...
        $this->dataHelper = $dataHelper;
        ...
    }

    public function ...(){
        $helper = $this->dataHelper;
    }

    ...
}

?>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.