Skip to content

Commit 8f59ae1

Browse files
committed
MAGETWO-86324: PWA URL resolver service
- fix case when canonical path is used as input
1 parent ab00cda commit 8f59ae1

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ public function resolve(array $args, ResolverContextInterface $context)
6565
*/
6666
private function findCanonicalUrl(string $requestPath)
6767
{
68-
$urlRewrite = $this->findUrl($requestPath);
69-
if ($urlRewrite->getRedirectType() > 0) {
68+
$urlRewrite = $this->findUrlFromRequestPath($requestPath);
69+
if ($urlRewrite && $urlRewrite->getRedirectType() > 0) {
7070
while ($urlRewrite && $urlRewrite->getRedirectType() > 0) {
71-
$urlRewrite = $this->findUrl($urlRewrite->getTargetPath());
71+
$urlRewrite = $this->findUrlFromRequestPath($urlRewrite->getTargetPath());
7272
}
7373
}
74+
if (!$urlRewrite) {
75+
$urlRewrite = $this->findUrlFromTargetPath($requestPath);
76+
}
7477
return $urlRewrite;
7578
}
7679

@@ -80,7 +83,7 @@ private function findCanonicalUrl(string $requestPath)
8083
* @param string $requestPath
8184
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite|null
8285
*/
83-
private function findUrl(string $requestPath)
86+
private function findUrlFromRequestPath(string $requestPath)
8487
{
8588
return $this->urlFinder->findOneByData(
8689
[
@@ -90,6 +93,22 @@ private function findUrl(string $requestPath)
9093
);
9194
}
9295

96+
/**
97+
* Find a url from a target url on the current store
98+
*
99+
* @param string $targetPath
100+
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite|null
101+
*/
102+
private function findUrlFromTargetPath(string $targetPath)
103+
{
104+
return $this->urlFinder->findOneByData(
105+
[
106+
'target_path' => $targetPath,
107+
'store_id' => $this->storeManager->getStore()->getId()
108+
]
109+
);
110+
}
111+
93112
/**
94113
* Sanitizes the type to fit schema specs
95114
*

0 commit comments

Comments
 (0)