99
1010use Magento \Framework \App \ResourceConnection ;
1111use Magento \Catalog \Model \Product \Attribute \Source \Status ;
12+ use Magento \Framework \EntityManager \MetadataPool ;
1213use Magento \Store \Model \Store ;
1314
1415/**
@@ -31,19 +32,28 @@ class Eraser
3132 */
3233 protected $ storeManager ;
3334
35+ /**
36+ * @var MetadataPool
37+ */
38+ private $ metadataPool ;
39+
3440 /**
3541 * @param \Magento\Framework\App\ResourceConnection $resource
3642 * @param \Magento\Catalog\Helper\Product\Flat\Indexer $productHelper
3743 * @param \Magento\Store\Model\StoreManagerInterface $storeManager
44+ * @param MetadataPool|null $metadataPool
3845 */
3946 public function __construct (
4047 \Magento \Framework \App \ResourceConnection $ resource ,
4148 \Magento \Catalog \Helper \Product \Flat \Indexer $ productHelper ,
42- \Magento \Store \Model \StoreManagerInterface $ storeManager
49+ \Magento \Store \Model \StoreManagerInterface $ storeManager ,
50+ MetadataPool $ metadataPool = null
4351 ) {
4452 $ this ->productIndexerHelper = $ productHelper ;
4553 $ this ->connection = $ resource ->getConnection ();
4654 $ this ->storeManager = $ storeManager ;
55+ $ this ->metadataPool = $ metadataPool ?:
56+ \Magento \Framework \App \ObjectManager::getInstance ()->get (MetadataPool::class);
4757 }
4858
4959 /**
@@ -81,17 +91,24 @@ public function removeDisabledProducts(array &$ids, $storeId)
8191 /* @var $statusAttribute \Magento\Eav\Model\Entity\Attribute */
8292 $ statusAttribute = $ this ->productIndexerHelper ->getAttribute ('status ' );
8393
94+ /** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
95+ $ metadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class);
96+
8497 $ select = $ this ->getSelectForProducts ($ ids );
8598 $ select ->joinLeft (
8699 ['status_global_attr ' => $ statusAttribute ->getBackendTable ()],
87100 ' 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 (),
89104 []
90105 );
91106 $ select ->joinLeft (
92107 ['status_attr ' => $ statusAttribute ->getBackendTable ()],
93108 ' 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 (),
95112 []
96113 );
97114 $ select ->where ('IFNULL(status_attr.value, status_global_attr.value) = ? ' , Status::STATUS_DISABLED );
0 commit comments