Skip to content

Commit ac1ac06

Browse files
Barny ShergoldBarny Shergold
authored andcommitted
Corrected issue causing integration test to fail when category move is tested
1 parent a6d1976 commit ac1ac06

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlPathGenerator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ public function getUrlPath($category, $parentCategory = null)
7373
if (in_array($category->getParentId(), [Category::ROOT_CATEGORY_ID, Category::TREE_ROOT_ID])) {
7474
return '';
7575
}
76-
$path = $category->getUrlPath();
77-
if ($path !== null && !$category->dataHasChangedFor('url_key') && !$category->dataHasChangedFor('parent_id')) {
78-
return $path;
79-
}
76+
8077
$path = $category->getUrlKey();
8178
if ($path === false) {
8279
return $category->getUrlPath();

app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ
177177
continue;
178178
}
179179

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);
183181
}
184182

185183
$productCategories = $this->objectRegistryFactory->create(['entities' => $categories]);
@@ -238,6 +236,35 @@ public function isCategoryProperForGenerating(Category $category, $storeId)
238236
return false;
239237
}
240238

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+
241268
/**
242269
* Check config value of generate_category_product_rewrites
243270
*

0 commit comments

Comments
 (0)