Skip to content

Commit 10f89e7

Browse files
MC-21426: Fix all broken Product related tests in Page Builder Component
- Fix query for staging.
1 parent 71c781d commit 10f89e7

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\Framework\DataObject;
1919
use Magento\Framework\EntityManager\EntityManager;
2020
use Magento\Catalog\Setup\CategorySetup;
21+
use Magento\Framework\EntityManager\MetadataPool;
22+
use Magento\Catalog\Api\Data\ProductInterface;
2123

2224
/**
2325
* Resource model for category entity
@@ -95,6 +97,11 @@ class Category extends AbstractResource
9597
*/
9698
private $indexerProcessor;
9799

100+
/**
101+
* @var MetadataPool
102+
*/
103+
private $metadataPool;
104+
98105
/**
99106
* Category constructor.
100107
* @param \Magento\Eav\Model\Entity\Context $context
@@ -106,6 +113,7 @@ class Category extends AbstractResource
106113
* @param Processor $indexerProcessor
107114
* @param array $data
108115
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
116+
* @param MetadataPool|null $metadataPool
109117
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
110118
*/
111119
public function __construct(
@@ -117,7 +125,8 @@ public function __construct(
117125
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
118126
Processor $indexerProcessor,
119127
$data = [],
120-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
128+
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
129+
MetadataPool $metadataPool = null
121130
) {
122131
parent::__construct(
123132
$context,
@@ -132,6 +141,7 @@ public function __construct(
132141
$this->indexerProcessor = $indexerProcessor;
133142
$this->serializer = $serializer ?: ObjectManager::getInstance()
134143
->get(\Magento\Framework\Serialize\Serializer\Json::class);
144+
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
135145
}
136146

137147
/**
@@ -1160,13 +1170,14 @@ public function getCategoryWithChildren(int $categoryId): array
11601170
return [];
11611171
}
11621172

1173+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
11631174
$select = $connection->select()
11641175
->from(
11651176
['cce' => $this->getTable('catalog_category_entity')],
1166-
['entity_id', 'parent_id', 'path']
1177+
[$linkField, 'parent_id', 'path']
11671178
)->join(
11681179
['cce_int' => $this->getTable('catalog_category_entity_int')],
1169-
'cce.entity_id = cce_int.entity_id',
1180+
'cce.' . $linkField . ' = cce_int.' . $linkField,
11701181
['is_anchor' => 'cce_int.value']
11711182
)->where(
11721183
'cce_int.attribute_id = ?',

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,13 +2113,14 @@ private function getChildrenCategories(int $categoryId): array
21132113

21142114
$firstCategory = array_shift($categories);
21152115
if ($firstCategory['is_anchor'] == 1) {
2116-
$anchorCategory[] = (int)$firstCategory['entity_id'];
2116+
$linkField = $this->getProductEntityMetadata()->getLinkField();
2117+
$anchorCategory[] = (int)$firstCategory[$linkField];
21172118
foreach ($categories as $category) {
21182119
if (in_array($category['parent_id'], $categoryIds)
21192120
&& in_array($category['parent_id'], $anchorCategory)) {
2120-
$categoryIds[] = (int)$category['entity_id'];
2121+
$categoryIds[] = (int)$category[$linkField];
21212122
if ($category['is_anchor'] == 1) {
2122-
$anchorCategory[] = (int)$category['entity_id'];
2123+
$anchorCategory[] = (int)$category[$linkField];
21232124
}
21242125
}
21252126
}

0 commit comments

Comments
 (0)