Skip to content

Commit b22150c

Browse files
committed
Merge branch 'MAGETWO-71662-2' into 2.2-develop-PR-2
2 parents fd2f74b + bc3d848 commit b22150c

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function reindexEntities($processIds)
8282
$this->_prepareIndex($processIds);
8383
$this->_prepareRelationIndex($processIds);
8484
$this->_removeNotVisibleEntityFromIndex();
85+
8586
return $this;
8687
}
8788

@@ -164,6 +165,7 @@ protected function _prepareRelationIndexSelect($parentIds = null)
164165
$connection = $this->getConnection();
165166
$idxTable = $this->getIdxTable();
166167
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
168+
167169
$select = $connection->select()->from(
168170
['l' => $this->getTable('catalog_product_relation')],
169171
[]
@@ -179,6 +181,16 @@ protected function _prepareRelationIndexSelect($parentIds = null)
179181
['i' => $idxTable],
180182
'l.child_id = i.entity_id AND cs.store_id = i.store_id',
181183
[]
184+
)->join(
185+
['sw' => $this->getTable('store_website')],
186+
"cs.website_id = sw.website_id",
187+
[]
188+
)->joinLeft(
189+
['cpw' => $this->getTable('catalog_product_website')],
190+
"i.entity_id = cpw.product_id AND sw.website_id = cpw.website_id",
191+
[]
192+
)->where(
193+
'cpw.product_id IS NOT NULL'
182194
)->group(
183195
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value', 'l.child_id']
184196
)->columns(

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,20 @@ public function testReindexWithoutArgumentsExecutesReindexAll()
113113
$this->_model->reindex();
114114
}
115115

116-
public function testReindexWithNotNullArgumentExecutesReindexEntities()
117-
{
118-
$childIds = [1, 2, 3];
119-
$parentIds = [4];
120-
$reindexIds = array_merge($childIds, $parentIds);
116+
/**
117+
* @param array $ids
118+
* @param array $parentIds
119+
* @param array $childIds
120+
* @throws \Exception
121+
* @dataProvider reindexEntitiesDataProvider
122+
*/
123+
public function testReindexWithNotNullArgumentExecutesReindexEntities(
124+
array $ids,
125+
array $parentIds,
126+
array $childIds
127+
) {
128+
$reindexIds = array_unique(array_merge($ids, $parentIds, $childIds));
129+
121130
$connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
122131
->getMockForAbstractClass();
123132

@@ -129,12 +138,23 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities()
129138
->disableOriginalConstructor()
130139
->getMock();
131140

132-
$eavSource->expects($this->once())->method('getRelationsByChild')->with($childIds)->willReturn($parentIds);
133-
$eavSource->expects($this->once())->method('getRelationsByParent')
134-
->with(array_unique(array_merge($parentIds, $childIds)))->willReturn($parentIds);
141+
$eavSource->expects($this->once())
142+
->method('getRelationsByChild')
143+
->with($ids)
144+
->willReturn($parentIds);
145+
$eavSource->expects($this->once())
146+
->method('getRelationsByParent')
147+
->with(array_unique(array_merge($parentIds, $ids)))
148+
->willReturn($childIds);
135149

136-
$eavDecimal->expects($this->once())->method('getRelationsByChild')->with($reindexIds)->willReturn($reindexIds);
137-
$eavDecimal->expects($this->once())->method('getRelationsByParent')->with($reindexIds)->willReturn([]);
150+
$eavDecimal->expects($this->once())
151+
->method('getRelationsByChild')
152+
->with($reindexIds)
153+
->willReturn($parentIds);
154+
$eavDecimal->expects($this->once())
155+
->method('getRelationsByParent')
156+
->with(array_unique(array_merge($parentIds, $reindexIds)))
157+
->willReturn($childIds);
138158

139159
$eavSource->expects($this->once())->method('getConnection')->willReturn($connectionMock);
140160
$eavDecimal->expects($this->once())->method('getConnection')->willReturn($connectionMock);
@@ -154,6 +174,15 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities()
154174
->method('create')
155175
->will($this->returnValue($eavDecimal));
156176

157-
$this->_model->reindex($childIds);
177+
$this->_model->reindex($ids);
178+
}
179+
180+
public function reindexEntitiesDataProvider()
181+
{
182+
return [
183+
[[4], [], [1, 2, 3]],
184+
[[3], [4], []],
185+
[[5], [], []]
186+
];
158187
}
159188
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ public function testReindexEntitiesForConfigurableProduct()
9696

9797
$result = $connection->fetchAll($select);
9898
$this->assertCount(0, $result);
99+
100+
/** @var \Magento\Catalog\Model\Product $product1 **/
101+
$product1 = $productRepository->getById(10);
102+
$product1->setStatus(Status::STATUS_ENABLED)->setWebsiteIds([]);
103+
$productRepository->save($product1);
104+
105+
/** @var \Magento\Catalog\Model\Product $product2 **/
106+
$product2 = $productRepository->getById(20);
107+
$product2->setStatus(Status::STATUS_ENABLED);
108+
$productRepository->save($product2);
109+
110+
$result = $connection->fetchAll($select);
111+
$this->assertCount(1, $result);
99112
}
100113

101114
/**

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
525525
*/
526526
public function testAdvancedSearchCompositeProductWithOutOfStockOption()
527527
{
528-
$this->markTestSkipped('MAGETWO-71445: configurable product created incorrectly - children not linked').
529528
/** @var Attribute $attribute */
530529
$attribute = $this->objectManager->get(Attribute::class)
531530
->loadByCode(Product::ENTITY, 'test_configurable');

0 commit comments

Comments
 (0)