Skip to content

Commit 821dce8

Browse files
committed
Merge branch 'ACP2E-2770' of https://github.com/adobe-commerce-tier-4/magento2ce into 2.4-develop
2 parents 6b19ffc + f23f4a8 commit 821dce8

File tree

6 files changed

+65
-12
lines changed

6 files changed

+65
-12
lines changed

app/code/Magento/Catalog/Helper/Product.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
*/
1919
class Product extends \Magento\Framework\Url\Helper\Data
2020
{
21-
const XML_PATH_PRODUCT_URL_USE_CATEGORY = 'catalog/seo/product_use_categories';
21+
public const XML_PATH_PRODUCT_URL_USE_CATEGORY = 'catalog/seo/product_use_categories';
2222

23-
const XML_PATH_USE_PRODUCT_CANONICAL_TAG = 'catalog/seo/product_canonical_tag';
23+
public const XML_PATH_USE_PRODUCT_CANONICAL_TAG = 'catalog/seo/product_canonical_tag';
2424

25-
const XML_PATH_AUTO_GENERATE_MASK = 'catalog/fields_masks';
25+
public const XML_PATH_AUTO_GENERATE_MASK = 'catalog/fields_masks';
26+
27+
public const XML_PATH_APPLY_TRANSLITERATION_TO_URL = 'catalog/seo/product_url_transliteration';
2628

2729
/**
2830
* Flag that shows if Magento has to check product to be saleable (enabled and/or inStock)
@@ -47,8 +49,6 @@ class Product extends \Magento\Framework\Url\Helper\Data
4749
protected $_assetRepo;
4850

4951
/**
50-
* Core registry
51-
*
5252
* @var \Magento\Framework\Registry
5353
*/
5454
protected $_coreRegistry;
@@ -59,8 +59,6 @@ class Product extends \Magento\Framework\Url\Helper\Data
5959
protected $_attributeConfig;
6060

6161
/**
62-
* Catalog session
63-
*
6462
* @var \Magento\Catalog\Model\Session
6563
*/
6664
protected $_catalogSession;

app/code/Magento/Catalog/Model/Product/Url.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,18 @@ public function getProductUrl($product, $useSid = null)
114114
*/
115115
public function formatUrlKey($str)
116116
{
117-
return $this->filter->translitUrl($str);
117+
if ($this->scopeConfig->getValue(
118+
\Magento\Catalog\Helper\Product::XML_PATH_APPLY_TRANSLITERATION_TO_URL,
119+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
120+
)) {
121+
return $this->filter->translitUrl($str);
122+
} else {
123+
$str = preg_replace('/\s+/', '-', $str);
124+
$str = mb_strtolower($str);
125+
$str = trim($str, '-');
126+
}
127+
128+
return $str;
118129
}
119130

120131
/**

app/code/Magento/Catalog/Test/Unit/Model/Product/UrlTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\Product\Url;
1313
use Magento\Catalog\Model\Product\Url as ProductUrl;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
1415
use Magento\Framework\Filter\FilterManager;
1516
use Magento\Framework\Session\SidResolverInterface;
1617
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -21,6 +22,9 @@
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
2324

25+
/**
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
2428
class UrlTest extends TestCase
2529
{
2630
/**
@@ -53,6 +57,11 @@ class UrlTest extends TestCase
5357
*/
5458
protected $sidResolver;
5559

60+
/**
61+
* @var ScopeConfigInterface
62+
*/
63+
private ScopeConfigInterface $scopeConfig;
64+
5665
protected function setUp(): void
5766
{
5867
$this->filter = $this->getMockBuilder(
@@ -86,6 +95,8 @@ protected function setUp(): void
8695
$urlFactory->method('create')
8796
->willReturn($this->url);
8897

98+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
99+
89100
$objectManager = new ObjectManager($this);
90101
$this->model = $objectManager->getObject(
91102
ProductUrl::class,
@@ -95,11 +106,15 @@ protected function setUp(): void
95106
'storeManager' => $storeManager,
96107
'urlFactory' => $urlFactory,
97108
'sidResolver' => $this->sidResolver,
109+
'scopeConfig' => $this->scopeConfig
98110
]
99111
);
100112
}
101113

102-
public function testFormatUrlKey()
114+
/**
115+
* @return void
116+
*/
117+
public function testFormatUrlKey(): void
103118
{
104119
$strIn = 'Some string';
105120
$resultString = 'some';
@@ -114,6 +129,29 @@ public function testFormatUrlKey()
114129
$resultString
115130
);
116131

132+
$this->scopeConfig->expects($this->once())
133+
->method('getValue')
134+
->with(
135+
\Magento\Catalog\Helper\Product::XML_PATH_APPLY_TRANSLITERATION_TO_URL,
136+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
137+
)->willReturn(true);
138+
$this->assertEquals($resultString, $this->model->formatUrlKey($strIn));
139+
}
140+
141+
/**
142+
* @return void
143+
*/
144+
public function testFormatUrlKeyWithoutTransliteration(): void
145+
{
146+
$strIn = 'Some string ';
147+
$resultString = 'some-string';
148+
149+
$this->scopeConfig->expects($this->once())
150+
->method('getValue')
151+
->with(
152+
\Magento\Catalog\Helper\Product::XML_PATH_APPLY_TRANSLITERATION_TO_URL,
153+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
154+
)->willReturn(false);
117155
$this->assertEquals($resultString, $this->model->formatUrlKey($strIn));
118156
}
119157

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,18 @@
116116
</group>
117117
<group id="seo" translate="label" type="text" sortOrder="500" showInDefault="1" showInWebsite="1" showInStore="1">
118118
<label>Search Engine Optimization</label>
119-
<field id="title_separator" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
119+
<field id="product_url_transliteration" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
120+
<label>Apply transliteration for product URL</label>
121+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
122+
</field>
123+
<field id="title_separator" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
120124
<label>Page Title Separator</label>
121125
</field>
122-
<field id="category_canonical_tag" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
126+
<field id="category_canonical_tag" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
123127
<label>Use Canonical Link Meta Tag For Categories</label>
124128
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
125129
</field>
126-
<field id="product_canonical_tag" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
130+
<field id="product_canonical_tag" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
127131
<label>Use Canonical Link Meta Tag For Products</label>
128132
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
129133
</field>

app/code/Magento/Catalog/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<title_separator>-</title_separator>
4949
<category_canonical_tag>0</category_canonical_tag>
5050
<product_canonical_tag>0</product_canonical_tag>
51+
<product_url_transliteration>1</product_url_transliteration>
5152
</seo>
5253
<custom_options>
5354
<date_fields_order>m,d,y</date_fields_order>

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ Comma-separated.,Comma-separated.
665665
"Page Title Separator","Page Title Separator"
666666
"Use Canonical Link Meta Tag For Categories","Use Canonical Link Meta Tag For Categories"
667667
"Use Canonical Link Meta Tag For Products","Use Canonical Link Meta Tag For Products"
668+
"Apply transliteration for product URL","Apply transliteration for product URL"
668669
"Catalog Price Scope","Catalog Price Scope"
669670
"This defines the base currency scope (""Currency Setup"" > ""Currency Options"" > ""Base Currency"").","This defines the base currency scope (""Currency Setup"" > ""Currency Options"" > ""Base Currency"")."
670671
"Category Top Navigation","Category Top Navigation"

0 commit comments

Comments
 (0)