0

There is error Call to a member function getValue() on null magento 2.4.6 after upgrading from Magento 2.3.3 to 2.4.6. It was working fine with earlier Magento 2 version. Here is code:

public function isModuleEnable() {
    $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
    return $this->scopeConfig->getValue('ordergrid/general/enable', $storeScope);
}

The system.xml file is fine as it was working earlier. It's throwing error on getValue on null.

1
  • Show your full class.
    – Sohel Rana
    Jun 18 at 13:59

2 Answers 2

0

have you checked the value of ordergrid/general/enable path in core_config_data ?

1
  • Yes I checked and this exists in Database. It isn't picking any store config value. That's strange. Jun 19 at 8:56
0

You need to add the Magento\Store\Model\ScopeInterface class in your constructor:

Code like below

protected $_scopeConfig;

public function __construct(
     ...
     \Magento\Store\Model\ScopeInterface $scopeInterface,
     ...
)
{
    ...
    $this->_scopeConfig = $scopeInterface;
    ...
}


public function isModuleEnable() {
    $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
    return $this->scopeConfig->getValue('ordergrid/general/enable', $storeScope);
}
1
  • I already added this dependency in constructor. I know how to get the value but the problem is it's throwing error. That's what I wanted to know if there is any other pattern used in latest version that I am missing. Jun 19 at 8:58

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.