-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG - Prevent Magento from Creating incorrect URLs for category/products when Store View has modified URL keys #28676
Changes from 4 commits
3409af0
a6d1976
ac1ac06
e100822
d59d740
0097625
7ee8e09
54457b4
aea1d8e
5d9ce4d
87a4fd9
ec3e6da
7a6a740
7f41733
4b9f004
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
|
||
/** | ||
* Class ProductScopeRewriteGenerator | ||
* | ||
* Generates Product/Category URLs for different scopes | ||
* | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class ProductScopeRewriteGenerator | ||
|
@@ -174,7 +177,6 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ | |
continue; | ||
} | ||
|
||
// category should be loaded per appropriate store if category's URL key has been changed | ||
$categories[] = $this->getCategoryWithOverriddenUrlKey($storeId, $category); | ||
} | ||
|
||
|
@@ -252,9 +254,14 @@ private function getCategoryWithOverriddenUrlKey($storeId, Category $category) | |
Category::ENTITY | ||
); | ||
|
||
if (!$isUrlKeyOverridden) { | ||
// Category should be loaded per appropriate store at all times. This is because whilst the URL key on the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use PHP Doc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// category in focus might be unchanged, parent category URL keys might be. If the category store ID | ||
// and passed store ID are the same then return current category as it is correct but may have changed in memory | ||
|
||
if (!$isUrlKeyOverridden && $storeId == $category->getStoreId()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use '===' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return $category; | ||
} | ||
|
||
return $this->categoryRepository->get($category->getEntityId(), $storeId); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
namespace Magento\CatalogUrlRewrite\Test\Unit\Model; | ||
|
||
use Magento\Catalog\Api\CategoryRepositoryInterface; | ||
use Magento\Catalog\Model\Category; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\CatalogUrlRewrite\Model\ObjectRegistry; | ||
|
@@ -69,6 +70,9 @@ class ProductScopeRewriteGeneratorTest extends TestCase | |
/** @var ScopeConfigInterface|MockObject */ | ||
private $configMock; | ||
|
||
/** @var CategoryRepositoryInterface|MockObject */ | ||
private $categoryRepository; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suffix with 'Mock' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
protected function setUp(): void | ||
{ | ||
$this->serializer = $this->createMock(Json::class); | ||
|
@@ -126,6 +130,8 @@ function ($value) { | |
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) | ||
->getMock(); | ||
|
||
$this->categoryRepository = $this->getMockForAbstractClass(CategoryRepositoryInterface::class); | ||
|
||
$this->productScopeGenerator = (new ObjectManager($this))->getObject( | ||
ProductScopeRewriteGenerator::class, | ||
[ | ||
|
@@ -137,7 +143,8 @@ function ($value) { | |
'storeViewService' => $this->storeViewService, | ||
'storeManager' => $this->storeManager, | ||
'mergeDataProviderFactory' => $mergeDataProviderFactory, | ||
'config' => $this->configMock | ||
'config' => $this->configMock, | ||
'categoryRepository' => $this->categoryRepository | ||
] | ||
); | ||
$this->categoryMock = $this->getMockBuilder(Category::class) | ||
|
@@ -215,6 +222,8 @@ public function testGenerationForSpecificStore() | |
$this->anchorUrlRewriteGenerator->expects($this->any())->method('generate') | ||
->willReturn([]); | ||
|
||
$this->categoryRepository->expects($this->once())->method('get')->willReturn($this->categoryMock); | ||
|
||
$this->assertEquals( | ||
['category-1_1' => $canonical], | ||
$this->productScopeGenerator->generateForSpecificStoreView(1, [$this->categoryMock], $product, 1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the original code but I've removed it anyway.