Skip to content

Commit 4475be6

Browse files
author
olysenko
committed
Merge remote-tracking branch 'origin/MAGETWO-53305' into pr
2 parents f879552 + 27e02f8 commit 4475be6

File tree

1 file changed

+21
-3
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
5656
/**
5757
* @var MetadataPool
5858
*/
59-
protected $metadataPool;
59+
private $metadataPool;
6060

6161
/**
6262
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -219,7 +219,8 @@ public function addProductFilter($products)
219219
if (!is_array($products)) {
220220
$products = [$products];
221221
}
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);
223224
$this->_hasLinkFilter = true;
224225
}
225226

@@ -258,6 +259,7 @@ protected function _beforeLoad()
258259
{
259260
if ($this->getLinkModel()) {
260261
$this->_joinLinks();
262+
$this->joinProductsToLinks();
261263
}
262264
return parent::_beforeLoad();
263265
}
@@ -423,12 +425,28 @@ public function addLinkAttributeToFilter($code, $condition)
423425
/**
424426
* Get MetadataPool instance
425427
* @return MetadataPool
428+
* @deprecated
426429
*/
427-
protected function getMetadataPool()
430+
private function getMetadataPool()
428431
{
429432
if (!$this->metadataPool) {
430433
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
431434
}
432435
return $this->metadataPool;
433436
}
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+
}
434452
}

0 commit comments

Comments
 (0)