1414use Magento \Framework \GraphQl \Query \ResolverInterface ;
1515use Magento \Store \Model \StoreManagerInterface ;
1616use Magento \UrlRewrite \Model \UrlFinderInterface ;
17+ use Magento \Store \Model \ScopeInterface ;
1718
1819/**
1920 * UrlRewrite field resolver, used for GraphQL request processing.
@@ -34,20 +35,29 @@ class UrlRewrite implements ResolverInterface
3435 * @var ValueFactory
3536 */
3637 private $ valueFactory ;
38+
39+ /**
40+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
41+ */
42+ private $ scopeConfig ;
43+
3744
3845 /**
3946 * @param UrlFinderInterface $urlFinder
4047 * @param StoreManagerInterface $storeManager
4148 * @param ValueFactory $valueFactory
49+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
4250 */
4351 public function __construct (
4452 UrlFinderInterface $ urlFinder ,
4553 StoreManagerInterface $ storeManager ,
46- ValueFactory $ valueFactory
54+ ValueFactory $ valueFactory ,
55+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
4756 ) {
4857 $ this ->urlFinder = $ urlFinder ;
4958 $ this ->storeManager = $ storeManager ;
5059 $ this ->valueFactory = $ valueFactory ;
60+ $ this ->scopeConfig = $ scopeConfig ;
5161 }
5262
5363 /**
@@ -63,8 +73,19 @@ public function resolve(
6373 $ result = function () {
6474 return null ;
6575 };
76+
6677 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 );
6889 if ($ urlRewrite ) {
6990 $ urlRewriteReturnArray = [
7091 'id ' => $ urlRewrite ->getEntityId (),
@@ -96,6 +117,7 @@ private function findCanonicalUrl(string $requestPath) : ?\Magento\UrlRewrite\Se
96117 if (!$ urlRewrite ) {
97118 $ urlRewrite = $ this ->findUrlFromTargetPath ($ requestPath );
98119 }
120+
99121 return $ urlRewrite ;
100122 }
101123
0 commit comments