systemConfig = $systemConfig;
$this->commerceHelper = $commerceHelper;
$this->fbeHelper = $fbeHelper;
}
/**
* Sync orders from facebook for a store
*
* @param int $storeId
* @return void
* @throws GuzzleException
*/
private function pullOrdersForStore(int $storeId): void
{
// Only pull order if all the condition met:
// 1. Order sync enabled
// 2. Extension enabled(included in 1)
// 3. There's any shop feature installed(fb_shop, page_shop, ig_shopping) and active
// 4. The installed shop is eligible for onsite features
if (!($this->systemConfig->isOrderSyncEnabled($storeId)
&& $this->systemConfig->isFBEShopInstalled($storeId)
&& $this->systemConfig->isInstalledShopOnsiteEligible($storeId))) {
return;
}
$this->commerceHelper->pullPendingOrders($storeId);
}
/**
* Sync orders from facebook for each magento store
*
* @return void
*/
public function execute()
{
foreach ($this->systemConfig->getAllOnsiteFBEInstalledStores() as $store) {
try {
$this->pullOrdersForStore((int)$store->getId());
} catch (Exception $e) {
$context = [
'store_id' => $store->getId(),
'event' => 'order_sync',
'event_type' => 'sync_orders_cron',
];
$this->fbeHelper->logExceptionImmediatelyToMeta($e, $context);
}
}
}
}