18
18
use Magento \Quote \Api \PaymentMethodManagementInterface ;
19
19
use Magento \Quote \Model \Quote ;
20
20
use Magento \Store \Model \ScopeInterface ;
21
- use Magento \Store \Model \StoreManagerInterface ;
22
21
use Mollie \Payment \Config ;
23
22
24
23
class SetDefaultSelectedPaymentMethod implements ObserverInterface
25
24
{
26
25
private PaymentInterfaceFactory $ paymentFactory ;
27
26
private Config $ config ;
28
- private StoreManagerInterface $ storeManager ;
29
27
private ScopeConfigInterface $ scopeConfig ;
30
28
private HyvaCheckoutConfig $ hyvaCheckoutConfig ;
31
29
private PaymentMethodManagementInterface $ paymentMethodManagement ;
@@ -35,12 +33,10 @@ public function __construct(
35
33
ScopeConfigInterface $ scopeConfig ,
36
34
Config $ config ,
37
35
PaymentInterfaceFactory $ paymentFactory ,
38
- StoreManagerInterface $ storeManager ,
39
36
PaymentMethodManagementInterface $ paymentMethodManagement
40
37
) {
41
38
$ this ->paymentFactory = $ paymentFactory ;
42
39
$ this ->config = $ config ;
43
- $ this ->storeManager = $ storeManager ;
44
40
$ this ->scopeConfig = $ scopeConfig ;
45
41
$ this ->hyvaCheckoutConfig = $ hyvaCheckoutConfig ;
46
42
$ this ->paymentMethodManagement = $ paymentMethodManagement ;
@@ -56,7 +52,8 @@ public function execute(Observer $observer): void
56
52
return ;
57
53
}
58
54
59
- $ defaultMethod = $ this ->config ->getDefaultSelectedMethod ($ this ->storeManager ->getStore ()->getId ());
55
+ $ storeId = (int )$ quote ->getStoreId ();
56
+ $ defaultMethod = $ this ->config ->getDefaultSelectedMethod ($ storeId );
60
57
if (!$ defaultMethod ) {
61
58
return ;
62
59
}
@@ -65,7 +62,7 @@ public function execute(Observer $observer): void
65
62
$ defaultMethod = $ this ->getFirstAvailableMollieMethod ($ quote );
66
63
}
67
64
68
- if ($ defaultMethod && !$ this ->isMethodActive ($ defaultMethod )) {
65
+ if ($ defaultMethod && !$ this ->isMethodActive ($ defaultMethod, $ storeId )) {
69
66
return ;
70
67
}
71
68
@@ -89,12 +86,12 @@ public function execute(Observer $observer): void
89
86
/**
90
87
* Check if that method is enabled for the current store
91
88
*/
92
- private function isMethodActive (string $ methodCode ): bool
89
+ private function isMethodActive (string $ methodCode, int $ storeId ): bool
93
90
{
94
91
return $ this ->scopeConfig ->isSetFlag (
95
92
sprintf ('payment/%s/active ' , $ methodCode ),
96
93
ScopeInterface::SCOPE_STORE ,
97
- $ this -> storeManager -> getStore ()-> getCode ()
94
+ $ storeId
98
95
);
99
96
}
100
97
0 commit comments