Skip to content

Commit d0773c4

Browse files
committed
MC-18996: GraphQl Url Resolver doesn't return any results if the url_key doesn't have the extension
- fix code review in category class
1 parent 02989b0 commit d0773c4

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/CategoryUrlSuffix.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
*/
2020
class CategoryUrlSuffix implements ResolverInterface
2121
{
22-
const XML_PATH_PRODUCT_URL_SUFFIX = 'catalog/seo/category_url_suffix';
22+
/**
23+
* System setting for the url suffix for categories
24+
*
25+
* @var string
26+
*/
27+
private static $xml_path_category_url_suffix = 'catalog/seo/category_url_suffix';
2328

2429
/**
2530
* Cache for product rewrite suffix
2631
*
2732
* @var array
2833
*/
29-
private $cateogryUrlSuffix = [];
34+
private $categoryUrlSuffix = [];
3035

3136
/**
3237
* @var ScopeConfigInterface
@@ -35,11 +40,9 @@ class CategoryUrlSuffix implements ResolverInterface
3540

3641
/**
3742
* @param ScopeConfigInterface $scopeConfig
38-
* @param array $cateogryUrlSuffix
3943
*/
40-
public function __construct(ScopeConfigInterface $scopeConfig, array $cateogryUrlSuffix = [])
44+
public function __construct(ScopeConfigInterface $scopeConfig)
4145
{
42-
$this->cateogryUrlSuffix = $cateogryUrlSuffix;
4346
$this->scopeConfig = $scopeConfig;
4447
}
4548

@@ -56,7 +59,7 @@ public function resolve(
5659
/** @var StoreInterface $store */
5760
$store = $context->getExtensionAttributes()->getStore();
5861
$storeId = (int)$store->getId();
59-
return $this->getProductUrlSuffix($storeId);
62+
return $this->getCategoryUrlSuffix($storeId);
6063
}
6164

6265
/**
@@ -65,15 +68,15 @@ public function resolve(
6568
* @param int $storeId
6669
* @return string
6770
*/
68-
private function getProductUrlSuffix(int $storeId): string
71+
private function getCategoryUrlSuffix(int $storeId): string
6972
{
70-
if (!isset($this->cateogryUrlSuffix[$storeId])) {
71-
$this->cateogryUrlSuffix[$storeId] = $this->scopeConfig->getValue(
72-
self::XML_PATH_PRODUCT_URL_SUFFIX,
73+
if (!isset($this->categoryUrlSuffix[$storeId])) {
74+
$this->categoryUrlSuffix[$storeId] = $this->scopeConfig->getValue(
75+
self::$xml_path_category_url_suffix,
7376
ScopeInterface::SCOPE_STORE,
7477
$storeId
7578
);
7679
}
77-
return $this->cateogryUrlSuffix[$storeId];
80+
return $this->categoryUrlSuffix[$storeId];
7881
}
7982
}

app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/ProductUrlSuffix.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
*/
2020
class ProductUrlSuffix implements ResolverInterface
2121
{
22-
const XML_PATH_PRODUCT_URL_SUFFIX = 'catalog/seo/product_url_suffix';
22+
/**
23+
* System setting for the url suffix for products
24+
*
25+
* @var string
26+
*/
27+
private static $xml_path_product_url_suffix = 'catalog/seo/product_url_suffix';
2328

2429
/**
2530
* Cache for product rewrite suffix
@@ -35,11 +40,9 @@ class ProductUrlSuffix implements ResolverInterface
3540

3641
/**
3742
* @param ScopeConfigInterface $scopeConfig
38-
* @param array $productUrlSuffix
3943
*/
40-
public function __construct(ScopeConfigInterface $scopeConfig, array $productUrlSuffix = [])
44+
public function __construct(ScopeConfigInterface $scopeConfig)
4145
{
42-
$this->productUrlSuffix = $productUrlSuffix;
4346
$this->scopeConfig = $scopeConfig;
4447
}
4548

@@ -69,7 +72,7 @@ private function getProductUrlSuffix(int $storeId): string
6972
{
7073
if (!isset($this->productUrlSuffix[$storeId])) {
7174
$this->productUrlSuffix[$storeId] = $this->scopeConfig->getValue(
72-
self::XML_PATH_PRODUCT_URL_SUFFIX,
75+
self::$xml_path_product_url_suffix,
7376
ScopeInterface::SCOPE_STORE,
7477
$storeId
7578
);

app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See COPYING.txt for license details.
33

44
type Query {
5-
urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\EntityUrl") @doc(description: "The urlResolver query returns the relative URL for a specified product, category or CMS page, using as input a url_key prepended by the url_suffix, if one exists") @cache(cacheIdentity: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite\\UrlResolverIdentity")
5+
urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\EntityUrl") @doc(description: "The urlResolver query returns the relative URL for a specified product, category or CMS page, using as input a url_key appended by the url_suffix, if one exists") @cache(cacheIdentity: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite\\UrlResolverIdentity")
66
}
77

88
type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `relative_url`, and `type` attributes") {

0 commit comments

Comments
 (0)