34
34
use Meta \BusinessExtension \Helper \FBEHelper ;
35
35
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
36
36
use Meta \Catalog \Helper \Product \Identifier as ProductIdentifier ;
37
+ use Magento \Framework \EntityManager \MetadataPool ;
38
+ use Magento \Catalog \Api \Data \CategoryInterface ;
37
39
38
40
/**
39
41
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -93,6 +95,11 @@ class CategoryUtilities
93
95
*/
94
96
private ResourceConnection $ resourceConnection ;
95
97
98
+ /**
99
+ * @var MetadataPool
100
+ */
101
+ private MetadataPool $ metadataPool ;
102
+
96
103
/**
97
104
* Constructor
98
105
* @param ProductCollectionFactory $productCollectionFactory
@@ -104,6 +111,7 @@ class CategoryUtilities
104
111
* @param CategoryImageService $imageService
105
112
* @param EavConfig $eavConfig
106
113
* @param ResourceConnection $resourceConnection
114
+ * @param MetadataPool $metadataPool
107
115
*/
108
116
public function __construct (
109
117
ProductCollectionFactory $ productCollectionFactory ,
@@ -114,7 +122,8 @@ public function __construct(
114
122
ProductIdentifier $ productIdentifier ,
115
123
CategoryImageService $ imageService ,
116
124
EavConfig $ eavConfig ,
117
- ResourceConnection $ resourceConnection
125
+ ResourceConnection $ resourceConnection ,
126
+ MetadataPool $ metadataPool
118
127
) {
119
128
$ this ->categoryCollection = $ categoryCollection ;
120
129
$ this ->categoryRepository = $ categoryRepository ;
@@ -125,6 +134,7 @@ public function __construct(
125
134
$ this ->imageService = $ imageService ;
126
135
$ this ->eavConfig = $ eavConfig ;
127
136
$ this ->resourceConnection = $ resourceConnection ;
137
+ $ this ->metadataPool = $ metadataPool ;
128
138
}
129
139
/**
130
140
* Fetch products for product category
@@ -382,13 +392,16 @@ public function saveFBProductSetID(Category $category, string $setId, $storeId):
382
392
$ categoryEntityVarcharTable = $ this ->resourceConnection ->getTableName (
383
393
'catalog_category_entity_varchar '
384
394
);
395
+
396
+ $ categoryLinkField = $ this ->metadataPool ->getMetadata (CategoryInterface::class)->getLinkField ();
397
+
385
398
if ($ category ->getData (SystemConfig::META_PRODUCT_SET_ID ) == null ) {
386
399
$ this ->resourceConnection ->getConnection ()->insert (
387
400
$ categoryEntityVarcharTable ,
388
401
[
389
402
'attribute_id ' => $ productSetAttributeId ,
390
403
'store_id ' => $ storeId ,
391
- ' entity_id ' => $ category ->getId (),
404
+ $ categoryLinkField => $ category ->getId (),
392
405
'value ' => $ setId
393
406
]
394
407
);
@@ -398,13 +411,13 @@ public function saveFBProductSetID(Category $category, string $setId, $storeId):
398
411
[
399
412
'attribute_id ' => $ productSetAttributeId ,
400
413
'store_id ' => $ storeId ,
401
- ' entity_id ' => $ category ->getId (),
414
+ $ categoryLinkField => $ category ->getId (),
402
415
'value ' => $ setId
403
416
],
404
417
[
405
418
'attribute_id = ? ' => $ productSetAttributeId ,
406
419
'store_id = ? ' => $ storeId ,
407
- ' entity_id = ? ' => $ category ->getId (),
420
+ sprintf ( ' %s = ? ', $ categoryLinkField ) => $ category ->getId ()
408
421
]
409
422
);
410
423
}
0 commit comments