I have a simple payment method module.
I have successfully used Dependency Injection on both the 2 Controllers I have for 2 new Routes and on my Observer where I grab some data from the config.
BUT, I have been having an issue with my payment method not disabling which is still open here, and now I’m in the process of fixing that.
One solution I found is to implement my own isAvailable()
method which works for hardcoded Boolean values, but obviously I need to check if the config value is yes or no and return true or false accordingly, but when I do this, I get the error:
Error: Call to a member function getValue() on null in /var/www/html/app/code/Magento/Payment/Model/Method/AbstractMethod.php:736
Which is the return line on this one:
public function getConfigData($field, $storeId = null)
{
if ('order_place_redirect_url' === $field) {
return $this->getOrderPlaceRedirectUrl();
}
if (null === $storeId) {
$storeId = $this->getStore();
}
$path = 'payment/' . $this->getCode() . '/' . $field;
return $this->_scopeConfig->getValue($path, MagentoStoreModelScopeInterface::SCOPE_STORE, $storeId);
}
When I inject my own Helper class, which works fine everywhere else in my module, within my PaymentModel.php
it breaks the AbstractMethod class that I extend? How is that related?
Why would scopeConfig
would be null but only when I inject it in another class?
I obviously run php bin/magento setup:di:compile
and cache: clean
every time I change it.