Skip to content

Commit 0eb6f20

Browse files
committed
MAGETWO-51732: Catalog product "Use default" check problems causing data loss when updating product on non default site
- fix test Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceTest testReindexEntitiesForConfigurableProduct History
1 parent 6314b4e commit 0eb6f20

File tree

1 file changed

+17
-16
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav

1 file changed

+17
-16
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,32 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
125125
['s' => $this->getTable('store')],
126126
['store_id', 'website_id']
127127
)->joinLeft(
128-
['d' => $this->getTable('catalog_product_entity_int')],
129-
'd.store_id = 0 OR d.store_id = s.store_id',
130-
['attribute_id', 'value']
128+
['dd' => $this->getTable('catalog_product_entity_int')],
129+
'dd.store_id = 0',
130+
['attribute_id']
131131
)->joinLeft(
132-
['d2' => $this->getTable('catalog_product_entity_int')],
133-
sprintf(
134-
"d.{$productIdField} = d2.{$productIdField}"
135-
. ' AND d2.attribute_id = %s AND d2.value = %s AND d.store_id = d2.store_id',
136-
$this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId(),
137-
ProductStatus::STATUS_ENABLED
138-
),
132+
['ds' => $this->getTable('catalog_product_entity_int')],
133+
"ds.store_id = s.store_id AND ds.attribute_id = dd.attribute_id AND ds.{$productIdField} = dd.{$productIdField}",
134+
['value' => new \Zend_Db_Expr('COALESCE(ds.value, dd.value)')]
135+
)->joinLeft(
136+
['d2d' => $this->getTable('catalog_product_entity_int')],
137+
sprintf("d2d.store_id = 0 AND d2d.{$productIdField} = dd.{$productIdField} AND d2d.attribute_id = %s", $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId()),
138+
[]
139+
)->joinLeft(
140+
['d2s' => $this->getTable('catalog_product_entity_int')],
141+
"d2s.store_id = s.store_id AND d2s.attribute_id = d2d.attribute_id AND d2s.{$productIdField} = d2d.{$productIdField}",
139142
[]
140143
)->joinLeft(
141144
['cpe' => $this->getTable('catalog_product_entity')],
142-
"cpe.{$productIdField} = d.{$productIdField}",
145+
"cpe.{$productIdField} = dd.{$productIdField}",
143146
array_unique([$productIdField, 'entity_id'])
144147
)->where(
145148
's.store_id != 0'
146149
)->where(
147-
'd.value IS NOT NULL'
150+
'(ds.value IS NOT NULL OR dd.value IS NOT NULL)'
148151
)->where(
149-
'd2.value IS NOT NULL'
150-
)->group([
151-
's.store_id', 's.website_id', 'cpe.entity_id', 'd.attribute_id', 'd.value',
152-
]);
152+
(new \Zend_Db_Expr('COALESCE(d2s.value, d2d.value)')) . ' = ' . ProductStatus::STATUS_ENABLED
153+
)->distinct(true);
153154

154155
if ($entityIds !== null) {
155156
$subSelect->where('cpe.entity_id IN(?)', $entityIds);

0 commit comments

Comments
 (0)