Skip to content

Commit f50e76b

Browse files
authored
Merge pull request #201 from magento-commerce/main
Sync meta main >>> sd release/1.3.5
2 parents 416dc28 + 5109ac4 commit f50e76b

File tree

9 files changed

+431
-251
lines changed

9 files changed

+431
-251
lines changed

app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php

Lines changed: 112 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,27 @@
2424
use Magento\Backend\Block\Template\Context;
2525
use Magento\Framework\App\RequestInterface;
2626
use Magento\Framework\Exception\NoSuchEntityException;
27+
use Magento\Framework\UrlInterface;
28+
use Magento\Store\Api\Data\StoreInterface;
2729
use Magento\Store\Api\StoreRepositoryInterface;
30+
use Magento\Store\Model\StoreManagerInterface;
2831
use Meta\BusinessExtension\Api\AdobeCloudConfigInterface;
2932
use Meta\BusinessExtension\Helper\CommerceExtensionHelper;
3033
use Meta\BusinessExtension\Helper\FBEHelper;
3134
use Meta\BusinessExtension\Model\Api\CustomApiKey\ApiKeyService;
3235
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
36+
use Magento\Framework\App\Config\ScopeConfigInterface;
37+
use Magento\Store\Model\ScopeInterface;
3338

3439
/**
3540
* @api
3641
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3742
*/
3843
class Setup extends Template
3944
{
45+
public const COUNTRY_CONFIG_PATH = 'general/country/default';
46+
public const TIMEZONE_CONFIG_PATH = 'general/locale/timezone';
47+
4048
/**
4149
* @var ApiKeyService
4250
*/
@@ -61,6 +69,11 @@ class Setup extends Template
6169
*/
6270
public StoreRepositoryInterface $storeRepo;
6371

72+
/**
73+
* @var StoreManagerInterface
74+
*/
75+
private StoreManagerInterface $storeManager;
76+
6477
/**
6578
* @var CommerceExtensionHelper
6679
*/
@@ -72,35 +85,46 @@ class Setup extends Template
7285
private AdobeCloudConfigInterface $adobeConfig;
7386

7487
/**
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
82101
* @param AdobeCloudConfigInterface $adobeConfig
83-
* @param array $data
102+
* @param ScopeConfigInterface $scopeConfig
103+
* @param array $data
84104
*/
85105
public function __construct(
86106
Context $context,
87107
RequestInterface $request,
88108
FBEHelper $fbeHelper,
89109
SystemConfig $systemConfig,
90110
StoreRepositoryInterface $storeRepo,
111+
StoreManagerInterface $storeManager,
91112
CommerceExtensionHelper $commerceExtensionHelper,
92113
ApiKeyService $apiKeyService,
93114
AdobeCloudConfigInterface $adobeConfig,
115+
ScopeConfigInterface $scopeConfig,
94116
array $data = []
95117
) {
96118
$this->fbeHelper = $fbeHelper;
97119
parent::__construct($context, $data);
98120
$this->request = $request;
99121
$this->systemConfig = $systemConfig;
100122
$this->storeRepo = $storeRepo;
123+
$this->storeManager = $storeManager;
101124
$this->commerceExtensionHelper = $commerceExtensionHelper;
102125
$this->apiKeyService = $apiKeyService;
103126
$this->adobeConfig = $adobeConfig;
127+
$this->scopeConfig = $scopeConfig;
104128
}
105129

106130
/**
@@ -121,7 +145,7 @@ public function getSelectedStoreId(): ?int
121145
try {
122146
$this->storeRepo->getById($requestStoreId);
123147
return $requestStoreId;
124-
} catch (NoSuchEntityException $_ex) {
148+
} catch (NoSuchEntityException) {
125149
$this->fbeHelper->log("Store with requestStoreId $requestStoreId not found");
126150
}
127151
}
@@ -173,7 +197,7 @@ public function getAAMSettingsRoute()
173197
/**
174198
* Fetch pixel id
175199
*
176-
* @param int $storeId
200+
* @param int $storeId
177201
* @return string|null
178202
*/
179203
public function fetchPixelId($storeId)
@@ -215,7 +239,7 @@ public function getSplashPageURL()
215239
/**
216240
* Get external business id
217241
*
218-
* @param int $storeId
242+
* @param int $storeId
219243
* @return string|null
220244
*/
221245
public function getExternalBusinessId($storeId)
@@ -287,18 +311,17 @@ public function getDeleteAssetIdsAjaxRoute()
287311
/**
288312
* Get currency code
289313
*
290-
* @return mixed
291-
* @throws \Magento\Framework\Exception\NoSuchEntityException
314+
* @return null|string
292315
*/
293-
public function getCurrencyCode()
316+
public function getCurrencyCode(): ?string
294317
{
295318
return $this->fbeHelper->getStoreCurrencyCode();
296319
}
297320

298321
/**
299322
* Is fbe installed
300323
*
301-
* @param int $storeId
324+
* @param int $storeId
302325
* @return bool
303326
*/
304327
public function isFBEInstalled($storeId)
@@ -309,7 +332,7 @@ public function isFBEInstalled($storeId)
309332
/**
310333
* Get a URL to use to render the CommerceExtension IFrame for an onboarded Store.
311334
*
312-
* @param int $storeId
335+
* @param int $storeId
313336
* @return string
314337
*/
315338
public function getCommerceExtensionIFrameURL($storeId)
@@ -320,10 +343,10 @@ public function getCommerceExtensionIFrameURL($storeId)
320343
/**
321344
* Get a URL to use to render the CommerceExtension IFrame for an onboarded Store.
322345
*
323-
* @param int $storeId
324-
* @return string
346+
* @param int $storeId
347+
* @return bool
325348
*/
326-
public function hasCommerceExtensionIFramePermissionError($storeId)
349+
public function hasCommerceExtensionIFramePermissionError(int $storeId): bool
327350
{
328351
return $this->commerceExtensionHelper->hasCommerceExtensionPermissionError($storeId);
329352
}
@@ -338,10 +361,30 @@ public function getAppId()
338361
return $this->systemConfig->getAppId();
339362
}
340363

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+
341384
/**
342385
* Get stores that are selectable (not Admin).
343386
*
344-
* @return \Magento\Store\Api\Data\StoreInterface[]
387+
* @return StoreInterface[]
345388
* */
346389
public function getSelectableStores()
347390
{
@@ -353,6 +396,7 @@ public function getSelectableStores()
353396
ARRAY_FILTER_USE_KEY,
354397
);
355398
}
399+
356400
/**
357401
* Get fbe installs config url endpoint
358402
*
@@ -406,7 +450,7 @@ public function getWebsiteId()
406450
/**
407451
* Get default store_id
408452
*
409-
* @return string
453+
* @return int
410454
*/
411455
public function getDefaultStoreViewId()
412456
{
@@ -462,4 +506,51 @@ public function getUpdateMBEConfigAjaxRoute()
462506
{
463507
return $this->fbeHelper->getUrl('fbeadmin/ajax/MBEUpdateInstalledConfig');
464508
}
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+
}
465556
}

0 commit comments

Comments
 (0)