Skip to content

Commit 045290d

Browse files
authored
Adding Shop info into Splash page's path paramters (#813)
* 1. Update the time zone with fetching the real timezone instead of hard coded 2. Get country code for the store and pass it into splash page * fix format: countryCode->country_code * Pipe in extension version and store URL * 1. Formatting the file to address linter 2. Remove unused method * 1. Formatting the file to address linter 2. Remove unused method * 1. Fix test file * Address code review comment * Cleanup linter wrong cleanup
1 parent 8d719c4 commit 045290d

File tree

5 files changed

+105
-14
lines changed

5 files changed

+105
-14
lines changed

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

Lines changed: 78 additions & 8 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
*/
@@ -71,15 +84,22 @@ class Setup extends Template
7184
*/
7285
private AdobeCloudConfigInterface $adobeConfig;
7386

87+
/**
88+
* @var ScopeConfigInterface
89+
*/
90+
private ScopeConfigInterface $scopeConfig;
91+
7492
/**
7593
* @param Context $context
7694
* @param RequestInterface $request
7795
* @param FBEHelper $fbeHelper
7896
* @param SystemConfig $systemConfig
7997
* @param StoreRepositoryInterface $storeRepo
98+
* @param StoreManagerInterface $storeManager
8099
* @param CommerceExtensionHelper $commerceExtensionHelper
81100
* @param ApiKeyService $apiKeyService
82101
* @param AdobeCloudConfigInterface $adobeConfig
102+
* @param ScopeConfigInterface $scopeConfig
83103
* @param array $data
84104
*/
85105
public function __construct(
@@ -88,19 +108,23 @@ public function __construct(
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
}
@@ -287,10 +311,9 @@ 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
}
@@ -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
}
@@ -341,7 +364,7 @@ public function getAppId()
341364
/**
342365
* Get stores that are selectable (not Admin).
343366
*
344-
* @return \Magento\Store\Api\Data\StoreInterface[]
367+
* @return StoreInterface[]
345368
* */
346369
public function getSelectableStores()
347370
{
@@ -462,4 +485,51 @@ public function getUpdateMBEConfigAjaxRoute()
462485
{
463486
return $this->fbeHelper->getUrl('fbeadmin/ajax/MBEUpdateInstalledConfig');
464487
}
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+
}
465535
}

app/code/Meta/BusinessExtension/Test/Unit/Block/Adminhtml/SetupTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Meta\BusinessExtension\Test\Unit\Block\Adminhtml;
44

55
use Magento\Backend\Block\Template\Context;
6+
use Magento\Framework\App\Config\ScopeConfigInterface;
67
use Magento\Framework\App\RequestInterface;
78
use Magento\Store\Api\StoreRepositoryInterface;
9+
use Magento\Store\Model\StoreManagerInterface;
810
use Meta\BusinessExtension\Api\AdobeCloudConfigInterface;
911
use Meta\BusinessExtension\Block\Adminhtml\Setup;
1012
use Meta\BusinessExtension\Helper\CommerceExtensionHelper;
@@ -35,6 +37,10 @@ public function testGetApiKey()
3537
->disableOriginalConstructor()
3638
->getMock();
3739

40+
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)
41+
->disableOriginalConstructor()
42+
->getMock();
43+
3844
$requestInterface = $this->getMockBuilder(RequestInterface::class)
3945
->disableOriginalConstructor()
4046
->getMock();
@@ -47,22 +53,28 @@ public function testGetApiKey()
4753
->disableOriginalConstructor()
4854
->getMock();
4955

50-
$apiKeyService->method('upsertApiKey')
51-
->willReturn($apiKey);
52-
5356
$adobeCloudConfigInterface = $this->getMockBuilder(AdobeCloudConfigInterface::class)
5457
->disableOriginalConstructor()
5558
->getMock();
5659

60+
$scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
61+
->disableOriginalConstructor()
62+
->getMock();
63+
64+
$apiKeyService->method('upsertApiKey')
65+
->willReturn($apiKey);
66+
5767
$setup = new Setup(
5868
$context,
5969
$requestInterface,
6070
$fbeHelper,
6171
$systemConfig,
6272
$storeRepo,
73+
$storeManager,
6374
$commerceExtensionHelper,
6475
$apiKeyService,
6576
$adobeCloudConfigInterface,
77+
$scopeConfig,
6678
[]
6779
);
6880

app/code/Meta/BusinessExtension/view/adminhtml/templates/setup.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
setPixelId: '<?= $escaper->escapeHtml($block->getPixelAjaxRoute()) ?>',
6464
setProfilesData: '<?= $escaper->escapeHtml($block->getProfilesAjaxRoute()) ?>',
6565
storeId: '<?= $escaper->escapeHtml($block->getSelectedStoreId()) ?>',
66-
timeZone: 'America/Los_Angeles'
66+
timeZone: '<?= $escaper->escapeHtml($block->getStoreTimezone()) ?>',
67+
countryCode: '<?= $escaper->escapeHtml($block->getStoreCountryCode()) ?>',
68+
shopDomain: '<?= $escaper->escapeHtml($block->getStoreBaseUrl()) ?>',
69+
extensionVersion: '<?= $escaper->escapeHtml($block->getExtensionVersion()) ?>',
6770
}
6871
</script>
6972
<?php if ($block->isCommerceExtensionEnabled() && $block->isFBEInstalled($block->getSelectedStoreId())): ?>

app/code/Meta/BusinessExtension/view/adminhtml/web/js/fbe_allinone.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ const ajaxify = function (url) {
3434
const getAndEncodeExternalClientMetadata = function () {
3535
const metaData = {
3636
customer_token: window.facebookBusinessExtensionConfig.customApiKey,
37-
commerce_partner_seller_platform_type: window.facebookBusinessExtensionConfig.commerce_partner_seller_platform_type
37+
commerce_partner_seller_platform_type: window.facebookBusinessExtensionConfig.commerce_partner_seller_platform_type,
38+
shop_domain: window.facebookBusinessExtensionConfig.shopDomain,
39+
country_code: window.facebookBusinessExtensionConfig.countryCode,
40+
client_version: window.facebookBusinessExtensionConfig.extensionVersion
3841
};
3942
return encodeURIComponent(JSON.stringify(metaData));
4043
}

app/code/Meta/BusinessExtension/view/adminhtml/web/js/lib/fbe.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ const ajaxify = function (url) {
3333
const getAndEncodeExternalClientMetadata = function () {
3434
const metaData = {
3535
customer_token: window.facebookBusinessExtensionConfig.customApiKey,
36-
commerce_partner_seller_platform_type: window.facebookBusinessExtensionConfig.commerce_partner_seller_platform_type
36+
commerce_partner_seller_platform_type: window.facebookBusinessExtensionConfig.commerce_partner_seller_platform_type,
37+
shop_domain: window.facebookBusinessExtensionConfig.shopDomain,
38+
country_code: window.facebookBusinessExtensionConfig.countryCode,
39+
client_version: window.facebookBusinessExtensionConfig.extensionVersion
3740
};
3841
return encodeURIComponent(JSON.stringify(metaData));
3942
}

0 commit comments

Comments
 (0)