Skip to content

Commit df09330

Browse files
authored
Merge pull request #3 from experius/bugfix/DLTS-1643
[BUGFIX][DLTS-1643] Add plugin to CatalogUrlRewriteGraphQl to remove …
2 parents 8665f1b + 908b845 commit df09330

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Experius\PageNotFoundGraphQl\Plugin\Graphql\Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite;
5+
6+
use Magento\Catalog\Model\ProductRepository;
7+
use Magento\Framework\Exception\NoSuchEntityException;
8+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
9+
10+
class ProductDataProvider
11+
{
12+
13+
public function __construct(
14+
protected ProductRepository $productRepository
15+
)
16+
{
17+
}
18+
19+
/**
20+
* @param \Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite\ProductDataProvider $subject
21+
* @param \Closure $proceed
22+
* @param string $entity_type
23+
* @param int $id
24+
* @param ResolveInfo|null $info
25+
* @param int|null $storeId
26+
* @return mixed
27+
* @throws NoSuchEntityException
28+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
29+
*/
30+
public function aroundGetData(
31+
\Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite\ProductDataProvider $subject,
32+
\Closure $proceed,
33+
string $entity_type,
34+
int $id,
35+
?ResolveInfo $info = null,
36+
?int $storeId = null
37+
)
38+
{
39+
$product = $this->productRepository->getById($id, false, $storeId);
40+
$result = $product->getData();
41+
42+
$result['model'] = $product;
43+
return $result;
44+
}
45+
}

etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" ?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite\ProductDataProvider">
4+
<plugin name="Experius_PageNotFoundGraphQl_Plugin_Graphql_Magento_CatalogUrlRewriteGraphQl_Model_DataProvider_UrlRewrite_ProductDataProvider" type="Experius\PageNotFoundGraphQl\Plugin\Graphql\Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite\ProductDataProvider" sortOrder="10" disabled="false"/>
5+
</type>
36
<type name="Magento\UrlRewriteGraphQl\Model\Resolver\Route">
47
<plugin disabled="false" name="Experius_PageNotFoundGraphQl_Plugin_Graphql_Magento_UrlRewriteGraphQl_Model_Resolver_Route" sortOrder="999" type="Experius\PageNotFoundGraphQl\Plugin\Graphql\Magento\UrlRewriteGraphQl\Model\Resolver\Route"/>
58
</type>

etc/module.xml

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

0 commit comments

Comments
 (0)