Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0"?>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
- <event name="controller_action_predispatch">
- <observer name="controller_action_predispatch" instance="BBBBObserverControllerPredispatch" />
- </event>
- </config>
- <?php
- namespace BBBBObserver;
- use MagentoFrameworkEventObserverInterface;
- use MagentoFrameworkEventObserver;
- class ControllerPredispatch implements ObserverInterface
- {
- /**
- * @var MagentoFrameworkUrlInterface
- */
- protected $url;
- /**
- * @var MagentoFrameworkAppResponseHttp
- */
- protected $http;
- /** @var MagentoCustomerModelSession */
- protected $customerSession;
- /**
- * @param MagentoFrameworkUrlInterface $url
- * @param MagentoFrameworkAppResponseHttp $http
- * @param MagentoCustomerModelSession $customerSession
- */
- public function __construct(
- MagentoFrameworkUrlInterface $url,
- MagentoFrameworkAppResponseHttp $http,
- MagentoCustomerModelSession $customerSession
- )
- {
- $this->url = $url;
- $this->http = $http;
- $this->customerSession = $customerSession;
- }
- /**
- * Manages redirect
- */
- public function execute(Observer $observer)
- {
- /**
- * Check if user logged in
- */
- if ($this->customerSession->isLoggedIn()) {
- return;
- }
- if ($observer->getRequest()->getFullActionName() == 'cms_index_index') {
- /**
- * Redirect to login
- */
- $this->http->setRedirect($this->url->getUrl('bb-check-extension.html'), 301);
- }
- }
- }
Add Comment
Please, Sign In to add comment