alma / alma-monthlypayments-magento2

Magento 2 Payment Gateway integration for Alma
Other
6 stars 9 forks source link

Error with Website Scope on Store -> Configuration -> Sales -> Payment Method #87

Closed walkwizus closed 4 days ago

walkwizus commented 1 year ago

When you change the scope in Magento's configuration to the website, there are an error:

1 exception(s):
Exception #0 (Magento\Framework\Exception\NoSuchEntityException): The store that was requested wasn't found. Verify the store and try again.

Exception #0 (Magento\Framework\Exception\NoSuchEntityException): The store that was requested wasn't found. Verify the store and try again.
<pre>#1 Magento\Store\Model\StoreManager->getStore() called at [generated/code/Magento/Store/Model/StoreManagerInterface/Proxy.php:119]
#2 Magento\Store\Model\StoreManagerInterface\Proxy->getStore() called at [vendor/magento/module-store/Model/Resolver/Store.php:30]
#3 Magento\Store\Model\Resolver\Store->getScope() called at [vendor/magento/framework/App/Config/ScopeCodeResolver.php:49]
#4 Magento\Framework\App\Config\ScopeCodeResolver->resolve() called at [vendor/magento/framework/App/Config.php:69]
#5 Magento\Framework\App\Config->getValue() called at [vendor/magento/module-payment/Gateway/Config/Config.php:94]
#6 Magento\Payment\Gateway\Config\Config->getValue() called at [vendor/almapay/alma-monthlypayments-magento2/Gateway/Config/Config.php:126]
#7 Alma\MonthlyPayments\Gateway\Config\Config->get() called at [vendor/almapay/alma-monthlypayments-magento2/Gateway/Config/Config.php:140]
#8 Alma\MonthlyPayments\Gateway\Config\Config->getIsActive() called at [vendor/almapay/alma-monthlypayments-magento2/Block/Adminhtml/System/Config/GeneralGroupFrontModel.php:30]
#9 Alma\MonthlyPayments\Block\Adminhtml\System\Config\GeneralGroupFrontModel->_getHeaderCommentHtml() called at [vendor/magento/module-config/Block/System/Config/Form/Fieldset.php:140]

The following method in Helpers/StoreHelper.php return a website ID:

private function backStoreId(): string
    {
        $store = $this->request->getParam('store');
        if ($store) {
            return $store;
        }
        $website = $this->request->getParam('website');
        if ($website) {
            return $website;
        }
        return '0';
    }

Magento is attempt a Store ID in module-payment/Gateway/Config.php:

public function getValue($field, $storeId = null)
    {
        if ($this->methodCode === null || $this->pathPattern === null) {
            return null;
        }

        return $this->scopeConfig->getValue(
            sprintf($this->pathPattern, $this->methodCode, $field),
            ScopeInterface::SCOPE_STORE,
            $storeId
        );
    }