Skip to content

Commit

Permalink
check is on site channels available
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jun 20, 2024
1 parent 2a4fc12 commit 25734c6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Model/MethodListPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ public function afterGetAvailableMethods(MethodList $compiled, $result)
return $result;
}

$onsiteChannels = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORE);
$channelList = $onsiteChannels ? explode(',', $onsiteChannels) : [];
$channels = $this->transactions->channels();
$conutryId = $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId();
$countryId = $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId();
[$channelList, $channels] = $this->getChannels();

if ($conutryId && $this->constraintValidator->isClientCountryValid($this->tpayConfig->isAllowSpecific(), $conutryId, $this->tpayConfig->getSpecificCountry())) {
if ($countryId && $this->constraintValidator->isClientCountryValid($this->tpayConfig->isAllowSpecific(), $countryId, $this->tpayConfig->getSpecificCountry())) {
return [];
}

Expand Down Expand Up @@ -146,4 +144,18 @@ private function filterTransaction(array $result): array
return 'Tpay_Magento2' !== $method->getCode();
});
}

private function getChannels(): array
{
$onsiteChannels = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORE);
$channelList = $onsiteChannels ? explode(',', $onsiteChannels) : [];
$channels = $this->transactions->channels();

$flippedChannels = array_flip(array_keys($channels));
$channelList = array_filter($channelList, function ($value) use ($flippedChannels) {
return isset($flippedChannels[$value]);
});

return [$channelList, $channels];
}
}

0 comments on commit 25734c6

Please sign in to comment.