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
*/
@@ -72,35 +85,46 @@ class Setup extends Template
72
85
private AdobeCloudConfigInterface $ adobeConfig ;
73
86
74
87
/**
75
- * @param Context $context
76
- * @param RequestInterface $request
77
- * @param FBEHelper $fbeHelper
78
- * @param SystemConfig $systemConfig
79
- * @param StoreRepositoryInterface $storeRepo
80
- * @param CommerceExtensionHelper $commerceExtensionHelper
81
- * @param ApiKeyService $apiKeyService
88
+ * @var ScopeConfigInterface
89
+ */
90
+ private ScopeConfigInterface $ scopeConfig ;
91
+
92
+ /**
93
+ * @param Context $context
94
+ * @param RequestInterface $request
95
+ * @param FBEHelper $fbeHelper
96
+ * @param SystemConfig $systemConfig
97
+ * @param StoreRepositoryInterface $storeRepo
98
+ * @param StoreManagerInterface $storeManager
99
+ * @param CommerceExtensionHelper $commerceExtensionHelper
100
+ * @param ApiKeyService $apiKeyService
82
101
* @param AdobeCloudConfigInterface $adobeConfig
83
- * @param array $data
102
+ * @param ScopeConfigInterface $scopeConfig
103
+ * @param array $data
84
104
*/
85
105
public function __construct (
86
106
Context $ context ,
87
107
RequestInterface $ request ,
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
}
@@ -173,7 +197,7 @@ public function getAAMSettingsRoute()
173
197
/**
174
198
* Fetch pixel id
175
199
*
176
- * @param int $storeId
200
+ * @param int $storeId
177
201
* @return string|null
178
202
*/
179
203
public function fetchPixelId ($ storeId )
@@ -215,7 +239,7 @@ public function getSplashPageURL()
215
239
/**
216
240
* Get external business id
217
241
*
218
- * @param int $storeId
242
+ * @param int $storeId
219
243
* @return string|null
220
244
*/
221
245
public function getExternalBusinessId ($ storeId )
@@ -287,18 +311,17 @@ 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
}
297
320
298
321
/**
299
322
* Is fbe installed
300
323
*
301
- * @param int $storeId
324
+ * @param int $storeId
302
325
* @return bool
303
326
*/
304
327
public function isFBEInstalled ($ storeId )
@@ -309,7 +332,7 @@ public function isFBEInstalled($storeId)
309
332
/**
310
333
* Get a URL to use to render the CommerceExtension IFrame for an onboarded Store.
311
334
*
312
- * @param int $storeId
335
+ * @param int $storeId
313
336
* @return string
314
337
*/
315
338
public function getCommerceExtensionIFrameURL ($ storeId )
@@ -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
}
@@ -338,10 +361,30 @@ public function getAppId()
338
361
return $ this ->systemConfig ->getAppId ();
339
362
}
340
363
364
+ /**
365
+ * Get client token
366
+ *
367
+ * @return string
368
+ */
369
+ public function getClientToken ()
370
+ {
371
+ return '52dcd04d6c7ed113121b5eb4be23b4a7 ' ;
372
+ }
373
+
374
+ /**
375
+ * Get access token
376
+ *
377
+ * @return string
378
+ */
379
+ public function getAccessClientToken ()
380
+ {
381
+ return $ this ->getAppId ().'| ' .$ this ->getClientToken ();
382
+ }
383
+
341
384
/**
342
385
* Get stores that are selectable (not Admin).
343
386
*
344
- * @return \Magento\Store\Api\Data\ StoreInterface[]
387
+ * @return StoreInterface[]
345
388
* */
346
389
public function getSelectableStores ()
347
390
{
@@ -353,6 +396,7 @@ public function getSelectableStores()
353
396
ARRAY_FILTER_USE_KEY ,
354
397
);
355
398
}
399
+
356
400
/**
357
401
* Get fbe installs config url endpoint
358
402
*
@@ -406,7 +450,7 @@ public function getWebsiteId()
406
450
/**
407
451
* Get default store_id
408
452
*
409
- * @return string
453
+ * @return int
410
454
*/
411
455
public function getDefaultStoreViewId ()
412
456
{
@@ -462,4 +506,51 @@ public function getUpdateMBEConfigAjaxRoute()
462
506
{
463
507
return $ this ->fbeHelper ->getUrl ('fbeadmin/ajax/MBEUpdateInstalledConfig ' );
464
508
}
509
+
510
+ /**
511
+ * Get Store's Timezone
512
+ *
513
+ * @return string
514
+ */
515
+ public function getStoreTimezone (): string
516
+ {
517
+ return $ this ->scopeConfig ->getValue (
518
+ self ::TIMEZONE_CONFIG_PATH ,
519
+ ScopeInterface::SCOPE_STORE
520
+ );
521
+ }
522
+
523
+ /**
524
+ * Get Store's Country Code
525
+ *
526
+ * @return string
527
+ */
528
+ public function getStoreCountryCode (): string
529
+ {
530
+ return $ this ->scopeConfig ->getValue (
531
+ self ::COUNTRY_CONFIG_PATH ,
532
+ ScopeInterface::SCOPE_STORE
533
+ );
534
+ }
535
+
536
+ /**
537
+ * Get Store's Base Url
538
+ *
539
+ * @return string
540
+ * @throws NoSuchEntityException
541
+ */
542
+ public function getStoreBaseUrl (): string
543
+ {
544
+ return $ this ->storeManager ->getStore ()->getBaseUrl (UrlInterface::URL_TYPE_WEB );
545
+ }
546
+
547
+ /**
548
+ * Get the extension version
549
+ *
550
+ * @return string
551
+ */
552
+ public function getExtensionVersion (): string
553
+ {
554
+ return $ this ->systemConfig ->getModuleVersion ();
555
+ }
465
556
}
0 commit comments