-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catalog config update script after one catalog decision (#426)
* Product set ids cleared while uninstalling integration * Cyclic module removed * Post FBE onboarding Catalog sync triggered * Added ajx call to trigger all products and category upload after MBE onboarding flow * Unused config removed * Post one catalog migration flow catalog update script added * Commerce sync flag updated * Typo fixed * Static errors fixed * Catalog sync enabled for commerce partner integration id * static errors fixed * PR comments fixed * exceptions being caught * Catalog config update script added * Redundant code removed * Shipping profile sync disabled based on meta commerce sync disabled flag * phpdocs added * static errors resolved * Unit test passed * unit tests fixed * Catalog code moved to catalog module * Do not call comment added for script * Commerce sync disable code removed * Extra line removed * events updated --------- Co-authored-by: Alex Zarichnyi <zlik@fb.com>
- Loading branch information
1 parent
c873aff
commit a58e1d7
Showing
10 changed files
with
303 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
app/code/Meta/BusinessExtension/Helper/CatalogConfigUpdateHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Meta\BusinessExtension\Helper; | ||
|
||
use Magento\Framework\Event\ManagerInterface as EventManager; | ||
use Meta\BusinessExtension\Model\System\Config as SystemConfig; | ||
|
||
class CatalogConfigUpdateHelper | ||
{ | ||
/** | ||
* @var FBEHelper | ||
*/ | ||
private FBEHelper $fbeHelper; | ||
|
||
/** | ||
* @var SystemConfig | ||
*/ | ||
private SystemConfig $systemConfig; | ||
|
||
/** | ||
* @var EventManager | ||
*/ | ||
private EventManager $eventManager; | ||
|
||
/** | ||
* @param FBEHelper $fbeHelper | ||
* @param SystemConfig $systemConfig | ||
* @param EventManager $eventManager | ||
*/ | ||
public function __construct( | ||
FBEHelper $fbeHelper, | ||
SystemConfig $systemConfig, | ||
EventManager $eventManager | ||
) { | ||
$this->fbeHelper = $fbeHelper; | ||
$this->systemConfig = $systemConfig; | ||
$this->eventManager = $eventManager; | ||
} | ||
|
||
/** | ||
* Function updates catalog config if updated on Meta side after onboarding flow completion on Meta side. | ||
* Function enables Meta Commerce Sync and do full catalog sync. | ||
* Do not call it apart from catalog update webhook event, it may cause stale state for catalog integration. | ||
* | ||
* @param int $storeId | ||
* @param string $catalogId | ||
* @param string $commercePartnerIntegrationId | ||
* @param string $pixelId | ||
* @return void | ||
*/ | ||
public function updateCatalogConfiguration( | ||
int $storeId, | ||
string $catalogId, | ||
string $commercePartnerIntegrationId, | ||
string $pixelId | ||
): void { | ||
$oldCatalogId = $this->systemConfig->getCatalogId($storeId); | ||
try { | ||
// if Catalog id is updated, only then we update the config | ||
if ($oldCatalogId != $catalogId) { | ||
// updates catalog id | ||
$this->systemConfig->saveConfig( | ||
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_CATALOG_ID, | ||
$catalogId, | ||
$storeId | ||
); | ||
// updates commerce partner integration id | ||
$this->systemConfig->saveConfig( | ||
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_COMMERCE_PARTNER_INTEGRATION_ID, | ||
$commercePartnerIntegrationId, | ||
$storeId | ||
); | ||
// updates pixel id | ||
$this->systemConfig->saveConfig( | ||
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_ID, | ||
$pixelId, | ||
$storeId | ||
); | ||
// delete feed id as new catalog would be having new feed id. | ||
$this->systemConfig->deleteConfig( | ||
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID, | ||
$storeId | ||
); | ||
// Dispatch the facebook_update_catalog_configuration event | ||
// so observer in other Meta modules can subscribe and update required configurations | ||
// along with configuration updated in this file. | ||
// for e.g. clears all the product set ids for categories for old catalog | ||
$this->eventManager->dispatch('facebook_update_catalog_configuration', ['store_id' => $storeId]); | ||
|
||
$this->fbeHelper->log('Catalog configuration updated and stale product set ids cleared --- ' | ||
. $commercePartnerIntegrationId); | ||
|
||
} | ||
|
||
$this->systemConfig->cleanCache(); | ||
|
||
// Dispatch the facebook_update_catalog_configuration_after event, | ||
// so observers in other Meta modules can subscribe and trigger their syncs, | ||
// such as full catalog sync, and shipping profiles sync | ||
$this->eventManager->dispatch('facebook_update_catalog_configuration_after', ['store_id' => $storeId]); | ||
} catch (\Throwable $e) { | ||
$context = [ | ||
'store_id' => $storeId, | ||
'event' => 'update_catalog_config', | ||
'event_type' => 'update_catalog_config', | ||
'catalog_id' => $catalogId, | ||
'old_catalog_id' => $oldCatalogId, | ||
'commerce_partner_integration_id' => $commercePartnerIntegrationId, | ||
'pixel_id' => $pixelId | ||
]; | ||
$this->fbeHelper->logExceptionImmediatelyToMeta($e, $context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.