@@ -56,7 +56,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
56
56
/**
57
57
* @var MetadataPool
58
58
*/
59
- protected $ metadataPool ;
59
+ private $ metadataPool ;
60
60
61
61
/**
62
62
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -219,7 +219,8 @@ public function addProductFilter($products)
219
219
if (!is_array ($ products )) {
220
220
$ products = [$ products ];
221
221
}
222
- $ this ->getSelect ()->where ('links.product_id IN (?) ' , $ products );
222
+ $ identifierField = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class)->getIdentifierField ();
223
+ $ this ->getSelect ()->where ("product_entity_table. $ identifierField IN (?) " , $ products );
223
224
$ this ->_hasLinkFilter = true ;
224
225
}
225
226
@@ -258,6 +259,7 @@ protected function _beforeLoad()
258
259
{
259
260
if ($ this ->getLinkModel ()) {
260
261
$ this ->_joinLinks ();
262
+ $ this ->joinProductsToLinks ();
261
263
}
262
264
return parent ::_beforeLoad ();
263
265
}
@@ -423,12 +425,28 @@ public function addLinkAttributeToFilter($code, $condition)
423
425
/**
424
426
* Get MetadataPool instance
425
427
* @return MetadataPool
428
+ * @deprecated
426
429
*/
427
- protected function getMetadataPool ()
430
+ private function getMetadataPool ()
428
431
{
429
432
if (!$ this ->metadataPool ) {
430
433
$ this ->metadataPool = ObjectManager::getInstance ()->get (MetadataPool::class);
431
434
}
432
435
return $ this ->metadataPool ;
433
436
}
437
+
438
+ /**
439
+ * Join Product To Links
440
+ * @return void
441
+ */
442
+ private function joinProductsToLinks ()
443
+ {
444
+ if ($ this ->_hasLinkFilter ) {
445
+ $ metaDataPool = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class);
446
+ $ linkField = $ metaDataPool ->getLinkField ();
447
+ $ entityTable = $ metaDataPool ->getEntityTable ();
448
+ $ this ->getSelect ()
449
+ ->join (['product_entity_table ' => $ entityTable ], "links.product_id = product_entity_table. $ linkField " , []);
450
+ }
451
+ }
434
452
}
0 commit comments