Magento2 : Redirect Page From ObserverMagento 2 - Redirect user to a specific page if not logged inHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlMagento2 : Redirect from observermain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento2: Redirect issue from the Observer
Where are the Wazirs?
What does the multimeter dial do internally?
Is homosexuality or bisexuality allowed for women?
Intern not wearing safety equipment; how could I have handled this differently?
What are the effects of abstaining from eating a certain flavor?
What was the profession 芸者 (female entertainer) called in Britain?
How does one acquire an undead eyeball encased in a gem?
How was the website able to tell my credit card was wrong before it processed it?
Is space division multiplexing really multiplexing?
Findminimum of Integral
How to understand flavors and when to use combination of them?
Gory anime with pink haired girl escaping an asylum
Interpretation of non-significant results as "trends"
Can one block with a protection from color creature?
What are the consequences for a developed nation to not accept any refugees?
QR codes, do people use them?
US citizen traveling with Peruvian passport
Strong Password Detection in Python
Array or vector? Two dimensional array or matrix?
Clarinets in the Rite of Spring
Did depressed people far more accurately estimate how many monsters they killed in a video game?
Deck of Cards with Shuffle and Sort functionality
Publishing papers seem natural to many, while I find it really hard to think novel stuff to pursue till publication. How to cope up with this?
What was the nature of the known bugs in the Space Shuttle software?
Magento2 : Redirect Page From Observer
Magento 2 - Redirect user to a specific page if not logged inHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlMagento2 : Redirect from observermain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento2: Redirect issue from the Observer
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to restrict some unwanted users to access the site. So I am redirecting them to 404 Page but my logic is going to an infinite loop as the event I am calling from controller_action_predispatch is called several times and I am not able to find the right one.
My Logic
namespace NamespaceModuleObserver;
class RedirectUsers implements MagentoFrameworkEventObserverInterface
protected $_myHelper;
public function __construct(
NamespaceModuleHelperData $myHelper,
)
$this->_myHelper = $myHelper;
public function execute(MagentoFrameworkEventObserver $observer)
if(in_array($currentUser, $restrictedUsers))
$url = $this->_myHelper->getNoRoutePageUrl();
header('Location: ' . $url);
exit;
My event.xml
<?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 instance="NamespaceModuleObserverRedirectIp" name="namespace_module_observer_controller_actionpredispatch_controller_action_predispatch"/>
</event>
</config>
magento2 event-observer redirect
add a comment |
I want to restrict some unwanted users to access the site. So I am redirecting them to 404 Page but my logic is going to an infinite loop as the event I am calling from controller_action_predispatch is called several times and I am not able to find the right one.
My Logic
namespace NamespaceModuleObserver;
class RedirectUsers implements MagentoFrameworkEventObserverInterface
protected $_myHelper;
public function __construct(
NamespaceModuleHelperData $myHelper,
)
$this->_myHelper = $myHelper;
public function execute(MagentoFrameworkEventObserver $observer)
if(in_array($currentUser, $restrictedUsers))
$url = $this->_myHelper->getNoRoutePageUrl();
header('Location: ' . $url);
exit;
My event.xml
<?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 instance="NamespaceModuleObserverRedirectIp" name="namespace_module_observer_controller_actionpredispatch_controller_action_predispatch"/>
</event>
</config>
magento2 event-observer redirect
Should read more here: magento.stackexchange.com/questions/131706/…
– Khoa TruongDinh
Oct 15 '16 at 5:29
add a comment |
I want to restrict some unwanted users to access the site. So I am redirecting them to 404 Page but my logic is going to an infinite loop as the event I am calling from controller_action_predispatch is called several times and I am not able to find the right one.
My Logic
namespace NamespaceModuleObserver;
class RedirectUsers implements MagentoFrameworkEventObserverInterface
protected $_myHelper;
public function __construct(
NamespaceModuleHelperData $myHelper,
)
$this->_myHelper = $myHelper;
public function execute(MagentoFrameworkEventObserver $observer)
if(in_array($currentUser, $restrictedUsers))
$url = $this->_myHelper->getNoRoutePageUrl();
header('Location: ' . $url);
exit;
My event.xml
<?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 instance="NamespaceModuleObserverRedirectIp" name="namespace_module_observer_controller_actionpredispatch_controller_action_predispatch"/>
</event>
</config>
magento2 event-observer redirect
I want to restrict some unwanted users to access the site. So I am redirecting them to 404 Page but my logic is going to an infinite loop as the event I am calling from controller_action_predispatch is called several times and I am not able to find the right one.
My Logic
namespace NamespaceModuleObserver;
class RedirectUsers implements MagentoFrameworkEventObserverInterface
protected $_myHelper;
public function __construct(
NamespaceModuleHelperData $myHelper,
)
$this->_myHelper = $myHelper;
public function execute(MagentoFrameworkEventObserver $observer)
if(in_array($currentUser, $restrictedUsers))
$url = $this->_myHelper->getNoRoutePageUrl();
header('Location: ' . $url);
exit;
My event.xml
<?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 instance="NamespaceModuleObserverRedirectIp" name="namespace_module_observer_controller_actionpredispatch_controller_action_predispatch"/>
</event>
</config>
magento2 event-observer redirect
magento2 event-observer redirect
edited Jun 29 at 5:39
Sarfaraj Sipai
5211 gold badge7 silver badges20 bronze badges
5211 gold badge7 silver badges20 bronze badges
asked Oct 14 '16 at 9:45
PriyankPriyank
5,7024 gold badges24 silver badges53 bronze badges
5,7024 gold badges24 silver badges53 bronze badges
Should read more here: magento.stackexchange.com/questions/131706/…
– Khoa TruongDinh
Oct 15 '16 at 5:29
add a comment |
Should read more here: magento.stackexchange.com/questions/131706/…
– Khoa TruongDinh
Oct 15 '16 at 5:29
Should read more here: magento.stackexchange.com/questions/131706/…
– Khoa TruongDinh
Oct 15 '16 at 5:29
Should read more here: magento.stackexchange.com/questions/131706/…
– Khoa TruongDinh
Oct 15 '16 at 5:29
add a comment |
2 Answers
2
active
oldest
votes
Below one you can follow
namespace CustomModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;
class YourObserver implements ObserverInterface
/**
* @var MagentoFrameworkAppResponseRedirectInterface
*/
protected $redirect;
public function __construct(MagentoFrameworkAppResponseRedirectInterface $redirect)
$this->redirect = $redirect;
public function execute(MagentoFrameworkEventObserver $observer)
$actionName = $observer->getEvent()->getRequest()->getFullActionName();
$controller = $observer->getControllerAction();
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Copy this code & put ur things in it Replace$this->redirect->getRefererUrl()with Ur URL which you want to redirect
– Ankit Shah
Oct 14 '16 at 10:15
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
Try to remove ur condition & Check. Please also give Urevents.xmlfile as well
– Ankit Shah
Oct 14 '16 at 10:32
event xml added
– Priyank
Oct 14 '16 at 10:37
|
show 3 more comments
set obeject :
//@var MagentoBackendModelViewResultRedirect $resultRedirect
$resultRedirect = $this->resultRedirectFactory->create();
then just use setPath() method
return $resultRedirect->setPath('*/*/');
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f140868%2fmagento2-redirect-page-from-observer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Below one you can follow
namespace CustomModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;
class YourObserver implements ObserverInterface
/**
* @var MagentoFrameworkAppResponseRedirectInterface
*/
protected $redirect;
public function __construct(MagentoFrameworkAppResponseRedirectInterface $redirect)
$this->redirect = $redirect;
public function execute(MagentoFrameworkEventObserver $observer)
$actionName = $observer->getEvent()->getRequest()->getFullActionName();
$controller = $observer->getControllerAction();
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Copy this code & put ur things in it Replace$this->redirect->getRefererUrl()with Ur URL which you want to redirect
– Ankit Shah
Oct 14 '16 at 10:15
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
Try to remove ur condition & Check. Please also give Urevents.xmlfile as well
– Ankit Shah
Oct 14 '16 at 10:32
event xml added
– Priyank
Oct 14 '16 at 10:37
|
show 3 more comments
Below one you can follow
namespace CustomModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;
class YourObserver implements ObserverInterface
/**
* @var MagentoFrameworkAppResponseRedirectInterface
*/
protected $redirect;
public function __construct(MagentoFrameworkAppResponseRedirectInterface $redirect)
$this->redirect = $redirect;
public function execute(MagentoFrameworkEventObserver $observer)
$actionName = $observer->getEvent()->getRequest()->getFullActionName();
$controller = $observer->getControllerAction();
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Copy this code & put ur things in it Replace$this->redirect->getRefererUrl()with Ur URL which you want to redirect
– Ankit Shah
Oct 14 '16 at 10:15
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
Try to remove ur condition & Check. Please also give Urevents.xmlfile as well
– Ankit Shah
Oct 14 '16 at 10:32
event xml added
– Priyank
Oct 14 '16 at 10:37
|
show 3 more comments
Below one you can follow
namespace CustomModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;
class YourObserver implements ObserverInterface
/**
* @var MagentoFrameworkAppResponseRedirectInterface
*/
protected $redirect;
public function __construct(MagentoFrameworkAppResponseRedirectInterface $redirect)
$this->redirect = $redirect;
public function execute(MagentoFrameworkEventObserver $observer)
$actionName = $observer->getEvent()->getRequest()->getFullActionName();
$controller = $observer->getControllerAction();
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
Below one you can follow
namespace CustomModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;
class YourObserver implements ObserverInterface
/**
* @var MagentoFrameworkAppResponseRedirectInterface
*/
protected $redirect;
public function __construct(MagentoFrameworkAppResponseRedirectInterface $redirect)
$this->redirect = $redirect;
public function execute(MagentoFrameworkEventObserver $observer)
$actionName = $observer->getEvent()->getRequest()->getFullActionName();
$controller = $observer->getControllerAction();
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
answered Oct 14 '16 at 9:56
Ankit ShahAnkit Shah
4,99912 gold badges75 silver badges148 bronze badges
4,99912 gold badges75 silver badges148 bronze badges
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Copy this code & put ur things in it Replace$this->redirect->getRefererUrl()with Ur URL which you want to redirect
– Ankit Shah
Oct 14 '16 at 10:15
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
Try to remove ur condition & Check. Please also give Urevents.xmlfile as well
– Ankit Shah
Oct 14 '16 at 10:32
event xml added
– Priyank
Oct 14 '16 at 10:37
|
show 3 more comments
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Copy this code & put ur things in it Replace$this->redirect->getRefererUrl()with Ur URL which you want to redirect
– Ankit Shah
Oct 14 '16 at 10:15
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
Try to remove ur condition & Check. Please also give Urevents.xmlfile as well
– Ankit Shah
Oct 14 '16 at 10:32
event xml added
– Priyank
Oct 14 '16 at 10:37
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Can you explain what is it doing or how I should implement this
– Priyank
Oct 14 '16 at 10:05
Copy this code & put ur things in it Replace
$this->redirect->getRefererUrl() with Ur URL which you want to redirect– Ankit Shah
Oct 14 '16 at 10:15
Copy this code & put ur things in it Replace
$this->redirect->getRefererUrl() with Ur URL which you want to redirect– Ankit Shah
Oct 14 '16 at 10:15
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
I hope you understood my question. I am not asking how I should redirect. I am asking my redirection is going to infinite loop as the event get calls again and again. I tried your example and I am getting the same result
– Priyank
Oct 14 '16 at 10:22
Try to remove ur condition & Check. Please also give Ur
events.xml file as well– Ankit Shah
Oct 14 '16 at 10:32
Try to remove ur condition & Check. Please also give Ur
events.xml file as well– Ankit Shah
Oct 14 '16 at 10:32
event xml added
– Priyank
Oct 14 '16 at 10:37
event xml added
– Priyank
Oct 14 '16 at 10:37
|
show 3 more comments
set obeject :
//@var MagentoBackendModelViewResultRedirect $resultRedirect
$resultRedirect = $this->resultRedirectFactory->create();
then just use setPath() method
return $resultRedirect->setPath('*/*/');
add a comment |
set obeject :
//@var MagentoBackendModelViewResultRedirect $resultRedirect
$resultRedirect = $this->resultRedirectFactory->create();
then just use setPath() method
return $resultRedirect->setPath('*/*/');
add a comment |
set obeject :
//@var MagentoBackendModelViewResultRedirect $resultRedirect
$resultRedirect = $this->resultRedirectFactory->create();
then just use setPath() method
return $resultRedirect->setPath('*/*/');
set obeject :
//@var MagentoBackendModelViewResultRedirect $resultRedirect
$resultRedirect = $this->resultRedirectFactory->create();
then just use setPath() method
return $resultRedirect->setPath('*/*/');
answered Oct 14 '16 at 13:23
Ronak ChauhanRonak Chauhan
4,3941 gold badge17 silver badges51 bronze badges
4,3941 gold badge17 silver badges51 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f140868%2fmagento2-redirect-page-from-observer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Should read more here: magento.stackexchange.com/questions/131706/…
– Khoa TruongDinh
Oct 15 '16 at 5:29