File tree 2 files changed +33
-13
lines changed
2 files changed +33
-13
lines changed Original file line number Diff line number Diff line change @@ -1132,19 +1132,21 @@ public function getIdentities()
1132
1132
{
1133
1133
$ identities = [];
1134
1134
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
+ }
1148
1150
}
1149
1151
1150
1152
return $ identities ;
Original file line number Diff line number Diff line change @@ -655,4 +655,22 @@ public function testGetIdentities()
655
655
$ category ->setId (42 );
656
656
$ this ->assertNotEmpty ($ category ->getIdentities ());
657
657
}
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
+ }
658
676
}
You can’t perform that action at this time.
0 commit comments