24
24
use Magento \Backend \Block \Template \Context ;
25
25
use Magento \Framework \App \RequestInterface ;
26
26
use Magento \Framework \Exception \NoSuchEntityException ;
27
+ use Magento \Framework \UrlInterface ;
28
+ use Magento \Store \Api \Data \StoreInterface ;
27
29
use Magento \Store \Api \StoreRepositoryInterface ;
30
+ use Magento \Store \Model \StoreManagerInterface ;
28
31
use Meta \BusinessExtension \Api \AdobeCloudConfigInterface ;
29
32
use Meta \BusinessExtension \Helper \CommerceExtensionHelper ;
30
33
use Meta \BusinessExtension \Helper \FBEHelper ;
31
34
use Meta \BusinessExtension \Model \Api \CustomApiKey \ApiKeyService ;
32
35
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
36
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
37
+ use Magento \Store \Model \ScopeInterface ;
33
38
34
39
/**
35
40
* @api
36
41
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
37
42
*/
38
43
class Setup extends Template
39
44
{
45
+ public const COUNTRY_CONFIG_PATH = 'general/country/default ' ;
46
+ public const TIMEZONE_CONFIG_PATH = 'general/locale/timezone ' ;
47
+
40
48
/**
41
49
* @var ApiKeyService
42
50
*/
@@ -61,6 +69,11 @@ class Setup extends Template
61
69
*/
62
70
public StoreRepositoryInterface $ storeRepo ;
63
71
72
+ /**
73
+ * @var StoreManagerInterface
74
+ */
75
+ private StoreManagerInterface $ storeManager ;
76
+
64
77
/**
65
78
* @var CommerceExtensionHelper
66
79
*/
@@ -71,15 +84,22 @@ class Setup extends Template
71
84
*/
72
85
private AdobeCloudConfigInterface $ adobeConfig ;
73
86
87
+ /**
88
+ * @var ScopeConfigInterface
89
+ */
90
+ private ScopeConfigInterface $ scopeConfig ;
91
+
74
92
/**
75
93
* @param Context $context
76
94
* @param RequestInterface $request
77
95
* @param FBEHelper $fbeHelper
78
96
* @param SystemConfig $systemConfig
79
97
* @param StoreRepositoryInterface $storeRepo
98
+ * @param StoreManagerInterface $storeManager
80
99
* @param CommerceExtensionHelper $commerceExtensionHelper
81
100
* @param ApiKeyService $apiKeyService
82
101
* @param AdobeCloudConfigInterface $adobeConfig
102
+ * @param ScopeConfigInterface $scopeConfig
83
103
* @param array $data
84
104
*/
85
105
public function __construct (
@@ -88,19 +108,23 @@ public function __construct(
88
108
FBEHelper $ fbeHelper ,
89
109
SystemConfig $ systemConfig ,
90
110
StoreRepositoryInterface $ storeRepo ,
111
+ StoreManagerInterface $ storeManager ,
91
112
CommerceExtensionHelper $ commerceExtensionHelper ,
92
113
ApiKeyService $ apiKeyService ,
93
114
AdobeCloudConfigInterface $ adobeConfig ,
115
+ ScopeConfigInterface $ scopeConfig ,
94
116
array $ data = []
95
117
) {
96
118
$ this ->fbeHelper = $ fbeHelper ;
97
119
parent ::__construct ($ context , $ data );
98
120
$ this ->request = $ request ;
99
121
$ this ->systemConfig = $ systemConfig ;
100
122
$ this ->storeRepo = $ storeRepo ;
123
+ $ this ->storeManager = $ storeManager ;
101
124
$ this ->commerceExtensionHelper = $ commerceExtensionHelper ;
102
125
$ this ->apiKeyService = $ apiKeyService ;
103
126
$ this ->adobeConfig = $ adobeConfig ;
127
+ $ this ->scopeConfig = $ scopeConfig ;
104
128
}
105
129
106
130
/**
@@ -121,7 +145,7 @@ public function getSelectedStoreId(): ?int
121
145
try {
122
146
$ this ->storeRepo ->getById ($ requestStoreId );
123
147
return $ requestStoreId ;
124
- } catch (NoSuchEntityException $ _ex ) {
148
+ } catch (NoSuchEntityException ) {
125
149
$ this ->fbeHelper ->log ("Store with requestStoreId $ requestStoreId not found " );
126
150
}
127
151
}
@@ -287,10 +311,9 @@ public function getDeleteAssetIdsAjaxRoute()
287
311
/**
288
312
* Get currency code
289
313
*
290
- * @return mixed
291
- * @throws \Magento\Framework\Exception\NoSuchEntityException
314
+ * @return null|string
292
315
*/
293
- public function getCurrencyCode ()
316
+ public function getCurrencyCode (): ? string
294
317
{
295
318
return $ this ->fbeHelper ->getStoreCurrencyCode ();
296
319
}
@@ -320,10 +343,10 @@ public function getCommerceExtensionIFrameURL($storeId)
320
343
/**
321
344
* Get a URL to use to render the CommerceExtension IFrame for an onboarded Store.
322
345
*
323
- * @param int $storeId
324
- * @return string
346
+ * @param int $storeId
347
+ * @return bool
325
348
*/
326
- public function hasCommerceExtensionIFramePermissionError ($ storeId )
349
+ public function hasCommerceExtensionIFramePermissionError (int $ storeId ): bool
327
350
{
328
351
return $ this ->commerceExtensionHelper ->hasCommerceExtensionPermissionError ($ storeId );
329
352
}
@@ -341,7 +364,7 @@ public function getAppId()
341
364
/**
342
365
* Get stores that are selectable (not Admin).
343
366
*
344
- * @return \Magento\Store\Api\Data\ StoreInterface[]
367
+ * @return StoreInterface[]
345
368
* */
346
369
public function getSelectableStores ()
347
370
{
@@ -462,4 +485,51 @@ public function getUpdateMBEConfigAjaxRoute()
462
485
{
463
486
return $ this ->fbeHelper ->getUrl ('fbeadmin/ajax/MBEUpdateInstalledConfig ' );
464
487
}
488
+
489
+ /**
490
+ * Get Store's Timezone
491
+ *
492
+ * @return string
493
+ */
494
+ public function getStoreTimezone (): string
495
+ {
496
+ return $ this ->scopeConfig ->getValue (
497
+ self ::TIMEZONE_CONFIG_PATH ,
498
+ ScopeInterface::SCOPE_STORE
499
+ );
500
+ }
501
+
502
+ /**
503
+ * Get Store's Country Code
504
+ *
505
+ * @return string
506
+ */
507
+ public function getStoreCountryCode (): string
508
+ {
509
+ return $ this ->scopeConfig ->getValue (
510
+ self ::COUNTRY_CONFIG_PATH ,
511
+ ScopeInterface::SCOPE_STORE
512
+ );
513
+ }
514
+
515
+ /**
516
+ * Get Store's Base Url
517
+ *
518
+ * @return string
519
+ * @throws NoSuchEntityException
520
+ */
521
+ public function getStoreBaseUrl (): string
522
+ {
523
+ return $ this ->storeManager ->getStore ()->getBaseUrl (UrlInterface::URL_TYPE_WEB );
524
+ }
525
+
526
+ /**
527
+ * Get the extension version
528
+ *
529
+ * @return string
530
+ */
531
+ public function getExtensionVersion (): string
532
+ {
533
+ return $ this ->systemConfig ->getModuleVersion ();
534
+ }
465
535
}
0 commit comments