|
8 | 8 | use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
|
9 | 9 | use Magento\Catalog\Api\Data\ProductInterface;
|
10 | 10 | use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
| 11 | +use Magento\Framework\DB\Select; |
| 12 | +use Magento\Framework\DB\Sql\UnionExpression; |
11 | 13 |
|
12 | 14 | /**
|
13 | 15 | * Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
|
@@ -199,13 +201,48 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
|
199 | 201 | 'dd.attribute_id',
|
200 | 202 | 's.store_id',
|
201 | 203 | 'value' => new \Zend_Db_Expr('COALESCE(ds.value, dd.value)'),
|
202 |
| - 'cpe.entity_id', |
| 204 | + 'cpe.entity_id AS source_id', |
203 | 205 | ]
|
204 | 206 | );
|
205 | 207 |
|
206 | 208 | if ($entityIds !== null) {
|
207 | 209 | $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})"); |
208 | 237 | $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]); |
209 | 246 | }
|
210 | 247 |
|
211 | 248 | /**
|
@@ -342,7 +379,7 @@ private function getMultiSelectAttributeWithSourceModels($attrIds)
|
342 | 379 | ProductAttributeInterface::ENTITY_TYPE_CODE,
|
343 | 380 | $criteria
|
344 | 381 | )->getItems();
|
345 |
| - |
| 382 | + |
346 | 383 | $options = [];
|
347 | 384 | foreach ($attributes as $attribute) {
|
348 | 385 | $sourceModelOptions = $attribute->getOptions();
|
|
0 commit comments