18
18
use Magento \Framework \DataObject ;
19
19
use Magento \Framework \EntityManager \EntityManager ;
20
20
use Magento \Catalog \Setup \CategorySetup ;
21
+ use Magento \Framework \EntityManager \MetadataPool ;
22
+ use Magento \Catalog \Api \Data \ProductInterface ;
21
23
22
24
/**
23
25
* Resource model for category entity
@@ -95,6 +97,11 @@ class Category extends AbstractResource
95
97
*/
96
98
private $ indexerProcessor ;
97
99
100
+ /**
101
+ * @var MetadataPool
102
+ */
103
+ private $ metadataPool ;
104
+
98
105
/**
99
106
* Category constructor.
100
107
* @param \Magento\Eav\Model\Entity\Context $context
@@ -106,6 +113,7 @@ class Category extends AbstractResource
106
113
* @param Processor $indexerProcessor
107
114
* @param array $data
108
115
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
116
+ * @param MetadataPool|null $metadataPool
109
117
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
110
118
*/
111
119
public function __construct (
@@ -117,7 +125,8 @@ public function __construct(
117
125
\Magento \Catalog \Model \ResourceModel \Category \CollectionFactory $ categoryCollectionFactory ,
118
126
Processor $ indexerProcessor ,
119
127
$ data = [],
120
- \Magento \Framework \Serialize \Serializer \Json $ serializer = null
128
+ \Magento \Framework \Serialize \Serializer \Json $ serializer = null ,
129
+ MetadataPool $ metadataPool = null
121
130
) {
122
131
parent ::__construct (
123
132
$ context ,
@@ -132,6 +141,7 @@ public function __construct(
132
141
$ this ->indexerProcessor = $ indexerProcessor ;
133
142
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()
134
143
->get (\Magento \Framework \Serialize \Serializer \Json::class);
144
+ $ this ->metadataPool = $ metadataPool ?: ObjectManager::getInstance ()->get (MetadataPool::class);
135
145
}
136
146
137
147
/**
@@ -1160,13 +1170,14 @@ public function getCategoryWithChildren(int $categoryId): array
1160
1170
return [];
1161
1171
}
1162
1172
1173
+ $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
1163
1174
$ select = $ connection ->select ()
1164
1175
->from (
1165
1176
['cce ' => $ this ->getTable ('catalog_category_entity ' )],
1166
- [' entity_id ' , 'parent_id ' , 'path ' ]
1177
+ [$ linkField , 'parent_id ' , 'path ' ]
1167
1178
)->join (
1168
1179
['cce_int ' => $ this ->getTable ('catalog_category_entity_int ' )],
1169
- 'cce.entity_id = cce_int.entity_id ' ,
1180
+ 'cce. ' . $ linkField . ' = cce_int.' . $ linkField ,
1170
1181
['is_anchor ' => 'cce_int.value ' ]
1171
1182
)->where (
1172
1183
'cce_int.attribute_id = ? ' ,
0 commit comments