Skip to content

Commit

Permalink
GITHUB-8970: Cannot assign products to categories not under tree root.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Oct 30, 2017
1 parent f0be8db commit de5990a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ
*/
public function isCategoryProperForGenerating(Category $category, $storeId)
{
$parentId = $category->getParentId();
if ($parentId != Category::ROOT_CATEGORY_ID && $parentId != Category::TREE_ROOT_ID) {
list(, $rootCategoryId) = $category->getParentIds();
$parentIds = $category->getParentIds();
if (count($parentIds) >= 2) {
$rootCategoryId = $parentIds[1];
return $rootCategoryId == $this->storeManager->getStore($storeId)->getRootCategoryId();
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ public function testGenerationForGlobalScope()
$product->expects($this->any())->method('getStoreIds')->will($this->returnValue([1]));
$this->storeViewService->expects($this->once())->method('doesEntityHaveOverriddenUrlKeyForStore')
->will($this->returnValue(false));
$this->categoryMock->expects($this->once())
->method('getParentId')
->willReturn(2);
$this->initObjectRegistryFactory([]);
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
$canonical->setRequestPath('category-1')
Expand Down Expand Up @@ -161,14 +158,12 @@ public function testGenerationForGlobalScope()
public function testGenerationForSpecificStore()
{
$storeRootCategoryId = 2;
$parent_id = 3;
$category_id = 4;
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
$product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
$product->expects($this->never())->method('getStoreIds');
$this->categoryMock->expects($this->any())->method('getParentIds')
->will($this->returnValue(['root-id', $storeRootCategoryId]));
$this->categoryMock->expects($this->any())->method('getParentId')->will($this->returnValue($parent_id));
$this->categoryMock->expects($this->any())->method('getId')->will($this->returnValue($category_id));
$this->initObjectRegistryFactory([$this->categoryMock]);
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
Expand Down Expand Up @@ -219,15 +214,13 @@ protected function initObjectRegistryFactory($entities)
/**
* Test the possibility of url rewrite generation.
*
* @param int $parentId
* @param array $parentIds
* @param bool $expectedResult
* @dataProvider isCategoryProperForGeneratingDataProvider
*/
public function testIsCategoryProperForGenerating($parentId, $parentIds, $expectedResult)
public function testIsCategoryProperForGenerating($parentIds, $expectedResult)
{
$storeId = 1;
$this->categoryMock->expects(self::any())->method('getParentId')->willReturn($parentId);
$this->categoryMock->expects(self::any())->method('getParentIds')->willReturn($parentIds);
$result = $this->productScopeGenerator->isCategoryProperForGenerating(
$this->categoryMock,
Expand All @@ -247,10 +240,10 @@ public function testIsCategoryProperForGenerating($parentId, $parentIds, $expect
public function isCategoryProperForGeneratingDataProvider()
{
return [
['0', ['0'], false],
['1', ['1'], false],
['2', ['1', '2'], true],
['2', ['1', '3'], false],
[['0'], false],
[['1'], false],
[['1', '2'], true],
[['1', '3'], false],
];
}
}

0 comments on commit de5990a

Please sign in to comment.