28
28
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
29
29
use Meta \BusinessExtension \Helper \GraphAPIAdapter ;
30
30
use Meta \Catalog \Model \Product \Feed \Method \BatchApi ;
31
+ use Magento \Catalog \Model \ProductRepository as MagentoProductRepository ;
31
32
32
33
/**
33
34
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -69,6 +70,11 @@ class CatalogUpdateHandler
69
70
*/
70
71
private ProductIdentifier $ productIdentifier ;
71
72
73
+ /**
74
+ * @var MagentoProductRepository
75
+ */
76
+ private MagentoProductRepository $ magentoProductRepository ;
77
+
72
78
/**
73
79
* CatalogUpdateConsumer constructor
74
80
*
@@ -79,6 +85,7 @@ class CatalogUpdateHandler
79
85
* @param GraphAPIAdapter $graphAPIAdapter
80
86
* @param BatchApi $batchApi
81
87
* @param ProductIdentifier $productIdentifier
88
+ * @param MagentoProductRepository $magentoProductRepository
82
89
*/
83
90
public function __construct (
84
91
FBCatalogUpdateResourceModel $ fbCatalogUpdateResourceModel ,
@@ -87,7 +94,8 @@ public function __construct(
87
94
ProductRepository $ productRepository ,
88
95
GraphAPIAdapter $ graphAPIAdapter ,
89
96
BatchApi $ batchApi ,
90
- ProductIdentifier $ productIdentifier
97
+ ProductIdentifier $ productIdentifier ,
98
+ MagentoProductRepository $ magentoProductRepository
91
99
) {
92
100
$ this ->fbCatalogUpdateResourceModel = $ fbCatalogUpdateResourceModel ;
93
101
$ this ->fbeHelper = $ fbeHelper ;
@@ -96,6 +104,7 @@ public function __construct(
96
104
$ this ->graphApiAdapter = $ graphAPIAdapter ;
97
105
$ this ->batchApi = $ batchApi ;
98
106
$ this ->productIdentifier = $ productIdentifier ;
107
+ $ this ->magentoProductRepository = $ magentoProductRepository ;
99
108
}
100
109
101
110
/**
@@ -213,6 +222,21 @@ private function processUpdates(Collection $productUpdates, $storeId, string $ca
213
222
$ parentProduct = $ parentProducts ->getItemById ($ productLinks [$ product ->getId ()]);
214
223
if ($ parentProduct ) {
215
224
$ product = $ this ->productRepository ->loadParentProductData ($ product , $ parentProduct );
225
+ } else {
226
+ try {
227
+ $ parentProduct = $ this ->magentoProductRepository ->getById ($ productLinks [$ product ->getId ()]);
228
+ $ product = $ this ->productRepository ->loadParentProductData ($ product , $ parentProduct );
229
+ } catch (\Exception $ e ) {
230
+ $ this ->fbeHelper ->logException (
231
+ $ e ,
232
+ [
233
+ 'log_type ' => 'error ' ,
234
+ 'error_description ' => 'Exception occured during loading parent product data ' ,
235
+ 'product_id ' => $ product ->getId (),
236
+ 'parent_product_id ' => $ productLinks [$ product ->getId ()]
237
+ ]
238
+ );
239
+ }
216
240
}
217
241
}
218
242
0 commit comments