Skip to content

Commit 8665f1b

Browse files
authored
Merge pull request #2 from experius/feature/graphql-support-new-features
[FEATURE][JIRA-123]switch to using base function from experius/module…
2 parents 43ef0cd + 947212a commit 8665f1b

File tree

3 files changed

+19
-64
lines changed

3 files changed

+19
-64
lines changed

Plugin/Graphql/Magento/UrlRewriteGraphQl/Model/Resolver/Route.php

Lines changed: 13 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,14 @@
77

88
namespace Experius\PageNotFoundGraphQl\Plugin\Graphql\Magento\UrlRewriteGraphQl\Model\Resolver;
99

10-
use Magento\Store\Api\Data\StoreInterface;
10+
use Experius\PageNotFound\Observer\Controller\ActionPredispatch;
11+
use Magento\UrlRewriteGraphQl\Model\Resolver\EntityUrl;
12+
use Magento\UrlRewriteGraphQl\Model\Resolver\Route as MagentoRoute;
1113

12-
class Route
14+
class Route extends ActionPredispatch
1315
{
1416
/**
15-
* @var \Experius\PageNotFound\Model\PageNotFoundFactory
16-
*/
17-
private $pageNotFoundFactory;
18-
19-
/**
20-
* EntityUrl constructor.
21-
*
22-
* @param \Experius\PageNotFound\Model\PageNotFoundFactory $pageNotFoundFactory
23-
*/
24-
public function __construct(
25-
\Experius\PageNotFound\Model\PageNotFoundFactory $pageNotFoundFactory
26-
) {
27-
$this->pageNotFoundFactory = $pageNotFoundFactory;
28-
}
29-
30-
/**
31-
* @param \Magento\UrlRewriteGraphQl\Model\Resolver\EntityUrl $subject
17+
* @param EntityUrl $subject
3218
* @param $result
3319
* @param $field
3420
* @param $context
@@ -39,17 +25,18 @@ public function __construct(
3925
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4026
*/
4127
public function aroundResolve(
42-
\Magento\UrlRewriteGraphQl\Model\Resolver\Route $subject,
43-
$proceed,
44-
$field,
45-
$context,
46-
$info,
28+
MagentoRoute $subject,
29+
$proceed,
30+
$field,
31+
$context,
32+
$info,
4733
array $value = null,
4834
array $args = null
49-
) {
35+
)
36+
{
5037
$result = $proceed($field, $context, $info, $value, $args);
5138
if (is_null($result) && $args['url'] != '/') {
52-
$args['url'] = $this->savePageNotFound($args['url'], $context->getExtensionAttributes()->getStore()) ?: $args['url'];
39+
$args['url'] = $this->savePageNotFound($args['url'], true, $context->getExtensionAttributes()->getStore()) ?: $args['url'];
5340
$result = $proceed($field, $context, $info, $value, $args);
5441
if (!is_null($result)) {
5542
$result['redirect_code'] = 301;
@@ -58,41 +45,4 @@ public function aroundResolve(
5845
return $result;
5946
}
6047

61-
/**
62-
* @param $fromUrl
63-
* @param StoreInterface $store
64-
* @return string|null
65-
* @throws \Exception
66-
*/
67-
protected function savePageNotFound(
68-
$fromUrl,
69-
StoreInterface $store
70-
) {
71-
/* @var $pageNotFoundModel \Experius\PageNotFound\Model\PageNotFound */
72-
$pageNotFoundModel = $this->pageNotFoundFactory->create();
73-
$baseUrl = $store->getBaseUrl();
74-
if (strpos($fromUrl, $baseUrl) === false) {
75-
$fromUrl = $baseUrl . ltrim($fromUrl, '/');
76-
}
77-
$pageNotFoundModel->load($fromUrl,'from_url');
78-
79-
if($pageNotFoundModel->getId()){
80-
$count = $pageNotFoundModel->getCount();
81-
$pageNotFoundModel->setCount($count+1);
82-
} else {
83-
$pageNotFoundModel->setFromUrl($fromUrl);
84-
$pageNotFoundModel->setCount(1);
85-
}
86-
87-
if($pageNotFoundModel->getToUrl()) {
88-
$pageNotFoundModel->setCountRedirect($pageNotFoundModel->getCountRedirect()+1);
89-
}
90-
91-
$pageNotFoundModel->save();
92-
if($pageNotFoundModel->getToUrl()) {
93-
return str_replace($baseUrl, '', $pageNotFoundModel->getToUrl());
94-
}
95-
return null;
96-
}
9748
}
98-

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"name": "Lewis Voncken",
1313
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Simon Vianen",
17+
"email": "[email protected]"
1418
}
1519
],
1620
"minimum-stability": "dev",
@@ -25,4 +29,4 @@
2529
"registration.php"
2630
]
2731
}
28-
}
32+
}

etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<module name="Experius_PageNotFoundGraphQl">
44
<sequence>
55
<module name="Magento_UrlRewriteGraphQl"/>
6+
<module name="Experius_PageNotFound"/>
67
</sequence>
78
</module>
89
</config>

0 commit comments

Comments
 (0)