@@ -26,16 +26,17 @@ class Route extends AbstractEntityUrl implements ResolverInterface
26
26
const CMS_PAGE = 'CMS_PAGE ' ;
27
27
const PRODUCT = 'PRODUCT ' ;
28
28
const CATEGORY = 'CATEGORY ' ;
29
- /**
30
- * @var PageDataProvider
31
- */
32
- private $ pageDataProvider ;
33
29
34
30
/**
35
31
* @var CustomUrlLocatorInterface
36
32
*/
37
33
private $ customUrlLocator ;
38
34
35
+ /**
36
+ * @var PageDataProvider
37
+ */
38
+ private $ pageDataProvider ;
39
+
39
40
/**
40
41
* @var ProductRepository
41
42
*/
@@ -57,13 +58,14 @@ class Route extends AbstractEntityUrl implements ResolverInterface
57
58
private $ categoryRepository ;
58
59
59
60
/**
61
+ * Route constructor.
60
62
* @param UrlFinderInterface $urlFinder
61
- * @param CustomUrlLocatorInterface $customUrlLocator
62
63
* @param ProductRepository $productRepository
63
64
* @param CategoryTreeDataProvider $categoryTree
64
65
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
65
66
* @param PageDataProvider $pageDataProvider
66
67
* @param CategoryRepository $categoryRepository
68
+ * @param CustomUrlLocatorInterface $customUrlLocator
67
69
*/
68
70
public function __construct (
69
71
UrlFinderInterface $ urlFinder ,
@@ -74,8 +76,7 @@ public function __construct(
74
76
PageDataProvider $ pageDataProvider ,
75
77
CategoryRepository $ categoryRepository
76
78
) {
77
- parent ::__construct ($ urlFinder );
78
- $ this ->customUrlLocator = $ customUrlLocator ;
79
+ parent ::__construct ($ customUrlLocator , $ urlFinder );
79
80
$ this ->productRepository = $ productRepository ;
80
81
$ this ->categoryTree = $ categoryTree ;
81
82
$ this ->extractDataFromCategoryTree = $ extractDataFromCategoryTree ;
@@ -93,63 +94,37 @@ public function resolve(
93
94
array $ value = null ,
94
95
array $ args = null
95
96
) {
96
- if (!isset ($ args ['url ' ]) || empty (trim ($ args ['url ' ]))) {
97
- throw new GraphQlInputException (__ ('"url" argument should be specified and not empty ' ));
98
- }
99
-
100
- $ storeId = (int )$ context ->getExtensionAttributes ()->getStore ()->getId ();
101
97
$ result = null ;
102
- $ url = $ args ['url ' ];
103
- if (substr ($ url , 0 , 1 ) === '/ ' && $ url !== '/ ' ) {
104
- $ url = ltrim ($ url , '/ ' );
105
- }
106
- $ this ->redirectType = 0 ;
107
- $ customUrl = $ this ->customUrlLocator ->locateUrl ($ url );
108
- $ url = $ customUrl ?: $ url ;
109
- $ finalUrlRewrite = $ this ->findFinalUrl ($ url , $ storeId );
110
-
111
- if ($ finalUrlRewrite ) {
112
- $ relativeUrl = $ finalUrlRewrite ->getRequestPath ();
113
- $ resultArray = $ this ->rewriteCustomUrls ($ finalUrlRewrite , $ storeId ) ?? [
114
- 'id ' => $ finalUrlRewrite ->getEntityId (),
115
- 'canonical_url ' => $ relativeUrl ,
116
- 'relative_url ' => $ relativeUrl ,
117
- 'redirectCode ' => $ this ->redirectType ,
118
- 'type ' => $ this ->sanitizeType ($ finalUrlRewrite ->getEntityType ())
119
- ];
120
-
121
- if (empty ($ resultArray ['id ' ])) {
122
- throw new GraphQlNoSuchEntityException (
123
- __ ('No such entity found with matching URL key: %url ' , ['url ' => $ url ])
124
- );
125
- }
126
-
98
+ $ resultArray = parent ::resolve (
99
+ $ field ,
100
+ $ context ,
101
+ $ info ,
102
+ $ value ,
103
+ $ args
104
+ );
105
+
106
+ if ($ resultArray ) {
127
107
if ($ resultArray ['type ' ] == self ::CMS_PAGE ) {
128
108
$ result = $ this ->pageDataProvider ->getDataByPageId ((int )$ resultArray ['id ' ]);
129
109
$ result ['type_id ' ] = self ::CMS_PAGE ;
130
110
} else if ($ resultArray ['type ' ] == self ::CATEGORY ) {
131
111
$ categoryId = (int )$ resultArray ['id ' ];
132
- $ categoty = $ this ->categoryRepository ->get ($ categoryId );
133
-
112
+ $ category = $ this ->categoryRepository ->get ($ categoryId );
134
113
$ categoriesTree = $ this ->categoryTree ->getTree ($ info , $ categoryId );
135
114
if (empty ($ categoriesTree ) || ($ categoriesTree ->count () == 0 )) {
136
115
throw new GraphQlNoSuchEntityException (__ ('Category doesn \'t exist ' ));
137
116
}
138
-
139
117
$ result = current ($ this ->extractDataFromCategoryTree ->execute ($ categoriesTree ));
140
-
141
- $ result ['meta_title ' ] = $ categoty ->getData ()['meta_title ' ] ?? null ;
142
- $ result ['meta_keywords ' ] = $ categoty ->getData ()['meta_keywords ' ] ?? null ;
143
- $ result ['meta_description ' ] = $ categoty ->getData ()['meta_description ' ] ?? null ;
118
+ $ result ['meta_title ' ] = $ category ->getData ()['meta_title ' ] ?? null ;
119
+ $ result ['meta_keywords ' ] = $ category ->getData ()['meta_keywords ' ] ?? null ;
120
+ $ result ['meta_description ' ] = $ category ->getData ()['meta_description ' ] ?? null ;
144
121
$ result ['type_id ' ] = self ::CATEGORY ;
145
122
} else if ($ resultArray ['type ' ] == self ::PRODUCT ) {
146
123
$ product = $ this ->productRepository ->getById ($ resultArray ['id ' ]);
147
124
$ result = $ product ->getData ();
148
125
$ result ['model ' ] = $ product ;
149
126
}
150
-
151
127
}
152
-
153
128
return $ result ;
154
129
}
155
130
}
0 commit comments