@@ -177,9 +177,7 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ
177
177
continue ;
178
178
}
179
179
180
- // Category should be loaded per appropriate store at all times. This is because whilst the URL key on the
181
- // category in focus might be unchanged, parent category URL keys might be
182
- $ categories [] = $ this ->categoryRepository ->get ($ category ->getEntityId (), $ storeId );
180
+ $ categories [] = $ this ->getCategoryWithOverriddenUrlKey ($ storeId , $ category );
183
181
}
184
182
185
183
$ productCategories = $ this ->objectRegistryFactory ->create (['entities ' => $ categories ]);
@@ -238,6 +236,35 @@ public function isCategoryProperForGenerating(Category $category, $storeId)
238
236
return false ;
239
237
}
240
238
239
+ /**
240
+ * Check if URL key has been changed
241
+ *
242
+ * Checks if URL key has been changed for provided category and returns reloaded category,
243
+ * in other case - returns provided category.
244
+ *
245
+ * @param int $storeId
246
+ * @param Category $category
247
+ * @return Category
248
+ */
249
+ private function getCategoryWithOverriddenUrlKey ($ storeId , Category $ category )
250
+ {
251
+ $ isUrlKeyOverridden = $ this ->storeViewService ->doesEntityHaveOverriddenUrlKeyForStore (
252
+ $ storeId ,
253
+ $ category ->getEntityId (),
254
+ Category::ENTITY
255
+ );
256
+
257
+ // Category should be loaded per appropriate store at all times. This is because whilst the URL key on the
258
+ // category in focus might be unchanged, parent category URL keys might be. If the category store ID
259
+ // and passed store ID are the same then return current category as it is correct but may have changed in memory
260
+
261
+ if (!$ isUrlKeyOverridden && $ storeId == $ category ->getStoreId ()) {
262
+ return $ category ;
263
+ }
264
+
265
+ return $ this ->categoryRepository ->get ($ category ->getEntityId (), $ storeId );
266
+ }
267
+
241
268
/**
242
269
* Check config value of generate_category_product_rewrites
243
270
*
0 commit comments