Skip to content

Commit e9c2d0b

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-62495_MAGETWO-96846' into EPAM-PR-37
2 parents b2d4e12 + c6a24d6 commit e9c2d0b

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,15 @@ public function reindex()
11241124
}
11251125
}
11261126
$productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
1127-
if (!$productIndexer->isScheduled()
1128-
&& (!empty($this->getAffectedProductIds()) || $this->dataHasChangedFor('is_anchor'))
1129-
) {
1130-
$productIndexer->reindexList($this->getPathIds());
1127+
1128+
if (!empty($this->getAffectedProductIds())
1129+
|| $this->dataHasChangedFor('is_anchor')
1130+
|| $this->dataHasChangedFor('is_active')) {
1131+
if (!$productIndexer->isScheduled()) {
1132+
$productIndexer->reindexList($this->getPathIds());
1133+
} else {
1134+
$productIndexer->invalidate();
1135+
}
11311136
}
11321137
}
11331138

@@ -1152,9 +1157,17 @@ public function getIdentities()
11521157
$identities = [
11531158
self::CACHE_TAG . '_' . $this->getId(),
11541159
];
1160+
11551161
if ($this->hasDataChanges()) {
11561162
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
11571163
}
1164+
1165+
if ($this->dataHasChangedFor('is_anchor') || $this->dataHasChangedFor('is_active')) {
1166+
foreach ($this->getPathIds() as $id) {
1167+
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $id;
1168+
}
1169+
}
1170+
11581171
if (!$this->getId() || $this->isDeleted() || $this->dataHasChangedFor(self::KEY_INCLUDE_IN_MENU)) {
11591172
$identities[] = self::CACHE_TAG;
11601173
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="ProductAvailableAfterEnablingSubCategoriesTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<title value="Check that parent categories are showing products after enabling subcategories after fully reindex"/>
15+
<description value="Check that parent categories are showing products after enabling subcategories after fully reindex"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-97370"/>
18+
<useCaseId value="MAGETWO-96846"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
<before>
22+
<createData entity="ApiCategory" stepKey="createCategory"/>
23+
<createData entity="SubCategoryWithParent" stepKey="simpleSubCategory">
24+
<requiredEntity createDataKey="createCategory"/>
25+
<field key="is_active">false</field>
26+
</createData>
27+
<createData entity="ApiSimpleProduct" stepKey="createSimpleProduct">
28+
<requiredEntity createDataKey="simpleSubCategory"/>
29+
</createData>
30+
31+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
32+
</before>
33+
<after>
34+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
35+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
36+
<actionGroup ref="logout" stepKey="logout"/>
37+
</after>
38+
39+
<amOnPage url="$$createCategory.name$$.html" stepKey="goToCategoryStorefront2"/>
40+
<waitForPageLoad stepKey="waitForCategoryStorefront"/>
41+
<dontSeeElement selector="{{StorefrontCategoryProductSection.ProductImageByName($$createSimpleProduct.name$$)}}" stepKey="dontSeeCreatedProduct"/>
42+
<amOnPage url="{{AdminCategoryPage.url}}" stepKey="onCategoryIndexPage"/>
43+
<waitForPageLoad stepKey="waitForCategoryPageLoadAddProducts"/>
44+
<click selector="{{AdminCategorySidebarTreeSection.expandAll}}" stepKey="expandAll"/>
45+
<click selector="{{AdminCategorySidebarTreeSection.categoryInTree($$simpleSubCategory.name$$)}}" stepKey="clickOnCreatedSimpleSubCategoryBeforeDelete"/>
46+
<waitForPageLoad stepKey="AdminCategoryEditPageLoad"/>
47+
<click selector="{{AdminCategoryBasicFieldSection.enableCategoryLabel}}" stepKey="EnableCategory"/>
48+
<click selector="{{AdminCategoryMainActionsSection.SaveButton}}" stepKey="saveCategoryWithProducts"/>
49+
<waitForPageLoad stepKey="waitForCategorySaved"/>
50+
<see userInput="You saved the category." stepKey="seeSuccessMessage"/>
51+
<amOnPage url="$$createCategory.name$$.html" stepKey="goToCategoryStorefront"/>
52+
<waitForPageLoad stepKey="waitForCategoryStorefrontPage"/>
53+
<seeElement selector="{{StorefrontCategoryProductSection.ProductImageByName($$createSimpleProduct.name$$)}}" stepKey="seeCreatedProduct"/>
54+
</test>
55+
</tests>

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,16 @@ public function testReindexFlatEnabled(
383383
public function reindexFlatDisabledTestDataProvider()
384384
{
385385
return [
386-
[false, null, null, null, 0],
387-
[true, null, null, null, 0],
388-
[false, [], null, null, 0],
389-
[false, ["1", "2"], null, null, 1],
390-
[false, null, 1, null, 1],
391-
[false, ["1", "2"], 0, 1, 1],
392-
[false, null, 1, 1, 0],
386+
[false, null, null, null, null, null, 0],
387+
[true, null, null, null, null, null, 0],
388+
[false, [], null, null, null, null, 0],
389+
[false, ["1", "2"], null, null, null, null, 1],
390+
[false, null, 1, null, null, null, 1],
391+
[false, ["1", "2"], 0, 1, null, null, 1],
392+
[false, null, 1, 1, null, null, 0],
393+
[false, ["1", "2"], null, null, 0, 1, 1],
394+
[false, ["1", "2"], null, null, 1, 0, 1],
395+
393396
];
394397
}
395398

@@ -407,11 +410,16 @@ public function testReindexFlatDisabled(
407410
$affectedIds,
408411
$isAnchorOrig,
409412
$isAnchor,
413+
$isActiveOrig,
414+
$isActive,
410415
$expectedProductReindexCall
411416
) {
412417
$this->category->setAffectedProductIds($affectedIds);
413418
$this->category->setData('is_anchor', $isAnchor);
414419
$this->category->setOrigData('is_anchor', $isAnchorOrig);
420+
$this->category->setData('is_active', $isActive);
421+
$this->category->setOrigData('is_active', $isActiveOrig);
422+
415423
$this->category->setAffectedProductIds($affectedIds);
416424

417425
$pathIds = ['path/1/2', 'path/2/3'];
@@ -422,7 +430,7 @@ public function testReindexFlatDisabled(
422430
->method('isFlatEnabled')
423431
->will($this->returnValue(false));
424432

425-
$this->productIndexer->expects($this->exactly(1))
433+
$this->productIndexer
426434
->method('isScheduled')
427435
->willReturn($productScheduled);
428436
$this->productIndexer->expects($this->exactly($expectedProductReindexCall))

0 commit comments

Comments
 (0)