Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0ff6732
magento/magento2#35371: Product page gives error because of url rewrites
Feb 28, 2025
0d4e053
magento/magento2#35371: Product page gives error because of url rewrites
Feb 28, 2025
19967c8
magento/magento2#35371: Product page gives error because of url rewrites
Feb 28, 2025
9e2f43d
Merge branch '2.4-develop' into fix-for-issue-35371
Himsoft Feb 28, 2025
46cffe1
Merge branch '2.4-develop' into fix-for-issue-35371
Himsoft Mar 6, 2025
20b76fa
Merge branch '2.4-develop' into fix-for-issue-35371
engcom-Hotel Mar 27, 2025
10eae94
Merge branch '2.4-develop' into fix-for-issue-35371
Mar 27, 2025
be61357
magento/magento2#35371: Product page gives error because of url rewrites
Mar 27, 2025
58e57fb
Merge remote-tracking branch 'origin/fix-for-issue-35371' into fix-fo…
Mar 27, 2025
3065aff
Merge branch '2.4-develop' into fix-for-issue-35371
engcom-Dash Apr 7, 2025
a0a157f
Merge branch '2.4-develop' into fix-for-issue-35371
engcom-Dash Apr 8, 2025
260e872
Merge branch '2.4-develop' into fix-for-issue-35371
Apr 8, 2025
62411cf
magento/magento2#35371: Product page gives error because of url rewrites
Apr 8, 2025
ec49e95
Merge remote-tracking branch 'origin/fix-for-issue-35371' into fix-fo…
Apr 8, 2025
e6167c8
Merge branch '2.4-develop' into fix-for-issue-35371
engcom-Dash Apr 11, 2025
60daff8
Merge branch '2.4-develop' into fix-for-issue-35371
engcom-Dash Apr 11, 2025
6e48007
Fixed Static Test Case Failures
engcom-Dash Apr 11, 2025
805c544
Copyright Message & Static Test Case Failure Fixed
engcom-Dash Apr 11, 2025
ca76908
Merge branch '2.4-develop' into fix-for-issue-35371
engcom-Hotel Apr 14, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Model\Storage;
Expand Down Expand Up @@ -170,7 +172,7 @@ private function findProductRewriteByRequestPath(array $data): ?array
}
$categorySuffix = $this->getCategoryUrlSuffix($data[UrlRewrite::STORE_ID]);
$productResource = $this->productFactory->create();
$categoryPath = str_replace('/' . $productUrl, '', $requestPath);
$categoryPath = substr($requestPath, 0, -1 * strlen('/' . $productUrl));
if ($productFromDb[UrlRewrite::REDIRECT_TYPE]) {
$productUrl = $productFromDb[UrlRewrite::TARGET_PATH];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -80,6 +80,11 @@ class DynamicStorageTest extends TestCase
*/
private $logger;

/**
* @var string
*/
private $requestPath;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -169,9 +174,7 @@ public function testFindProductRewriteByRequestPath(
bool $canBeShownInCategory,
?array $expectedProductRewrite
): void {
$this->connectionMock->expects($this->any())
->method('fetchRow')
->will($this->onConsecutiveCalls($productFromDb, $categoryFromDb));
$this->fetchDataMock($productFromDb, $categoryFromDb);

$scopeConfigMap = [
[
Expand Down Expand Up @@ -347,6 +350,68 @@ public static function findProductRewriteByRequestPathDataProvider(): array
'redirect_type' => OptionProvider::PERMANENT,
]
],
[
// Category has product url key at the beginning of its url key
[
'request_path' => 'test-category/test-sub-category/test',
'store_id' => 1
],
[
'entity_type' => 'product',
'entity_id' => '1',
'request_path' => 'test',
'target_path' => 'catalog/product/view/id/1',
'redirect_type' => '0',
],
'',
[
'entity_type' => 'category',
'entity_id' => '38',
'request_path' => 'test-category/test-sub-category',
'target_path' => 'catalog/category/view/id/38',
'redirect_type' => '0',
],
true,
[
'entity_type' => 'product',
'entity_id' => '1',
'request_path' => 'test-category/test-sub-category/test',
'target_path' => 'catalog/product/view/id/1/category/38',
'redirect_type' => '0',
]
],
];
}

/**
* @param array|false $productFromDb
* @param array|false $categoryFromDb
*
* @return void
*/
private function fetchDataMock($productFromDb, $categoryFromDb): void
{
$selectMock = $this->selectMock;
$this->selectMock->expects($this->any())
->method('where')
->willReturnCallback(function ($string, $value) use ($selectMock) {
if ($string == 'url_rewrite.request_path IN (?)') {
$this->requestPath = array_shift($value);
}
return $selectMock;
});
$this->connectionMock->expects($this->any())
->method('fetchRow')
->willReturnCallback(function () use ($productFromDb, $categoryFromDb) {
switch (true) {
case $productFromDb && $productFromDb['request_path'] == $this->requestPath:
return $productFromDb;
case $categoryFromDb && $categoryFromDb['request_path'] == $this->requestPath:
return $categoryFromDb;
default:
return false;
}
})
;
}
}