Skip to content

Commit b9fee20

Browse files
author
Oleksandr Karpenko
committed
Merge remote-tracking branch 'origin/MAGETWO-44429' into BUGS
2 parents 35f9622 + deaada9 commit b9fee20

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,10 @@ public function reindex()
10861086
$flatIndexer->reindexRow($this->getId());
10871087
}
10881088
}
1089-
$affectedProductIds = $this->getAffectedProductIds();
10901089
$productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
1091-
if (!$productIndexer->isScheduled() && !empty($affectedProductIds)) {
1090+
if (!$productIndexer->isScheduled()
1091+
&& (!empty($this->getAffectedProductIds()) || $this->dataHasChangedFor('is_anchor'))
1092+
) {
10921093
$productIndexer->reindexList($this->getPathIds());
10931094
}
10941095
}

app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,37 @@ public function testReindexFlatEnabled($flatScheduled, $productScheduled, $expec
380380
public function reindexFlatDisabledTestDataProvider()
381381
{
382382
return [
383-
'set 1' => [false, 1],
384-
'set 2' => [true, 0],
383+
[false, null, null, null, 0],
384+
[true, null, null, null, 0],
385+
[false, [], null, null, 0],
386+
[false, ["1", "2"], null, null, 1],
387+
[false, null, 1, null, 1],
388+
[false, ["1", "2"], 0, 1, 1],
389+
[false, null, 1, 1, 0],
385390
];
386391
}
387392

388393
/**
389-
* @param $productScheduled
390-
* @param $expectedProductReindexCall
394+
* @param bool $productScheduled
395+
* @param array $affectedIds
396+
* @param int|string $isAnchorOrig
397+
* @param int|string $isAnchor
398+
* @param int $expectedProductReindexCall
391399
*
392400
* @dataProvider reindexFlatDisabledTestDataProvider
393401
*/
394-
public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall)
395-
{
396-
$affectedProductIds = ["1", "2"];
397-
$this->category->setAffectedProductIds($affectedProductIds);
402+
public function testReindexFlatDisabled(
403+
$productScheduled,
404+
$affectedIds,
405+
$isAnchorOrig,
406+
$isAnchor,
407+
$expectedProductReindexCall
408+
) {
409+
$this->category->setAffectedProductIds($affectedIds);
410+
$this->category->setData('is_anchor', $isAnchor);
411+
$this->category->setOrigData('is_anchor', $isAnchorOrig);
412+
$this->category->setAffectedProductIds($affectedIds);
413+
398414
$pathIds = ['path/1/2', 'path/2/3'];
399415
$this->category->setData('path_ids', $pathIds);
400416
$this->category->setId('123');
@@ -403,8 +419,12 @@ public function testReindexFlatDisabled($productScheduled, $expectedProductReind
403419
->method('isFlatEnabled')
404420
->will($this->returnValue(false));
405421

406-
$this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled));
407-
$this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds);
422+
$this->productIndexer->expects($this->exactly(1))
423+
->method('isScheduled')
424+
->willReturn($productScheduled);
425+
$this->productIndexer->expects($this->exactly($expectedProductReindexCall))
426+
->method('reindexList')
427+
->with($pathIds);
408428

409429
$this->indexerRegistry->expects($this->at(0))
410430
->method('get')

0 commit comments

Comments
 (0)