From c100f2d577c1f3e7245ceccf8334fa4fe5830bff Mon Sep 17 00:00:00 2001 From: singhramanpreett <129768663+singhramanpreett@users.noreply.github.com> Date: Wed, 6 Sep 2023 01:04:40 +0530 Subject: [PATCH] Catalog sync enabled for commerce partner integration id (#417) * Catalog sync enabled for commerce partner integration id * Catalog sync enable flag moved to separate function * equality checks updated * Static issue resolved --- .../Adminhtml/Ajax/PersistConfiguration.php | 24 ++++++++++++++++++- .../Setup/Patch/Data/AddCatalogSwitch.php | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/PersistConfiguration.php b/app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/PersistConfiguration.php index 96fd269a..30b85671 100644 --- a/app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/PersistConfiguration.php +++ b/app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/PersistConfiguration.php @@ -86,7 +86,8 @@ public function executeForJson() ->saveCatalogId($catalogId, $storeId) ->saveCommercePartnerIntegrationId($commercePartnerIntegrationId, $storeId) ->saveInstalledFlag($storeId) - ->completeOnsiteOnboarding($accessToken, $pageId, $storeId); + ->completeOnsiteOnboarding($accessToken, $pageId, $storeId) + ->enableCatalogSync($commercePartnerIntegrationId, $storeId); $response['success'] = true; $response['message'] = 'Configuration successfully saved'; @@ -147,6 +148,27 @@ public function saveCommercePartnerIntegrationId($commercePartnerIntegrationId, return $this; } + /** + * Based on commerce PI presence it enables catalog sync. + * + * @param int $commercePartnerIntegrationId + * @param int $storeId + * @return $this + */ + public function enableCatalogSync($commercePartnerIntegrationId, $storeId) + { + if ($commercePartnerIntegrationId) { + $this->fbeHelper->log(sprintf('Catalog sync is enabled for store %s', $storeId)); + + $this->systemConfig->saveConfig( + SystemConfig::XML_PATH_FACEBOOK_ENABLE_CATALOG_SYNC, + true, + $storeId + ); + } + return $this; + } + /** * Save external business id * diff --git a/app/code/Meta/Catalog/Setup/Patch/Data/AddCatalogSwitch.php b/app/code/Meta/Catalog/Setup/Patch/Data/AddCatalogSwitch.php index 3b1519eb..045865eb 100644 --- a/app/code/Meta/Catalog/Setup/Patch/Data/AddCatalogSwitch.php +++ b/app/code/Meta/Catalog/Setup/Patch/Data/AddCatalogSwitch.php @@ -101,12 +101,12 @@ private function updateStoreCatalogIntegration($storeId): void 'facebook/catalog_management/out_of_stock_threshold' ); - if ($isCatalogSyncEnabled == null) { + if ($isCatalogSyncEnabled === null && $isDailyFeedSyncEnabled !== null) { $connection->insert($coreConfigTable, [ 'scope' => $storeId ? 'stores' : 'default', 'scope_id' => $storeId, 'path' => SystemConfig::XML_PATH_FACEBOOK_ENABLE_CATALOG_SYNC, - 'value' => $isDailyFeedSyncEnabled === null ? true : $isDailyFeedSyncEnabled, + 'value' => $isDailyFeedSyncEnabled, ]); }