Skip to content

Commit

Permalink
Merge pull request #18 from SwedbankPay/hotfix/scope-config
Browse files Browse the repository at this point in the history
Improve scope functionality
  • Loading branch information
shahriar-vdc authored Apr 22, 2021
2 parents 9ccc810 + 492bf6b commit 369cde9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,29 @@ public function isPayment($module = '')
return $isPayment;
}

/**
* @param string $scopeType
* @param string|int $scopeId
* @param string $module
* @return bool
*/
public function isScopeActive($scopeType, $scopeId, $module = 'core')
{
if ($scopeType === ScopeInterface::SCOPE_STORES) {
return $this->isActive($scopeId, $module);
}

if ($this->isPayment($module)) {
$configPath = $this->getPaymentConfigPath('active', $module);
}

if (!isset($configPath)) {
$configPath = $this->getConfigPath('active', $module);
}

return $this->scopeConfig->isSetFlag($configPath, $scopeType, $scopeId);
}

/**
* @param Store|int|string|null $store
* @param string $module
Expand All @@ -207,6 +230,8 @@ public function isPayment($module = '')
*/
public function isActive($store = null, $module = 'core')
{
$store = $store ?? $this->storeManager->getStore()->getId();

if ($this->isPayment($module)) {
$configPath = $this->getPaymentConfigPath('active', $module);
}
Expand Down
2 changes: 1 addition & 1 deletion Observer/ConfigChangeObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function execute(Observer $observer)

$moduleConfigHelper = $this->configFactory->create($moduleName);

$isValid = $moduleConfigHelper->isActive($store);
$isValid = $moduleConfigHelper->isScopeActive($scope, $scopeId);

if ($isActivated && !$isValid) {
$moduleConfigHelper->deactivateModule($scope, $scopeId);
Expand Down

0 comments on commit 369cde9

Please sign in to comment.