Skip to content

Commit 25e8826

Browse files
Meta Deleted feed handled on Magento side (#242)
* Meta Deleted feed handled on Magento side * duplicate feed config save is removed * Feed ID persisted if it is not null after feed upload * existing feed id and new feed id check added
1 parent 381c0a2 commit 25e8826

File tree

1 file changed

+15
-10
lines changed
  • app/code/Meta/Catalog/Model/Product/Feed/Method

1 file changed

+15
-10
lines changed

app/code/Meta/Catalog/Model/Product/Feed/Method/FeedApi.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,22 @@ private function getFbFeedId()
104104
{
105105
$feedId = $this->systemConfig->getFeedId($this->storeId);
106106
$feedName = self::FB_FEED_NAME;
107+
$catalogId = $this->systemConfig->getCatalogId($this->storeId);
108+
$catalogFeeds = $this->graphApiAdapter->getCatalogFeeds($catalogId);
109+
110+
// make sure feed exists on meta side, not deleted
111+
if ($feedId) {
112+
$magentoFeeds = array_filter($catalogFeeds, function ($a) use ($feedId) {
113+
return $a['id'] === $feedId;
114+
});
115+
// in case feed id is not found in meta catalog, feed id on
116+
// magento will be flushed and new feed will be created in Meta Catalog
117+
if (empty($magentoFeeds)) {
118+
$feedId = null;
119+
}
120+
}
107121

108122
if (!$feedId) {
109-
$catalogId = $this->systemConfig->getCatalogId($this->storeId);
110-
$catalogFeeds = $this->graphApiAdapter->getCatalogFeeds($catalogId);
111123
$magentoFeeds = array_filter($catalogFeeds, function ($a) use ($feedName) {
112124
return $a['name'] === $feedName;
113125
});
@@ -117,9 +129,7 @@ private function getFbFeedId()
117129
}
118130

119131
if (!$feedId) {
120-
$catalogId = $this->systemConfig->getCatalogId($this->storeId);
121132
$feedId = $this->graphApiAdapter->createEmptyFeed($catalogId, $feedName);
122-
123133
$maxAttempts = 5;
124134
$attempts = 0;
125135
do {
@@ -132,12 +142,7 @@ private function getFbFeedId()
132142
} while ($attempts < $maxAttempts);
133143
}
134144

135-
if (!$this->systemConfig->getFeedId($this->storeId) && $feedId) {
136-
$this->systemConfig->saveConfig(
137-
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID,
138-
$feedId,
139-
$this->storeId
140-
);
145+
if ($feedId && $this->systemConfig->getFeedId($this->storeId) != $feedId) {
141146
$this->systemConfig
142147
->saveConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID, $feedId, $this->storeId)
143148
->cleanCache();

0 commit comments

Comments
 (0)