Guest User

Untitled

a guest
Dec 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <?php
  2. namespace VendorRealproductController;
  3.  
  4. class Router implements MagentoFrameworkAppRouterInterface
  5. {
  6. /**
  7. * @var MagentoFrameworkAppActionFactory
  8. */
  9. protected $actionFactory;
  10.  
  11. /**
  12. * Router constructor.
  13. *
  14. * @param MagentoFrameworkAppActionFactory $actionFactory
  15. */
  16. public function __construct(
  17. MagentoFrameworkAppActionFactory $actionFactory
  18. ) {
  19. $this->actionFactory = $actionFactory;
  20. }
  21.  
  22. /**
  23. *
  24. * @param MagentoFrameworkAppRequestInterface $request
  25. * @return bool
  26. */
  27. public function match(MagentoFrameworkAppRequestInterface $request)
  28. {
  29. $identifier = trim($request->getPathInfo(), '/');
  30. $d = explode('/', $identifier, 3);
  31.  
  32. if(isset($d[0]) && ($d[0] != 'Realproducts')) {
  33. return false;
  34. }
  35.  
  36.  
  37. $paramStr = '';
  38. if(isset($d[1])) {
  39. $paramStr = $d[1];
  40. }
  41.  
  42. $params = [];
  43.  
  44. if($paramStr) {
  45. $params = explode('-', $paramStr);
  46. }
  47.  
  48.  
  49. $params = ['year' => $params[0], 'make' => $params[1], 'model' => $params[2]];
  50.  
  51. //print_r($params);
  52. //exit;
  53.  
  54. $request->setModuleName('Realproduct')->setControllerName('index')->setActionName('index');
  55. if(count($params)) {
  56. $request->setParams($params);
  57. }
  58.  
  59. $request->setAlias(MagentoFrameworkUrl::REWRITE_REQUEST_PATH_ALIAS, $identifier);
  60. //print_r($request);
  61. //exit;
  62. return $this->actionFactory->create(
  63. 'MagentoFrameworkAppActionForward',
  64. ['request' => $request]
  65. );
  66. }
  67. }
Add Comment
Please, Sign In to add comment