Skip to content

Commit 717d99b

Browse files
Bugfix: Use the store id of the quote
1 parent d80cc20 commit 717d99b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/Mollie_HyvaCheckout/Observer/SalesQuoteCollectTotalsBefore/SetDefaultSelectedPaymentMethod.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
use Magento\Quote\Api\PaymentMethodManagementInterface;
1919
use Magento\Quote\Model\Quote;
2020
use Magento\Store\Model\ScopeInterface;
21-
use Magento\Store\Model\StoreManagerInterface;
2221
use Mollie\Payment\Config;
2322

2423
class SetDefaultSelectedPaymentMethod implements ObserverInterface
2524
{
2625
private PaymentInterfaceFactory $paymentFactory;
2726
private Config $config;
28-
private StoreManagerInterface $storeManager;
2927
private ScopeConfigInterface $scopeConfig;
3028
private HyvaCheckoutConfig $hyvaCheckoutConfig;
3129
private PaymentMethodManagementInterface $paymentMethodManagement;
@@ -35,12 +33,10 @@ public function __construct(
3533
ScopeConfigInterface $scopeConfig,
3634
Config $config,
3735
PaymentInterfaceFactory $paymentFactory,
38-
StoreManagerInterface $storeManager,
3936
PaymentMethodManagementInterface $paymentMethodManagement
4037
) {
4138
$this->paymentFactory = $paymentFactory;
4239
$this->config = $config;
43-
$this->storeManager = $storeManager;
4440
$this->scopeConfig = $scopeConfig;
4541
$this->hyvaCheckoutConfig = $hyvaCheckoutConfig;
4642
$this->paymentMethodManagement = $paymentMethodManagement;
@@ -56,7 +52,8 @@ public function execute(Observer $observer): void
5652
return;
5753
}
5854

59-
$defaultMethod = $this->config->getDefaultSelectedMethod($this->storeManager->getStore()->getId());
55+
$storeId = (int)$quote->getStoreId();
56+
$defaultMethod = $this->config->getDefaultSelectedMethod($storeId);
6057
if (!$defaultMethod) {
6158
return;
6259
}
@@ -65,7 +62,7 @@ public function execute(Observer $observer): void
6562
$defaultMethod = $this->getFirstAvailableMollieMethod($quote);
6663
}
6764

68-
if ($defaultMethod && !$this->isMethodActive($defaultMethod)) {
65+
if ($defaultMethod && !$this->isMethodActive($defaultMethod, $storeId)) {
6966
return;
7067
}
7168

@@ -89,12 +86,12 @@ public function execute(Observer $observer): void
8986
/**
9087
* Check if that method is enabled for the current store
9188
*/
92-
private function isMethodActive(string $methodCode): bool
89+
private function isMethodActive(string $methodCode, int $storeId): bool
9390
{
9491
return $this->scopeConfig->isSetFlag(
9592
sprintf('payment/%s/active', $methodCode),
9693
ScopeInterface::SCOPE_STORE,
97-
$this->storeManager->getStore()->getCode()
94+
$storeId
9895
);
9996
}
10097

0 commit comments

Comments
 (0)