Skip to content

Commit 49bd88e

Browse files
author
Alexander Akimov
authored
Merge pull request #2275 from magento-tsg/2.1.13-develop-pr49
[TSG] Backporting for 2.1 (pr49) (2.1.13)
2 parents 992a17f + 34b6183 commit 49bd88e

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,19 +1132,21 @@ public function getIdentities()
11321132
{
11331133
$identities = [];
11341134
if ($this->getId()) {
1135-
$identities[] = self::CACHE_TAG . '_' . $this->getId();
1136-
}
1137-
if ($this->getId()
1138-
&& (
1139-
$this->hasDataChanges()
1140-
|| $this->isDeleted()
1141-
|| $this->dataHasChangedFor(self::KEY_INCLUDE_IN_MENU)
1142-
)
1143-
) {
1144-
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
1145-
}
1146-
if ($this->getId() && $this->isObjectNew()) {
1147-
$identities[] = self::CACHE_TAG;
1135+
if ($this->getAffectedCategoryIds()) {
1136+
foreach (array_unique($this->getAffectedCategoryIds()) as $affectedCategoryId) {
1137+
$identities[] = self::CACHE_TAG . '_' . $affectedCategoryId;
1138+
}
1139+
} else {
1140+
$identities[] = self::CACHE_TAG . '_' . $this->getId();
1141+
}
1142+
1143+
if ($this->hasDataChanges() || $this->isDeleted() || $this->dataHasChangedFor(self::KEY_INCLUDE_IN_MENU)) {
1144+
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
1145+
}
1146+
1147+
if ($this->isObjectNew()) {
1148+
$identities[] = self::CACHE_TAG;
1149+
}
11481150
}
11491151

11501152
return $identities;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,4 +655,22 @@ public function testGetIdentities()
655655
$category->setId(42);
656656
$this->assertNotEmpty($category->getIdentities());
657657
}
658+
659+
/**
660+
* @return void
661+
*/
662+
public function testGetIdentitiesWithAffectedCategories()
663+
{
664+
$category = $this->getCategoryModel();
665+
$expectedIdentities = [
666+
'catalog_category_1',
667+
'catalog_category_2',
668+
'catalog_category_3',
669+
'catalog_category_product_1',
670+
];
671+
$category->setId(1);
672+
$category->setAffectedCategoryIds([1,2,3]);
673+
674+
$this->assertEquals($expectedIdentities, $category->getIdentities());
675+
}
658676
}

0 commit comments

Comments
 (0)