9
9
10
10
use Magento \Framework \App \ResourceConnection ;
11
11
use Magento \Catalog \Model \Product \Attribute \Source \Status ;
12
+ use Magento \Framework \EntityManager \MetadataPool ;
12
13
use Magento \Store \Model \Store ;
13
14
14
15
/**
@@ -31,19 +32,28 @@ class Eraser
31
32
*/
32
33
protected $ storeManager ;
33
34
35
+ /**
36
+ * @var MetadataPool
37
+ */
38
+ private $ metadataPool ;
39
+
34
40
/**
35
41
* @param \Magento\Framework\App\ResourceConnection $resource
36
42
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productHelper
37
43
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
44
+ * @param MetadataPool|null $metadataPool
38
45
*/
39
46
public function __construct (
40
47
\Magento \Framework \App \ResourceConnection $ resource ,
41
48
\Magento \Catalog \Helper \Product \Flat \Indexer $ productHelper ,
42
- \Magento \Store \Model \StoreManagerInterface $ storeManager
49
+ \Magento \Store \Model \StoreManagerInterface $ storeManager ,
50
+ MetadataPool $ metadataPool = null
43
51
) {
44
52
$ this ->productIndexerHelper = $ productHelper ;
45
53
$ this ->connection = $ resource ->getConnection ();
46
54
$ this ->storeManager = $ storeManager ;
55
+ $ this ->metadataPool = $ metadataPool ?:
56
+ \Magento \Framework \App \ObjectManager::getInstance ()->get (MetadataPool::class);
47
57
}
48
58
49
59
/**
@@ -81,17 +91,24 @@ public function removeDisabledProducts(array &$ids, $storeId)
81
91
/* @var $statusAttribute \Magento\Eav\Model\Entity\Attribute */
82
92
$ statusAttribute = $ this ->productIndexerHelper ->getAttribute ('status ' );
83
93
94
+ /** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
95
+ $ metadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class);
96
+
84
97
$ select = $ this ->getSelectForProducts ($ ids );
85
98
$ select ->joinLeft (
86
99
['status_global_attr ' => $ statusAttribute ->getBackendTable ()],
87
100
' status_global_attr.attribute_id = ' . (int )$ statusAttribute ->getAttributeId ()
88
- . ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID ,
101
+ . ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID
102
+ . ' AND status_global_attr. ' . $ statusAttribute ->getEntityIdField () . '= '
103
+ . 'product_table. ' . $ metadata ->getLinkField (),
89
104
[]
90
105
);
91
106
$ select ->joinLeft (
92
107
['status_attr ' => $ statusAttribute ->getBackendTable ()],
93
108
' status_attr.attribute_id = ' . (int )$ statusAttribute ->getAttributeId ()
94
- . ' AND status_attr.store_id = ' . $ storeId ,
109
+ . ' AND status_attr.store_id = ' . $ storeId
110
+ . ' AND status_attr. ' . $ statusAttribute ->getEntityIdField () . '= '
111
+ . 'product_table. ' . $ metadata ->getLinkField (),
95
112
[]
96
113
);
97
114
$ select ->where ('IFNULL(status_attr.value, status_global_attr.value) = ? ' , Status::STATUS_DISABLED );
0 commit comments