Skip to content

Commit 544f513

Browse files
Priyambad PandeyPriyambad Pandey
authored andcommitted
ADO-379: Uses correct primary key for catalog_category_entity table in enterprise vs opensource magento
1 parent a65f51e commit 544f513

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/code/Meta/Catalog/Model/Category/CategoryUtility/CategoryUtilities.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
use Meta\BusinessExtension\Helper\FBEHelper;
3535
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
3636
use Meta\Catalog\Helper\Product\Identifier as ProductIdentifier;
37+
use Magento\Framework\EntityManager\MetadataPool;
38+
use Magento\Catalog\Api\Data\CategoryInterface;
3739

3840
/**
3941
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -93,6 +95,11 @@ class CategoryUtilities
9395
*/
9496
private ResourceConnection $resourceConnection;
9597

98+
/**
99+
* @var MetadataPool
100+
*/
101+
private MetadataPool $metadataPool;
102+
96103
/**
97104
* Constructor
98105
* @param ProductCollectionFactory $productCollectionFactory
@@ -104,6 +111,7 @@ class CategoryUtilities
104111
* @param CategoryImageService $imageService
105112
* @param EavConfig $eavConfig
106113
* @param ResourceConnection $resourceConnection
114+
* @param MetadataPool $metadataPool
107115
*/
108116
public function __construct(
109117
ProductCollectionFactory $productCollectionFactory,
@@ -114,7 +122,8 @@ public function __construct(
114122
ProductIdentifier $productIdentifier,
115123
CategoryImageService $imageService,
116124
EavConfig $eavConfig,
117-
ResourceConnection $resourceConnection
125+
ResourceConnection $resourceConnection,
126+
MetadataPool $metadataPool
118127
) {
119128
$this->categoryCollection = $categoryCollection;
120129
$this->categoryRepository = $categoryRepository;
@@ -125,6 +134,7 @@ public function __construct(
125134
$this->imageService = $imageService;
126135
$this->eavConfig = $eavConfig;
127136
$this->resourceConnection = $resourceConnection;
137+
$this->metadataPool = $metadataPool;
128138
}
129139
/**
130140
* Fetch products for product category
@@ -382,13 +392,16 @@ public function saveFBProductSetID(Category $category, string $setId, $storeId):
382392
$categoryEntityVarcharTable = $this->resourceConnection->getTableName(
383393
'catalog_category_entity_varchar'
384394
);
395+
396+
$categoryLinkField = $this->metadataPool->getMetadata(CategoryInterface::class)->getLinkField();
397+
385398
if ($category->getData(SystemConfig::META_PRODUCT_SET_ID) == null) {
386399
$this->resourceConnection->getConnection()->insert(
387400
$categoryEntityVarcharTable,
388401
[
389402
'attribute_id' => $productSetAttributeId,
390403
'store_id' => $storeId,
391-
'entity_id' => $category->getId(),
404+
$categoryLinkField => $category->getId(),
392405
'value' => $setId
393406
]
394407
);
@@ -398,13 +411,13 @@ public function saveFBProductSetID(Category $category, string $setId, $storeId):
398411
[
399412
'attribute_id' => $productSetAttributeId,
400413
'store_id' => $storeId,
401-
'entity_id' => $category->getId(),
414+
$categoryLinkField => $category->getId(),
402415
'value' => $setId
403416
],
404417
[
405418
'attribute_id = ?' => $productSetAttributeId,
406419
'store_id = ?' => $storeId,
407-
'entity_id = ?' => $category->getId(),
420+
sprintf('%s = ?', $categoryLinkField) => $category->getId()
408421
]
409422
);
410423
}

0 commit comments

Comments
 (0)