14
14
use Magento \Framework \GraphQl \Query \ResolverInterface ;
15
15
use Magento \Store \Model \StoreManagerInterface ;
16
16
use Magento \UrlRewrite \Model \UrlFinderInterface ;
17
+ use Magento \Store \Model \ScopeInterface ;
17
18
18
19
/**
19
20
* UrlRewrite field resolver, used for GraphQL request processing.
@@ -34,20 +35,29 @@ class UrlRewrite implements ResolverInterface
34
35
* @var ValueFactory
35
36
*/
36
37
private $ valueFactory ;
38
+
39
+ /**
40
+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
41
+ */
42
+ private $ scopeConfig ;
43
+
37
44
38
45
/**
39
46
* @param UrlFinderInterface $urlFinder
40
47
* @param StoreManagerInterface $storeManager
41
48
* @param ValueFactory $valueFactory
49
+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
42
50
*/
43
51
public function __construct (
44
52
UrlFinderInterface $ urlFinder ,
45
53
StoreManagerInterface $ storeManager ,
46
- ValueFactory $ valueFactory
54
+ ValueFactory $ valueFactory ,
55
+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
47
56
) {
48
57
$ this ->urlFinder = $ urlFinder ;
49
58
$ this ->storeManager = $ storeManager ;
50
59
$ this ->valueFactory = $ valueFactory ;
60
+ $ this ->scopeConfig = $ scopeConfig ;
51
61
}
52
62
53
63
/**
@@ -63,8 +73,19 @@ public function resolve(
63
73
$ result = function () {
64
74
return null ;
65
75
};
76
+
66
77
if (isset ($ args ['url ' ])) {
67
- $ urlRewrite = $ this ->findCanonicalUrl ($ args ['url ' ]);
78
+ $ url = $ args ['url ' ];
79
+ if (substr ($ url , 0 , 1 ) === '/ ' && $ url !== '/ ' ) {
80
+ $ url = ltrim ($ url , '/ ' );
81
+ } else if ($ url === '/ ' ) {
82
+ $ homePageIdentifier = $ this ->scopeConfig ->getValue (
83
+ \Magento \Cms \Helper \Page::XML_PATH_HOME_PAGE ,
84
+ ScopeInterface::SCOPE_STORE
85
+ );
86
+ $ url = $ homePageIdentifier ;
87
+ }
88
+ $ urlRewrite = $ this ->findCanonicalUrl ($ url );
68
89
if ($ urlRewrite ) {
69
90
$ urlRewriteReturnArray = [
70
91
'id ' => $ urlRewrite ->getEntityId (),
@@ -96,6 +117,7 @@ private function findCanonicalUrl(string $requestPath) : ?\Magento\UrlRewrite\Se
96
117
if (!$ urlRewrite ) {
97
118
$ urlRewrite = $ this ->findUrlFromTargetPath ($ requestPath );
98
119
}
120
+
99
121
return $ urlRewrite ;
100
122
}
101
123
0 commit comments