Skip to content

Commit 0792ff1

Browse files
committed
Fix bug which happened during indexing with active grouped products having inactive children
1 parent b8d5672 commit 0792ff1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Model/ResourceModel/GroupedProductAssociations.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use IntegerNet\Solr\Indexer\Data\ProductAssociation;
1515
use IntegerNet\Solr\Model\Data\ArrayCollection;
16+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface as AttributeRepository;
1617
use Magento\Catalog\Api\Data\ProductInterface;
1718
use Magento\Framework\EntityManager\MetadataPool;
1819
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
@@ -25,13 +26,22 @@ class GroupedProductAssociations extends AbstractDb implements ProductAssociatio
2526
* @var MetadataPool
2627
*/
2728
private $metadataPool;
29+
/**
30+
* @var AttributeRepository
31+
*/
32+
private $attributeRepository;
2833

2934
private $productEntityLinkField;
3035

31-
public function __construct(ResourceContext $context, MetadataPool $metadataPool, $connectionName = null
36+
public function __construct(
37+
ResourceContext $context,
38+
MetadataPool $metadataPool,
39+
AttributeRepository $attributeRepository,
40+
$connectionName = null
3241
) {
3342
$this->metadataPool = $metadataPool;
3443
parent::__construct($context, $connectionName);
44+
$this->attributeRepository = $attributeRepository;
3545
}
3646

3747
/**
@@ -53,7 +63,9 @@ protected function _construct()
5363
public function getAssociations($parentIds)
5464
{
5565
$connection = $this->getConnection();
56-
$bind = [':link_type_id' => ProductLinkResource::LINK_TYPE_GROUPED];
66+
$statusAttributeId = $this->attributeRepository->get('status')->getAttributeId();
67+
$bind = [':link_type_id' => ProductLinkResource::LINK_TYPE_GROUPED, ':status_attribute_id' => $statusAttributeId];
68+
5769
$select = $connection->select()->from(
5870
['l' => $this->getMainTable()],
5971
['product_id', 'linked_product_id']
@@ -63,9 +75,14 @@ public function getAssociations($parentIds)
6375
'cpe.%s = l.product_id',
6476
$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()
6577
)
78+
)->join(
79+
['cpei' => $this->getTable('catalog_product_entity_int')],
80+
'cpei.entity_id = l.linked_product_id AND cpei.attribute_id = :status_attribute_id',
81+
''
6682
)->where(
6783
'link_type_id = :link_type_id'
6884
);
85+
$select->where('cpei.value = ?', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
6986
if ($parentIds !== null) {
7087
$select->where('cpe.entity_id IN (?)', $parentIds);
7188
}

0 commit comments

Comments
 (0)