Skip to content

Commit 71fc4d7

Browse files
committed
MC-18996: GraphQl Url Resolver doesn't return any results if the url_key doesn't have the extension
- add url prefix to schema
1 parent c090d38 commit 71fc4d7

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
namespace Magento\CatalogUrlRewriteGraphQl\Model\Resolver;
99

10-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Store\Api\Data\StoreInterface;
1111
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
1313
use Magento\Framework\GraphQl\Query\ResolverInterface;
1414
use Magento\Store\Model\ScopeInterface;
1515
use Magento\Framework\App\Config\ScopeConfigInterface;
1616

1717
/**
18-
* Returns the url suffix for catalog
18+
* Returns the url suffix for category
1919
*/
2020
class CategoryUrlSuffix implements ResolverInterface
2121
{
@@ -26,7 +26,7 @@ class CategoryUrlSuffix implements ResolverInterface
2626
*
2727
* @var array
2828
*/
29-
private $productUrlSuffix = [];
29+
private $cateogryUrlSuffix = [];
3030

3131
/**
3232
* @var ScopeConfigInterface
@@ -35,11 +35,11 @@ class CategoryUrlSuffix implements ResolverInterface
3535

3636
/**
3737
* @param ScopeConfigInterface $scopeConfig
38-
* @param array $productUrlSuffix
38+
* @param array $cateogryUrlSuffix
3939
*/
40-
public function __construct(ScopeConfigInterface $scopeConfig, array $productUrlSuffix = [])
40+
public function __construct(ScopeConfigInterface $scopeConfig, array $cateogryUrlSuffix = [])
4141
{
42-
$this->productUrlSuffix = $productUrlSuffix;
42+
$this->cateogryUrlSuffix = $cateogryUrlSuffix;
4343
$this->scopeConfig = $scopeConfig;
4444
}
4545

@@ -53,25 +53,27 @@ public function resolve(
5353
array $value = null,
5454
array $args = null
5555
): string {
56-
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
56+
/** @var StoreInterface $store */
57+
$store = $context->getExtensionAttributes()->getStore();
58+
$storeId = (int)$store->getId();
5759
return $this->getProductUrlSuffix($storeId);
5860
}
5961

6062
/**
61-
* Retrieve product url suffix by store
63+
* Retrieve category url suffix by store
6264
*
6365
* @param int $storeId
6466
* @return string
6567
*/
6668
private function getProductUrlSuffix(int $storeId): string
6769
{
68-
if (!isset($this->productUrlSuffix[$storeId])) {
69-
$this->productUrlSuffix[$storeId] = $this->scopeConfig->getValue(
70+
if (!isset($this->cateogryUrlSuffix[$storeId])) {
71+
$this->cateogryUrlSuffix[$storeId] = $this->scopeConfig->getValue(
7072
self::XML_PATH_PRODUCT_URL_SUFFIX,
7173
ScopeInterface::SCOPE_STORE,
7274
$storeId
7375
);
7476
}
75-
return $this->productUrlSuffix[$storeId];
77+
return $this->cateogryUrlSuffix[$storeId];
7678
}
7779
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\CatalogUrlRewriteGraphQl\Model\Resolver;
99

10-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Store\Api\Data\StoreInterface;
1111
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
1313
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -53,7 +53,9 @@ public function resolve(
5353
array $value = null,
5454
array $args = null
5555
): string {
56-
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
56+
/** @var StoreInterface $store */
57+
$store = $context->getExtensionAttributes()->getStore();
58+
$storeId = (int)$store->getId();
5759
return $this->getProductUrlSuffix($storeId);
5860
}
5961

app/code/Magento/CatalogUrlRewriteGraphQl/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"type": "magento2-module",
55
"require": {
66
"php": "~7.1.3||~7.2.0||~7.3.0",
7+
"magento/module-store": "*",
78
"magento/module-catalog": "*",
89
"magento/framework": "*"
910
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
interface ProductInterface {
55
url_key: String @doc(description: "The part of the URL that identifies the product")
6-
url_suffix: String @doc(description: "The part of the URL that is appended after the url key") @resolver(class: "Magento\\CatalogUrlRewriteGraphQl\\Model\\Resolver\\ProductUrlSuffix")
6+
url_suffix: String @doc(description: "The part of the product URL that is appended after the url key") @resolver(class: "Magento\\CatalogUrlRewriteGraphQl\\Model\\Resolver\\ProductUrlSuffix")
77
url_path: String @deprecated(reason: "Use product's `canonical_url` or url rewrites instead")
88
url_rewrites: [UrlRewrite] @doc(description: "URL rewrites list") @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite")
99
}
1010

1111
interface CategoryInterface {
12-
url_suffix: String @doc(description: "The part of the URL that is appended after the url key") @resolver(class: "Magento\\CatalogUrlRewriteGraphQl\\Model\\Resolver\\CategoryUrlSuffix")
12+
url_suffix: String @doc(description: "The part of the category URL that is appended after the url key") @resolver(class: "Magento\\CatalogUrlRewriteGraphQl\\Model\\Resolver\\CategoryUrlSuffix")
1313
}
1414

1515
input ProductFilterInput {

0 commit comments

Comments
 (0)