Skip to content

Commit f961681

Browse files
committed
MAGETWO-87526: URL rewrite for store is not created for child if parent category has non-default URL key on store
1 parent fd59087 commit f961681

File tree

2 files changed

+39
-1
lines changed
  • app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category
  • dev/tests/integration/testsuite/Magento/Catalog/Model

2 files changed

+39
-1
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function aroundSave(
9494
}
9595

9696
/**
97-
* Check is global scope
97+
* Check that store id is in global scope
9898
*
9999
* @param int|null $storeId
100100
* @return bool

dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,44 @@ public function testDeleteChildren()
320320
$this->assertEquals($this->_model->getId(), null);
321321
}
322322

323+
/**
324+
* @magentoDataFixture Magento/Store/_files/second_store.php
325+
* @magentoDataFixture Magento/Catalog/_files/categories.php
326+
* @magentoDbIsolation enabled
327+
*/
328+
public function testCreateSubcategoryWithMultipleStores()
329+
{
330+
$parentCategoryId = 3;
331+
$storeManager = $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
332+
$storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
333+
/** @var \Magento\Store\Api\StoreRepositoryInterface $storeRepository */
334+
$storeRepository = $this->objectManager->get(\Magento\Store\Api\StoreRepositoryInterface::class);
335+
$storeId = $storeRepository->get('fixture_second_store')->getId();
336+
/** @var \Magento\Catalog\Api\CategoryRepositoryInterface $repository */
337+
$repository = $this->objectManager->get(\Magento\Catalog\Api\CategoryRepositoryInterface::class);
338+
$parentCategory = $repository->get($parentCategoryId, $storeId);
339+
$parentAllStoresPath = $parentCategory->getUrlPath();
340+
$parentSecondStoreKey = 'parent-category-url-key-second-store';
341+
$parentCategory->setUrlKey($parentSecondStoreKey);
342+
$repository->save($parentCategory);
343+
/** @var \Magento\Catalog\Model\Category $childCategory */
344+
$childCategory = $this->objectManager->create(\Magento\Catalog\Model\Category::class);
345+
$childCategory->setName('Test Category 100')
346+
->setParentId($parentCategoryId)
347+
->setLevel(2)
348+
->setAvailableSortBy(['position', 'name'])
349+
->setDefaultSortBy('name')
350+
->setIsActive(true)
351+
->setPosition(1)
352+
->isObjectNew(true);
353+
$repository->save($childCategory);
354+
$childCategorySecondStore = $repository->get($childCategory->getId(), $storeId);
355+
356+
$this->assertEquals($parentAllStoresPath . '/test-category-100', $childCategory->getUrlPath());
357+
$this->assertEquals($parentSecondStoreKey . '/test-category-100', $childCategorySecondStore->getUrlPath());
358+
359+
}
360+
323361
protected function getCategoryByName($categoryName)
324362
{
325363
/* @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */

0 commit comments

Comments
 (0)