Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace VendorRealproductController;
- class Router implements MagentoFrameworkAppRouterInterface
- {
- /**
- * @var MagentoFrameworkAppActionFactory
- */
- protected $actionFactory;
- /**
- * Router constructor.
- *
- * @param MagentoFrameworkAppActionFactory $actionFactory
- */
- public function __construct(
- MagentoFrameworkAppActionFactory $actionFactory
- ) {
- $this->actionFactory = $actionFactory;
- }
- /**
- *
- * @param MagentoFrameworkAppRequestInterface $request
- * @return bool
- */
- public function match(MagentoFrameworkAppRequestInterface $request)
- {
- $identifier = trim($request->getPathInfo(), '/');
- $d = explode('/', $identifier, 3);
- if(isset($d[0]) && ($d[0] != 'Realproducts')) {
- return false;
- }
- $paramStr = '';
- if(isset($d[1])) {
- $paramStr = $d[1];
- }
- $params = [];
- if($paramStr) {
- $params = explode('-', $paramStr);
- }
- $params = ['year' => $params[0], 'make' => $params[1], 'model' => $params[2]];
- //print_r($params);
- //exit;
- $request->setModuleName('Realproduct')->setControllerName('index')->setActionName('index');
- if(count($params)) {
- $request->setParams($params);
- }
- $request->setAlias(MagentoFrameworkUrl::REWRITE_REQUEST_PATH_ALIAS, $identifier);
- //print_r($request);
- //exit;
- return $this->actionFactory->create(
- 'MagentoFrameworkAppActionForward',
- ['request' => $request]
- );
- }
- }
Add Comment
Please, Sign In to add comment