@@ -104,10 +104,22 @@ private function getFbFeedId()
104
104
{
105
105
$ feedId = $ this ->systemConfig ->getFeedId ($ this ->storeId );
106
106
$ 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
+ }
107
121
108
122
if (!$ feedId ) {
109
- $ catalogId = $ this ->systemConfig ->getCatalogId ($ this ->storeId );
110
- $ catalogFeeds = $ this ->graphApiAdapter ->getCatalogFeeds ($ catalogId );
111
123
$ magentoFeeds = array_filter ($ catalogFeeds , function ($ a ) use ($ feedName ) {
112
124
return $ a ['name ' ] === $ feedName ;
113
125
});
@@ -117,9 +129,7 @@ private function getFbFeedId()
117
129
}
118
130
119
131
if (!$ feedId ) {
120
- $ catalogId = $ this ->systemConfig ->getCatalogId ($ this ->storeId );
121
132
$ feedId = $ this ->graphApiAdapter ->createEmptyFeed ($ catalogId , $ feedName );
122
-
123
133
$ maxAttempts = 5 ;
124
134
$ attempts = 0 ;
125
135
do {
@@ -132,12 +142,7 @@ private function getFbFeedId()
132
142
} while ($ attempts < $ maxAttempts );
133
143
}
134
144
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 ) {
141
146
$ this ->systemConfig
142
147
->saveConfig (SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID , $ feedId , $ this ->storeId )
143
148
->cleanCache ();
0 commit comments