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, ]); }