13
13
14
14
use IntegerNet \Solr \Indexer \Data \ProductAssociation ;
15
15
use IntegerNet \Solr \Model \Data \ArrayCollection ;
16
+ use Magento \Catalog \Api \ProductAttributeRepositoryInterface as AttributeRepository ;
16
17
use Magento \Catalog \Api \Data \ProductInterface ;
17
18
use Magento \Framework \EntityManager \MetadataPool ;
18
19
use Magento \Framework \Model \ResourceModel \Db \AbstractDb ;
@@ -25,13 +26,22 @@ class GroupedProductAssociations extends AbstractDb implements ProductAssociatio
25
26
* @var MetadataPool
26
27
*/
27
28
private $ metadataPool ;
29
+ /**
30
+ * @var AttributeRepository
31
+ */
32
+ private $ attributeRepository ;
28
33
29
34
private $ productEntityLinkField ;
30
35
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
32
41
) {
33
42
$ this ->metadataPool = $ metadataPool ;
34
43
parent ::__construct ($ context , $ connectionName );
44
+ $ this ->attributeRepository = $ attributeRepository ;
35
45
}
36
46
37
47
/**
@@ -53,7 +63,9 @@ protected function _construct()
53
63
public function getAssociations ($ parentIds )
54
64
{
55
65
$ 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
+
57
69
$ select = $ connection ->select ()->from (
58
70
['l ' => $ this ->getMainTable ()],
59
71
['product_id ' , 'linked_product_id ' ]
@@ -63,9 +75,14 @@ public function getAssociations($parentIds)
63
75
'cpe.%s = l.product_id ' ,
64
76
$ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ()
65
77
)
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
+ ''
66
82
)->where (
67
83
'link_type_id = :link_type_id '
68
84
);
85
+ $ select ->where ('cpei.value = ? ' , \Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED );
69
86
if ($ parentIds !== null ) {
70
87
$ select ->where ('cpe.entity_id IN (?) ' , $ parentIds );
71
88
}
0 commit comments