Skip to content

Commit 0d973fe

Browse files
committed
AC-3223::Special characters in category url_key (when created via REST API)
1 parent 2c844ad commit 0d973fe

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Plugin\Model;
10+
11+
use Magento\Catalog\Api\Data\CategoryInterface;
12+
use Magento\Catalog\Model\CategoryRepository;
13+
14+
/**
15+
* Plugin for category repository
16+
*/
17+
class CategoryRepositoryPlugin
18+
{
19+
private const ATTRIBUTES_TO_PROCESS = [
20+
'url_key',
21+
'url_path'
22+
];
23+
24+
/**
25+
* Formats category url key and path using the default formatter.
26+
*
27+
* @param CategoryRepository $subject
28+
* @param CategoryInterface $category
29+
* @return array
30+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
31+
*/
32+
public function beforeSave(CategoryRepository $subject, CategoryInterface $category): array
33+
{
34+
foreach (self::ATTRIBUTES_TO_PROCESS as $attributeKey) {
35+
if ($attribute = $category->getCustomAttribute($attributeKey)) {
36+
$attribute->setValue($category->formatUrlKey(
37+
$category->getData($attributeKey)
38+
));
39+
}
40+
}
41+
return [$category];
42+
}
43+
}

app/code/Magento/Catalog/etc/webapi_rest/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@
4444
<plugin name="reindex_after_save_product_links" type="Magento\Catalog\Plugin\Api\ProductLinkRepositoryInterface\ReindexAfterSaveProductLinksPlugin"/>
4545
<plugin name="reindex_after_delete_by_id_product_links" type="Magento\Catalog\Plugin\Api\ProductLinkRepositoryInterface\ReindexAfterDeleteByIdProductLinksPlugin"/>
4646
</type>
47+
<type name="Magento\Catalog\Model\CategoryRepository">
48+
<plugin name="format_category_url_key_rest_api" type="Magento\Catalog\Plugin\Model\CategoryRepositoryPlugin" />
49+
</type>
4750
</config>

lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function getData($key = '', $index = null)
297297
? $this->_data[self::CUSTOM_ATTRIBUTES]
298298
: [];
299299
$this->convertCustomAttributeValues($customAttributes);
300-
$data = $customAttributes ? array_merge($customAttributes, $this->_data) : array_merge($this->_data, $customAttributes);
300+
$data = array_merge($this->_data, $customAttributes);
301301
unset($data[self::CUSTOM_ATTRIBUTES]);
302302
} else {
303303
$data = parent::getData($key, $index);

0 commit comments

Comments
 (0)