Skip to content

Commit 6cc34d0

Browse files
sujiezjczhuoMeta
andauthored
Adding the Platform Types Representing Seller Cloud Cohort to the Repair CPI API (#669)
* When MiCE overview page load and in MBE update cron job, call repair CPI endpoint to update the latest fields * Run CPI repair in MBE update cron job * add in the platform type into the repair API * Revert testing and debugging changes * rebase * rebase * fix static * strip off unrelated changes * rebased, modify as comment and re-test * restore unused files --------- Co-authored-by: Zhuo Chen <[email protected]>
1 parent caf6ad0 commit 6cc34d0

File tree

5 files changed

+59
-21
lines changed

5 files changed

+59
-21
lines changed

app/code/Meta/BusinessExtension/Api/AdobeCloudConfigInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ interface AdobeCloudConfigInterface
4343
* @return bool
4444
*/
4545
public function isSellerOnAdobeCloud(): bool;
46+
47+
/**
48+
* Call this method to get a string indicator on seller types (hosted by Adobe).
49+
*
50+
* @return string
51+
*/
52+
public function getCommercePartnerSellerPlatformType(): string;
4653
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ class Setup extends Template
9191
* @param array $data
9292
*/
9393
public function __construct(
94-
Context $context,
95-
RequestInterface $request,
96-
FBEHelper $fbeHelper,
97-
SystemConfig $systemConfig,
98-
StoreRepositoryInterface $storeRepo,
99-
WebsiteCollectionFactory $websiteCollectionFactory,
100-
CommerceExtensionHelper $commerceExtensionHelper,
101-
ApiKeyService $apiKeyService,
94+
Context $context,
95+
RequestInterface $request,
96+
FBEHelper $fbeHelper,
97+
SystemConfig $systemConfig,
98+
StoreRepositoryInterface $storeRepo,
99+
WebsiteCollectionFactory $websiteCollectionFactory,
100+
CommerceExtensionHelper $commerceExtensionHelper,
101+
ApiKeyService $apiKeyService,
102102
AdobeCloudConfigInterface $adobeConfig,
103-
array $data = []
103+
array $data = []
104104
) {
105105
$this->fbeHelper = $fbeHelper;
106106
parent::__construct($context, $data);
@@ -463,8 +463,7 @@ public function upsertApiKey()
463463
*/
464464
public function getCommercePartnerSellerPlatformType(): string
465465
{
466-
return $this->adobeConfig->isSellerOnAdobeCloud() ?
467-
AdobeCloudConfigInterface::ADOBE_COMMERCE_CLOUD : AdobeCloudConfigInterface::MAGENTO_OPEN_SOURCE;
466+
return $this->adobeConfig->getCommercePartnerSellerPlatformType();
468467
}
469468

470469
/**

app/code/Meta/BusinessExtension/Helper/GraphAPIAdapter.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,15 +1076,22 @@ public function getGraphApiVersion(): string
10761076
* @param string $shopDomain
10771077
* @param string $customToken
10781078
* @param string $accessToken
1079+
* @param string $seller_platform_type
10791080
* @throws GuzzleException
10801081
*/
1081-
public function repairCommercePartnerIntegration($externalBusinessId, $shopDomain, $customToken, $accessToken)
1082-
{
1082+
public function repairCommercePartnerIntegration(
1083+
$externalBusinessId,
1084+
$shopDomain,
1085+
$customToken,
1086+
$accessToken,
1087+
$seller_platform_type
1088+
) {
10831089
$request = [
10841090
'access_token' => $accessToken,
10851091
'fbe_external_business_id' => $externalBusinessId,
10861092
'custom_token' => $customToken,
1087-
'shop_domain' => $shopDomain
1093+
'shop_domain' => $shopDomain,
1094+
'commerce_partner_seller_platform_type' => $seller_platform_type
10881095
];
10891096
$response = $this->callApi('POST', "commerce_partner_integrations_repair", $request);
10901097
return json_decode($response->getBody()->__toString(), true);

app/code/Meta/BusinessExtension/Model/Api/AdobeCloudConfig.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ public function isSellerOnAdobeCloud(): bool
3535
// phpcs:ignore
3636
return isset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
3737
}
38+
39+
/**
40+
* Call this method to get a string indicator on seller types (hosted by Adobe).
41+
*
42+
* @return string
43+
*/
44+
public function getCommercePartnerSellerPlatformType(): string
45+
{
46+
return $this->isSellerOnAdobeCloud() ?
47+
AdobeCloudConfigInterface::ADOBE_COMMERCE_CLOUD : AdobeCloudConfigInterface::MAGENTO_OPEN_SOURCE;
48+
}
3849
}

app/code/Meta/BusinessExtension/Model/MBEInstalls.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
use Meta\BusinessExtension\Model\ResourceModel\FacebookInstalledFeature;
3232
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
3333
use Psr\Log\LoggerInterface;
34+
use Meta\BusinessExtension\Api\AdobeCloudConfigInterface;
3435

36+
/**
37+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
38+
*/
3539
class MBEInstalls
3640
{
3741
/**
@@ -71,6 +75,11 @@ class MBEInstalls
7175
*/
7276
private LoggerInterface $logger;
7377

78+
/**
79+
* @var AdobeCloudConfigInterface
80+
*/
81+
private AdobeCloudConfigInterface $adobeConfig;
82+
7483
/**
7584
* Construct
7685
*
@@ -82,16 +91,18 @@ class MBEInstalls
8291
* @param ApiKeyService $apiKeyService
8392
* @param StoreManagerInterface $storeManager
8493
* @param LoggerInterface $logger
94+
* @param AdobeCloudConfigInterface $adobeConfig
8595
*/
8696
public function __construct(
87-
FBEHelper $fbeHelper,
88-
SystemConfig $systemConfig,
89-
GraphAPIAdapter $graphApiAdapter,
90-
FacebookInstalledFeature $installedFeatureResource,
97+
FBEHelper $fbeHelper,
98+
SystemConfig $systemConfig,
99+
GraphAPIAdapter $graphApiAdapter,
100+
FacebookInstalledFeature $installedFeatureResource,
91101
CatalogConfigUpdateHelper $catalogConfigUpdateHelper,
92102
ApiKeyService $apiKeyService,
93103
StoreManagerInterface $storeManager,
94-
LoggerInterface $logger
104+
LoggerInterface $logger,
105+
AdobeCloudConfigInterface $adobeConfig
95106
) {
96107
$this->fbeHelper = $fbeHelper;
97108
$this->systemConfig = $systemConfig;
@@ -101,6 +112,7 @@ public function __construct(
101112
$this->apiKeyService = $apiKeyService;
102113
$this->storeManager = $storeManager;
103114
$this->logger = $logger;
115+
$this->adobeConfig = $adobeConfig;
104116
}
105117

106118
/**
@@ -125,7 +137,7 @@ public function save($response, $storeId)
125137

126138
// we will update catalog config if catalog has been updated in Meta
127139
$this->catalogConfigUpdateHelper->updateCatalogConfiguration(
128-
(int) $storeId,
140+
(int)$storeId,
129141
$catalogId,
130142
$commercePartnerIntegrationId,
131143
$pixelId,
@@ -329,12 +341,14 @@ public function repairCommercePartnerIntegration($storeId): bool
329341
$externalBusinessId = $this->systemConfig->getExternalBusinessId($storeId);
330342
$customToken = $this->apiKeyService->getCustomApiKey();
331343
$domain = $this->storeManager->getStore($storeId)->getBaseUrl();
344+
$seller_platform_type = $this->adobeConfig->getCommercePartnerSellerPlatformType();
332345

333346
$response = $this->graphApiAdapter->repairCommercePartnerIntegration(
334347
$externalBusinessId,
335348
$domain,
336349
$customToken,
337-
$accessToken
350+
$accessToken,
351+
$seller_platform_type
338352
);
339353
if ($response['success'] === true) {
340354
$integrationId = $response['id'];

0 commit comments

Comments
 (0)