@@ -65,12 +65,15 @@ public function resolve(array $args, ResolverContextInterface $context)
65
65
*/
66
66
private function findCanonicalUrl (string $ requestPath )
67
67
{
68
- $ urlRewrite = $ this ->findUrl ($ requestPath );
69
- if ($ urlRewrite ->getRedirectType () > 0 ) {
68
+ $ urlRewrite = $ this ->findUrlFromRequestPath ($ requestPath );
69
+ if ($ urlRewrite && $ urlRewrite ->getRedirectType () > 0 ) {
70
70
while ($ urlRewrite && $ urlRewrite ->getRedirectType () > 0 ) {
71
- $ urlRewrite = $ this ->findUrl ($ urlRewrite ->getTargetPath ());
71
+ $ urlRewrite = $ this ->findUrlFromRequestPath ($ urlRewrite ->getTargetPath ());
72
72
}
73
73
}
74
+ if (!$ urlRewrite ) {
75
+ $ urlRewrite = $ this ->findUrlFromTargetPath ($ requestPath );
76
+ }
74
77
return $ urlRewrite ;
75
78
}
76
79
@@ -80,7 +83,7 @@ private function findCanonicalUrl(string $requestPath)
80
83
* @param string $requestPath
81
84
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite|null
82
85
*/
83
- private function findUrl (string $ requestPath )
86
+ private function findUrlFromRequestPath (string $ requestPath )
84
87
{
85
88
return $ this ->urlFinder ->findOneByData (
86
89
[
@@ -90,6 +93,22 @@ private function findUrl(string $requestPath)
90
93
);
91
94
}
92
95
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
+
93
112
/**
94
113
* Sanitizes the type to fit schema specs
95
114
*
0 commit comments