Skip to content

Commit 123cf77

Browse files
Catalog update script called in FBE installs response (#472)
* Catalog update script called in FBE installs response * Int type casted * comment updated
1 parent b8b7bf2 commit 123cf77

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ public function __construct(
6464
* @param string $catalogId
6565
* @param string $commercePartnerIntegrationId
6666
* @param string $pixelId
67+
* @param bool $triggerFullSync
6768
* @return void
6869
*/
6970
public function updateCatalogConfiguration(
7071
int $storeId,
7172
string $catalogId,
7273
string $commercePartnerIntegrationId,
73-
string $pixelId
74+
string $pixelId,
75+
bool $triggerFullSync = true,
7476
): void {
7577
$oldCatalogId = $this->systemConfig->getCatalogId($storeId);
7678
try {
79+
$isCatalogUpdated = $oldCatalogId != $catalogId;
80+
7781
// if Catalog id is updated, only then we update the config
78-
if ($oldCatalogId != $catalogId) {
82+
if ($isCatalogUpdated) {
7983
// updates catalog id
8084
$this->systemConfig->saveConfig(
8185
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_CATALOG_ID,
@@ -115,7 +119,9 @@ public function updateCatalogConfiguration(
115119
// Dispatch the facebook_update_catalog_configuration_after event,
116120
// so observers in other Meta modules can subscribe and trigger their syncs,
117121
// such as full catalog sync, and shipping profiles sync
118-
$this->eventManager->dispatch('facebook_update_catalog_configuration_after', ['store_id' => $storeId]);
122+
if ($triggerFullSync || $isCatalogUpdated) {
123+
$this->eventManager->dispatch('facebook_update_catalog_configuration_after', ['store_id' => $storeId]);
124+
}
119125
} catch (\Throwable $e) {
120126
$context = [
121127
'store_id' => $storeId,

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use GuzzleHttp\Exception\GuzzleException;
2424
use Magento\Framework\Exception\LocalizedException;
2525
use Magento\Store\Model\ScopeInterface;
26+
use Meta\BusinessExtension\Helper\CatalogConfigUpdateHelper;
2627
use Meta\BusinessExtension\Helper\FBEHelper;
2728
use Meta\BusinessExtension\Helper\GraphAPIAdapter;
2829
use Meta\BusinessExtension\Model\ResourceModel\FacebookInstalledFeature;
@@ -50,24 +51,32 @@ class SaveFBEInstallsResponse
5051
*/
5152
private $installedFeatureResource;
5253

54+
/**
55+
* @var CatalogConfigUpdateHelper
56+
*/
57+
private CatalogConfigUpdateHelper $catalogConfigUpdateHelper;
58+
5359
/**
5460
* Construct
5561
*
5662
* @param FBEHelper $fbeHelper
5763
* @param SystemConfig $systemConfig
5864
* @param GraphAPIAdapter $graphApiAdapter
5965
* @param FacebookInstalledFeature $installedFeatureResource
66+
* @param CatalogConfigUpdateHelper $catalogConfigUpdateHelper
6067
*/
6168
public function __construct(
6269
FBEHelper $fbeHelper,
6370
SystemConfig $systemConfig,
6471
GraphAPIAdapter $graphApiAdapter,
65-
FacebookInstalledFeature $installedFeatureResource
72+
FacebookInstalledFeature $installedFeatureResource,
73+
CatalogConfigUpdateHelper $catalogConfigUpdateHelper
6674
) {
6775
$this->fbeHelper = $fbeHelper;
6876
$this->systemConfig = $systemConfig;
6977
$this->graphApiAdapter = $graphApiAdapter;
7078
$this->installedFeatureResource = $installedFeatureResource;
79+
$this->catalogConfigUpdateHelper = $catalogConfigUpdateHelper;
7180
}
7281

7382
/**
@@ -86,15 +95,24 @@ public function save($response, $storeId)
8695
return false;
8796
}
8897
$data = $response[0];
98+
$catalogId = $data['catalog_id'] ?? '';
99+
$pixelId = $data['pixel_id'] ?? '';
100+
$commercePartnerIntegrationId = $data['commerce_partner_integration_id'] ?? '';
101+
102+
// we will update catalog config if catalog has been updated in Meta
103+
$this->catalogConfigUpdateHelper->updateCatalogConfiguration(
104+
(int) $storeId,
105+
$catalogId,
106+
$commercePartnerIntegrationId,
107+
$pixelId,
108+
false
109+
);
89110

90-
$this->savePixelId($data['pixel_id'] ?? '', $storeId);
111+
$this->savePixelId($pixelId, $storeId);
91112
$this->saveProfiles($data['profiles'] ?? '', $storeId);
92113
$this->savePages($data['pages'] ?? '', $storeId);
93-
$this->saveCatalogId($data['catalog_id'] ?? '', $storeId);
94-
$this->saveCommercePartnerIntegrationId(
95-
$data['commerce_partner_integration_id'] ?? '',
96-
$storeId
97-
);
114+
$this->saveCatalogId($catalogId, $storeId);
115+
$this->saveCommercePartnerIntegrationId($commercePartnerIntegrationId, $storeId);
98116
$this->saveMerchantSettingsId($data['commerce_merchant_settings_id'] ?? '', $storeId);
99117
$this->saveInstalledFeatures($data['installed_features'] ?? '', $storeId);
100118
$this->systemConfig->cleanCache();

0 commit comments

Comments
 (0)