Guest User

Untitled

a guest
Jul 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
  3. <event name="controller_action_predispatch">
  4. <observer name="controller_action_predispatch" instance="BBBBObserverControllerPredispatch" />
  5. </event>
  6. </config>
  7.  
  8. <?php
  9.  
  10. namespace BBBBObserver;
  11.  
  12. use MagentoFrameworkEventObserverInterface;
  13. use MagentoFrameworkEventObserver;
  14.  
  15. class ControllerPredispatch implements ObserverInterface
  16. {
  17. /**
  18. * @var MagentoFrameworkUrlInterface
  19. */
  20. protected $url;
  21.  
  22. /**
  23. * @var MagentoFrameworkAppResponseHttp
  24. */
  25. protected $http;
  26.  
  27. /** @var MagentoCustomerModelSession */
  28. protected $customerSession;
  29.  
  30. /**
  31. * @param MagentoFrameworkUrlInterface $url
  32. * @param MagentoFrameworkAppResponseHttp $http
  33. * @param MagentoCustomerModelSession $customerSession
  34. */
  35. public function __construct(
  36. MagentoFrameworkUrlInterface $url,
  37. MagentoFrameworkAppResponseHttp $http,
  38. MagentoCustomerModelSession $customerSession
  39. )
  40. {
  41. $this->url = $url;
  42. $this->http = $http;
  43. $this->customerSession = $customerSession;
  44. }
  45.  
  46. /**
  47. * Manages redirect
  48. */
  49. public function execute(Observer $observer)
  50. {
  51. /**
  52. * Check if user logged in
  53. */
  54. if ($this->customerSession->isLoggedIn()) {
  55. return;
  56. }
  57.  
  58. if ($observer->getRequest()->getFullActionName() == 'cms_index_index') {
  59. /**
  60. * Redirect to login
  61. */
  62. $this->http->setRedirect($this->url->getUrl('bb-check-extension.html'), 301);
  63. }
  64. }
  65. }
Add Comment
Please, Sign In to add comment