Skip to content

Commit

Permalink
Merge pull request #9 from mageworx/add_entity_info_to_custom_redirect
Browse files Browse the repository at this point in the history
Add entity data in response to custom redirect
  • Loading branch information
SiarheyUchukhlebau authored Nov 8, 2024
2 parents 1f9ea51 + b1da3c3 commit 6729afd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Plugin/ModifyRouteDataPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\UrlRewriteGraphQl\Model\DataProvider\EntityDataProviderComposite;
use MageWorx\SeoRedirects\Model\Redirect\CustomRedirectFinder;
use MageWorx\SeoRedirectsGraphQl\Model\CustomRedirectDataProviderInterface;
use MageWorx\SeoRedirectsGraphQl\Model\DpRedirectDataProviderInterface;
Expand All @@ -21,15 +22,18 @@ class ModifyRouteDataPlugin
protected DpRedirectDataProviderInterface $dpRedirectDataProvider;
protected CustomRedirectDataProviderInterface $customRedirectDataProvider;
protected CustomRedirectFinder $customRedirectFinder;
protected EntityDataProviderComposite $entityDataProviderComposite;

public function __construct(
DpRedirectDataProviderInterface $dpRedirectDataProvider,
CustomRedirectDataProviderInterface $customRedirectDataProvider,
CustomRedirectFinder $customRedirectFinder
CustomRedirectFinder $customRedirectFinder,
EntityDataProviderComposite $entityDataProviderComposite
) {
$this->dpRedirectDataProvider = $dpRedirectDataProvider;
$this->customRedirectDataProvider = $customRedirectDataProvider;
$this->customRedirectFinder = $customRedirectFinder;
$this->entityDataProviderComposite = $entityDataProviderComposite;
}

/**
Expand Down Expand Up @@ -92,6 +96,15 @@ public function afterResolve(
}

$urlRewriteData = $this->customRedirectDataProvider->getEntityUrlDataByCustomRedirectEntity($customRedirect);
if (is_array($urlRewriteData) && !empty($urlRewriteData['type']) && !empty($urlRewriteData['id'])) {
$entityData = $this->entityDataProviderComposite->getData(
$urlRewriteData['type'],
(int)$urlRewriteData['id'],
$info,
$storeId
);
$urlRewriteData = $entityData + $urlRewriteData;;
}

return empty($urlRewriteData) ? null : $urlRewriteData;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"MageWorx\\SeoRedirectsGraphQl\\": ""
}
},
"version": "1.3.2"
"version": "1.3.3"
}

0 comments on commit 6729afd

Please sign in to comment.