Skip to content

Commit f1a6a94

Browse files
MC-19916: Attribute not showing on layered navigation if no value set for "All Store Views"
1 parent 9b2cefd commit f1a6a94

File tree

1 file changed

+39
-2
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav

1 file changed

+39
-2
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
99
use Magento\Catalog\Api\Data\ProductInterface;
1010
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Framework\DB\Select;
12+
use Magento\Framework\DB\Sql\UnionExpression;
1113

1214
/**
1315
* Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
@@ -199,13 +201,48 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
199201
'dd.attribute_id',
200202
's.store_id',
201203
'value' => new \Zend_Db_Expr('COALESCE(ds.value, dd.value)'),
202-
'cpe.entity_id',
204+
'cpe.entity_id AS source_id',
203205
]
204206
);
205207

206208
if ($entityIds !== null) {
207209
$ids = implode(',', array_map('intval', $entityIds));
210+
$selectWithoutDefaultStore = $connection->select()->from(
211+
['wd' => $this->getTable('catalog_product_entity_int')],
212+
[
213+
$productIdField,
214+
'attribute_id',
215+
'store_id',
216+
'value',
217+
$productIdField
218+
]
219+
)->joinLeft(
220+
['d2d' => $this->getTable('catalog_product_entity_int')],
221+
sprintf(
222+
"d2d.store_id = 0 AND d2d.{$productIdField} = wd.{$productIdField} AND d2d.attribute_id = %s",
223+
$this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId()
224+
),
225+
[]
226+
)->joinLeft(
227+
['d2s' => $this->getTable('catalog_product_entity_int')],
228+
"d2s.store_id != 0 AND d2s.attribute_id = d2d.attribute_id AND " .
229+
"d2s.{$productIdField} = d2d.{$productIdField}",
230+
[]
231+
)
232+
->where((new \Zend_Db_Expr('COALESCE(d2s.value, d2d.value)')) . ' = ' . ProductStatus::STATUS_ENABLED)
233+
->where("wd.attribute_id IN({$attrIdsFlat})")
234+
->where('wd.value IS NOT NULL')
235+
->where('wd.store_id != 0')
236+
->where("wd.{$productIdField} IN({$ids})");
208237
$select->where("cpe.entity_id IN({$ids})");
238+
$selects = new UnionExpression(
239+
[$select, $selectWithoutDefaultStore],
240+
Select::SQL_UNION,
241+
'( %s )'
242+
);
243+
244+
$select = $connection->select();
245+
$select->from(['u' => $selects]);
209246
}
210247

211248
/**
@@ -342,7 +379,7 @@ private function getMultiSelectAttributeWithSourceModels($attrIds)
342379
ProductAttributeInterface::ENTITY_TYPE_CODE,
343380
$criteria
344381
)->getItems();
345-
382+
346383
$options = [];
347384
foreach ($attributes as $attribute) {
348385
$sourceModelOptions = $attribute->getOptions();

0 commit comments

Comments
 (0)