Skip to content

Commit 82c9186

Browse files
committed
Merge remote-tracking branch 'origin/MC-32810' into 2.3-develop-pr41
2 parents f523c38 + 27e5b42 commit 82c9186

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
use Magento\Catalog\Model\Product;
99
use Magento\Catalog\Model\Product\Visibility;
10+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1011

1112
/**
12-
* Class ProductUrlRewriteGenerator
13-
* @package Magento\CatalogUrlRewrite\Model
13+
* Class to generate product url path
1414
*/
1515
class CategoryProductUrlPathGenerator
1616
{
@@ -31,9 +31,9 @@ public function __construct(
3131
/**
3232
* Generate product url rewrites based on all product categories
3333
*
34-
* @param \Magento\Catalog\Model\Product $product
34+
* @param Product $product
3535
* @param int|null $rootCategoryId
36-
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
36+
* @return UrlRewrite[]
3737
*/
3838
public function generate(Product $product, $rootCategoryId = null)
3939
{
@@ -44,6 +44,7 @@ public function generate(Product $product, $rootCategoryId = null)
4444
$storeId = $product->getStoreId();
4545

4646
$productCategories = $product->getCategoryCollection()
47+
->setStoreId($storeId)
4748
->addAttributeToSelect('url_key')
4849
->addAttributeToSelect('url_path');
4950

app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function generate($storeId, Product $product, ObjectRegistry $productCate
6767
$anchorCategoryIds = $category->getAnchorsAbove();
6868
if ($anchorCategoryIds) {
6969
foreach ($anchorCategoryIds as $anchorCategoryId) {
70-
$anchorCategory = $this->categoryRepository->get($anchorCategoryId);
70+
$anchorCategory = $this->categoryRepository->get($anchorCategoryId, $storeId);
7171
if ((int)$anchorCategory->getParentId() === Category::TREE_ROOT_ID) {
7272
continue;
7373
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryProductUrlPathGeneratorTest.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
*/
66
namespace Magento\CatalogUrlRewrite\Test\Unit\Model;
77

8-
use Magento\Catalog\Model\Category;
98
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1010
use Magento\CatalogUrlRewrite\Model\CategoryProductUrlPathGenerator;
1111
use Magento\CatalogUrlRewrite\Model\ProductScopeRewriteGenerator;
12-
use Magento\Catalog\Model\ResourceModel\Category\Collection;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
1314

1415
/**
15-
* Class CategoryProductUrlPathGeneratorTest
16+
* Class test generate product url path
1617
*/
17-
class CategoryProductUrlPathGeneratorTest extends \PHPUnit\Framework\TestCase
18+
class CategoryProductUrlPathGeneratorTest extends TestCase
1819
{
1920
/**
20-
* @var ProductScopeRewriteGenerator|\PHPUnit_Framework_MockObject_MockObject
21+
* @var ProductScopeRewriteGenerator|MockObject
2122
*/
2223
private $productScopeRewriteGeneratorMock;
2324

@@ -26,6 +27,9 @@ class CategoryProductUrlPathGeneratorTest extends \PHPUnit\Framework\TestCase
2627
*/
2728
private $generator;
2829

30+
/**
31+
* @inheritdoc
32+
*/
2933
public function setUp()
3034
{
3135
$this->productScopeRewriteGeneratorMock = $this->getMockBuilder(ProductScopeRewriteGenerator::class)
@@ -37,11 +41,16 @@ public function setUp()
3741
);
3842
}
3943

44+
/**
45+
* Test to generate product url rewrites based on all product categories on global scope
46+
*/
4047
public function testGenerationWithGlobalScope()
4148
{
49+
/** @var Collection|MockObject $categoryCollectionMock */
4250
$categoryCollectionMock = $this->getMockBuilder(Collection::class)
4351
->disableOriginalConstructor()
4452
->getMock();
53+
/** @var Product|MockObject $productMock */
4554
$productMock = $this->getMockBuilder(Product::class)
4655
->disableOriginalConstructor()
4756
->getMock();
@@ -58,6 +67,10 @@ public function testGenerationWithGlobalScope()
5867
$productMock->expects($this->once())
5968
->method('getCategoryCollection')
6069
->willReturn($categoryCollectionMock);
70+
$categoryCollectionMock->expects($this->once())
71+
->method('setStoreId')
72+
->with($storeId)
73+
->willReturnSelf();
6174
$categoryCollectionMock->expects($this->atLeastOnce())
6275
->method('addAttributeToSelect')
6376
->willReturnSelf();
@@ -74,11 +87,16 @@ public function testGenerationWithGlobalScope()
7487
$this->assertEquals($urls, $this->generator->generate($productMock, $categoryId));
7588
}
7689

90+
/**
91+
* Test to generate product url rewrites based on all product categories on specific store
92+
*/
7793
public function testGenerationWithSpecificStore()
7894
{
95+
/** @var Collection|MockObject $categoryCollectionMock */
7996
$categoryCollectionMock = $this->getMockBuilder(Collection::class)
8097
->disableOriginalConstructor()
8198
->getMock();
99+
/** @var Product|MockObject $productMock */
82100
$productMock = $this->getMockBuilder(Product::class)
83101
->disableOriginalConstructor()
84102
->getMock();
@@ -95,6 +113,10 @@ public function testGenerationWithSpecificStore()
95113
$productMock->expects($this->once())
96114
->method('getCategoryCollection')
97115
->willReturn($categoryCollectionMock);
116+
$categoryCollectionMock->expects($this->once())
117+
->method('setStoreId')
118+
->with($storeId)
119+
->willReturnSelf();
98120
$categoryCollectionMock->expects($this->atLeastOnce())
99121
->method('addAttributeToSelect')
100122
->willReturnSelf();

0 commit comments

Comments
 (0)