Skip to content

Commit 4e98a94

Browse files
authored
Only sync orders if shop feature installed (#838)
* Address linter warning suggestions * Only sync orders if: Order sync enabled AND Extension enabled(included in 1) AND There's any shop feature installed(fb_shop, page_shop, ig_shopping) and active * Split format change into a different PR * Bring back int casting * Address linter warning suggestions * Only sync orders if: Order sync enabled AND Extension enabled(included in 1) AND There's any shop feature installed(fb_shop, page_shop, ig_shopping) and active * Split format change into a different PR * Bring back int casting * When saving fbeConfig, also save the onsite eligibility flag
1 parent 0e46468 commit 4e98a94

File tree

4 files changed

+47
-57
lines changed

4 files changed

+47
-57
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function save($response, $storeId)
134134
$data = $response[0];
135135
$catalogId = $data['catalog_id'] ?? '';
136136
$pixelId = $data['pixel_id'] ?? '';
137+
$onsite_eligible = $data['onsite_eligible'] ?? false;
137138
$commercePartnerIntegrationId = $data['commerce_partner_integration_id'] ?? '';
138139

139140
// we will update catalog config if catalog has been updated in Meta
@@ -150,6 +151,7 @@ public function save($response, $storeId)
150151
$this->savePages($data['pages'] ?? '', $storeId);
151152
$this->saveCatalogId($catalogId, $storeId);
152153
$this->saveCommercePartnerIntegrationId($commercePartnerIntegrationId, $storeId);
154+
$this->saveIsOnsiteEligible($onsite_eligible, $storeId);
153155
$this->saveMerchantSettingsId($data['commerce_merchant_settings_id'] ?? '', $storeId);
154156
$this->saveInstalledFeatures($data['installed_features'] ?? '', $storeId);
155157
$this->setInstalledFlag($storeId);
@@ -276,6 +278,28 @@ public function saveCommercePartnerIntegrationId($commercePartnerIntegrationId,
276278
return $this;
277279
}
278280

281+
/**
282+
* Save Onsite Eligible for the store
283+
*
284+
* @param bool $onsite_eligible
285+
* @param int $storeId
286+
* @return $this
287+
*/
288+
public function saveIsOnsiteEligible($onsite_eligible, $storeId)
289+
{
290+
if ($onsite_eligible) {
291+
$this->systemConfig->saveConfig(
292+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_IS_ONSITE_ELIGIBLE,
293+
1,
294+
$storeId
295+
);
296+
$this->fbeHelper->log(
297+
"Mark storeID: {$storeId} as Onsite eligible"
298+
);
299+
}
300+
return $this;
301+
}
302+
279303
/**
280304
* Save commerce merchant settings id
281305
*

app/code/Meta/BusinessExtension/Model/System/Config.php

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Config
4242
private const VERSION_CACHE_KEY = 'meta-business-extension-version';
4343
private const EXTENSION_PACKAGE_NAME = 'meta/meta-for-magento2';
4444

45-
private const XML_PATH_AUCTANE_API_ACTIVE = 'carriers/shipstation/active';
4645
private const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACTIVE = 'facebook/business_extension/active';
4746
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED = 'facebook/business_extension/installed';
4847

@@ -63,6 +62,8 @@ class Config
6362

6463
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_COMMERCE_PARTNER_INTEGRATION_ID =
6564
'facebook/business_extension/commerce_partner_integration_id';
65+
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_IS_ONSITE_ELIGIBLE =
66+
'facebook/business_extension/is_onsite_eligible';
6667
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_COMMERCE_ACCOUNT_ID =
6768
'facebook/business_extension/commerce_account_id';
6869
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID = 'facebook/business_extension/feed_id';
@@ -447,23 +448,6 @@ public function getFulfillmentAddress($scopeId = null, $scope = ScopeInterface::
447448
return $address;
448449
}
449450

450-
/**
451-
* Check if Auctane API is installed
452-
*
453-
* @return bool
454-
*/
455-
public function isAuctaneApiInstalled(): bool
456-
{
457-
try {
458-
// In the "Single Store" case, getting the config of a non-existent path can throw.
459-
// This corresponds to "missing Shipstation Extension"
460-
$value = $this->getConfig(self::XML_PATH_AUCTANE_API_ACTIVE);
461-
} catch (Exception $e) {
462-
return false;
463-
}
464-
return $value === '1';
465-
}
466-
467451
/**
468452
* Is auto newsletter subscription on
469453
*
@@ -552,25 +536,6 @@ public function cleanCache()
552536
return $this;
553537
}
554538

555-
/**
556-
* Disable extension for non default stores
557-
*
558-
* @return $this
559-
*/
560-
public function disableExtensionForNonDefaultStores()
561-
{
562-
$storeManager = $this->getStoreManager();
563-
if (!$storeManager->isSingleStoreMode()) {
564-
$defaultStoreId = $storeManager->getDefaultStoreView()->getId();
565-
foreach ($storeManager->getStores() as $store) {
566-
if ($store->getId() !== $defaultStoreId) {
567-
$this->saveConfig(self::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACTIVE, 0, $store->getId());
568-
}
569-
}
570-
}
571-
return $this;
572-
}
573-
574539
/**
575540
* Get access token
576541
*
@@ -1089,14 +1054,16 @@ public function isFBEAdsInstalled($storeId = null)
10891054
}
10901055

10911056
/**
1092-
* Check if FBE ads is Installed
1057+
* Check if any shop feature installed(fb_shop, page_shop, ig_shopping) and active
10931058
*
1094-
* @param int $storeId
1059+
* @param int|null $storeId
10951060
* @return bool
10961061
*/
1097-
public function isFBEShopInstalled($storeId = null)
1062+
public function isFBEShopInstalled(int $storeId = null): bool
10981063
{
1099-
return $this->isFeatureInstalled('fb_shop', $storeId);
1064+
return $this->isFeatureInstalled('fb_shop', $storeId) ||
1065+
$this->isFeatureInstalled('ig_shopping', $storeId) ||
1066+
$this->isFeatureInstalled('page_shop', $storeId);
11001067
}
11011068

11021069
/**

app/code/Meta/Sales/Cron/SyncOrders.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
namespace Meta\Sales\Cron;
2222

2323
use Exception;
24-
use Magento\Store\Model\StoreManagerInterface;
2524
use Meta\Sales\Helper\CommerceHelper;
2625
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2726
use GuzzleHttp\Exception\GuzzleException;
@@ -32,10 +31,6 @@
3231
*/
3332
class SyncOrders
3433
{
35-
/**
36-
* @var StoreManagerInterface
37-
*/
38-
private StoreManagerInterface $storeManager;
3934

4035
/**
4136
* @var SystemConfig
@@ -53,35 +48,35 @@ class SyncOrders
5348
private FBEHelper $fbeHelper;
5449

5550
/**
56-
* @param StoreManagerInterface $storeManager
57-
* @param SystemConfig $systemConfig
58-
* @param CommerceHelper $commerceHelper
59-
* @param FBEHelper $fbeHelper
51+
* @param SystemConfig $systemConfig
52+
* @param CommerceHelper $commerceHelper
53+
* @param FBEHelper $fbeHelper
6054
*/
6155
public function __construct(
62-
StoreManagerInterface $storeManager,
6356
SystemConfig $systemConfig,
6457
CommerceHelper $commerceHelper,
6558
FBEHelper $fbeHelper
6659
) {
6760
$this->systemConfig = $systemConfig;
6861
$this->commerceHelper = $commerceHelper;
69-
$this->storeManager = $storeManager;
7062
$this->fbeHelper = $fbeHelper;
7163
}
7264

7365
/**
7466
* Sync orders from facebook for a store
7567
*
76-
* @param int $storeId
68+
* @param int $storeId
7769
* @return void
7870
* @throws GuzzleException
7971
*/
80-
private function pullOrdersForStore(int $storeId)
72+
private function pullOrdersForStore(int $storeId): void
8173
{
74+
// Only pull order if all the condition met:
75+
// 1. Order sync enabled
76+
// 2. Extension enabled(included in 1)
77+
// 3. There's any shop feature installed(fb_shop, page_shop, ig_shopping) and active
8278
if (!($this->systemConfig->isOrderSyncEnabled($storeId)
83-
&& $this->systemConfig->isActiveExtension($storeId))
84-
) {
79+
&& $this->systemConfig->isFBEShopInstalled($storeId))) {
8580
return;
8681
}
8782

app/code/Meta/Sales/Cron/SyncRefundsAndCancellations.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ public function __construct(
7979
*/
8080
private function pullRefundsAndCancellationsForStore(int $storeId)
8181
{
82+
// Only pull order if all the condition met:
83+
// 1. Order sync enabled
84+
// 2. Extension enabled(included in 1)
85+
// 3. There's any shop feature installed(fb_shop, page_shop, ig_shopping) and active
8286
if (!($this->systemConfig->isOrderSyncEnabled($storeId)
83-
&& $this->systemConfig->isActiveExtension($storeId))
87+
&& $this->systemConfig->isFBEShopInstalled($storeId))
8488
) {
8589
return;
8690
}

0 commit comments

Comments
 (0)