Skip to content

Commit b0f19b7

Browse files
author
Roman Ganin
committed
Merge remote-tracking branch 'origin/MAGETWO-33583' into Troll_S31
2 parents d2ad717 + c267725 commit b0f19b7

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,12 @@ public function eavReindexCallback()
836836
public function reindex()
837837
{
838838
if ($this->_catalogProduct->isDataForProductCategoryIndexerWasChanged($this) || $this->isDeleted()) {
839-
$this->_productFlatIndexerProcessor->reindexRow($this->getEntityId());
840-
$categoryIndexer = $this->indexerRegistry->get(Indexer\Product\Category::INDEXER_ID);
841-
if (!$categoryIndexer->isScheduled()) {
842-
$categoryIndexer->reindexRow($this->getId());
839+
$productCategoryIndexer = $this->indexerRegistry->get(Indexer\Product\Category::INDEXER_ID);
840+
if (!$productCategoryIndexer->isScheduled()) {
841+
$productCategoryIndexer->reindexRow($this->getId());
843842
}
844843
}
844+
$this->_productFlatIndexerProcessor->reindexRow($this->getEntityId());
845845
}
846846

847847
/**
@@ -2013,7 +2013,12 @@ public function getIdentities()
20132013
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
20142014
}
20152015
}
2016-
return $identities;
2016+
if ($this->getOrigData('status') > $this->getData('status')) {
2017+
foreach ($this->getData('category_ids') as $categoryId) {
2018+
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2019+
}
2020+
}
2021+
return array_unique($identities);
20172022
}
20182023

20192024
/**

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<item name="entity_id" xsi:type="string">entity_id</item>
9090
<item name="store_id" xsi:type="string">store_id</item>
9191
<item name="visibility" xsi:type="string">visibility</item>
92+
<item name="status" xsi:type="string">status</item>
9293
</item>
9394
</argument>
9495
<argument name="productRepository" xsi:type="object">Magento\Catalog\Api\ProductRepositoryInterface\Proxy</argument>

dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,20 @@ public function testIndexerAfterDeleteCommitProduct()
383383
public function testReindex($productChanged, $isScheduled, $productFlatCount, $categoryIndexerCount)
384384
{
385385
$this->model->setData('entity_id', 1);
386-
$this->_catalogProduct->expects($this->once())->method('isDataForProductCategoryIndexerWasChanged')->willReturn($productChanged);
386+
$this->_catalogProduct->expects($this->once())
387+
->method('isDataForProductCategoryIndexerWasChanged')
388+
->willReturn($productChanged);
389+
if ($productChanged) {
390+
$this->indexerRegistryMock->expects($this->exactly($productFlatCount))
391+
->method('get')
392+
->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)
393+
->will($this->returnValue($this->categoryIndexerMock));
394+
$this->categoryIndexerMock->expects($this->any())
395+
->method('isScheduled')
396+
->will($this->returnValue($isScheduled));
397+
$this->categoryIndexerMock->expects($this->exactly($categoryIndexerCount))->method('reindexRow');
398+
}
387399
$this->productFlatProcessor->expects($this->exactly($productFlatCount))->method('reindexRow');
388-
$this->indexerRegistryMock->expects($this->exactly($productFlatCount))
389-
->method('get')
390-
->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)
391-
->will($this->returnValue($this->categoryIndexerMock));
392-
$this->categoryIndexerMock->expects($this->any())->method('isScheduled')->will($this->returnValue($isScheduled));
393-
$this->categoryIndexerMock->expects($this->exactly($categoryIndexerCount))->method('reindexRow');
394-
395400
$this->model->reindex();
396401
}
397402

@@ -400,7 +405,7 @@ public function getProductReindexProvider()
400405
return array(
401406
'set 1' => [true, false, 1, 1],
402407
'set 2' => [true, true, 1, 0],
403-
'set 3' => [false, false, 0, 0]
408+
'set 3' => [false, false, 1, 0]
404409
);
405410
}
406411

@@ -465,6 +470,21 @@ public function getIdentitiesProvider()
465470
'affected_category_ids' => [1],
466471
'is_changed_categories' => true
467472
]
473+
],
474+
[
475+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
476+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
477+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
478+
],
479+
[
480+
[0 => 'catalog_product_1'],
481+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
482+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
483+
],
484+
[
485+
[0 => 'catalog_product_1'],
486+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
487+
['id' => 1, 'name' => 'value', 'category_ids' => [], 'status' => 1],
468488
]
469489
];
470490
}

0 commit comments

Comments
 (0)