1818use Magento \Framework \DataObject ;
1919use Magento \Framework \EntityManager \EntityManager ;
2020use 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 = ? ' ,
0 commit comments