Magento 2 : Redirect on cart page after login Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Redirect user after loginCustomer login redirect to homepageRedirect Registered Customer issueMagento 2: How to redirect customer to login pageRedirect to login page if not login magentoRedirect to login page after registration in Magento 2Magento 2 After login redirect user to referrerMagento 1.9 checkout/onepage after login redirect to checkout/onepageMagento 1: after login need to redirect to previous page (before login) instead of dashboard pageHow to redirect customer to cart page if they are login from checkout page?
Is there a documented rationale why the House Ways and Means chairman can demand tax info?
How do I automatically answer y in bash script?
Why use gamma over alpha radiation?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
Was credit for the black hole image misattributed?
How to retrograde a note sequence in Finale?
What is the electric potential inside a point charge?
I'm thinking of a number
Fishing simulator
When is phishing education going too far?
Make it rain characters
Mortgage adviser recommends a longer term than necessary combined with overpayments
Autumning in love
Complexity of many constant time steps with occasional logarithmic steps
Simulating Exploding Dice
What to do with post with dry rot?
Can I throw a sword that doesn't have the Thrown property at someone?
I'm having difficulty getting my players to do stuff in a sandbox campaign
If A makes B more likely then B makes A more likely"
Estimate capacitor parameters
Replacing HDD with SSD; what about non-APFS/APFS?
Am I ethically obligated to go into work on an off day if the reason is sudden?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
What do you call a plan that's an alternative plan in case your initial plan fails?
Magento 2 : Redirect on cart page after login
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Redirect user after loginCustomer login redirect to homepageRedirect Registered Customer issueMagento 2: How to redirect customer to login pageRedirect to login page if not login magentoRedirect to login page after registration in Magento 2Magento 2 After login redirect user to referrerMagento 1.9 checkout/onepage after login redirect to checkout/onepageMagento 1: after login need to redirect to previous page (before login) instead of dashboard pageHow to redirect customer to cart page if they are login from checkout page?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.
Anyone know how to do this?
Please help me.
magento2 customer redirect
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.
Anyone know how to do this?
Please help me.
magento2 customer redirect
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.
Anyone know how to do this?
Please help me.
magento2 customer redirect
I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.
Anyone know how to do this?
Please help me.
magento2 customer redirect
magento2 customer redirect
edited Oct 7 '17 at 14:15
Amit Bera♦
60k1677178
60k1677178
asked Oct 6 '17 at 10:14
Sneha PanchalSneha Panchal
540325
540325
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Step 1 : Create
Vendor/Module/etc/frontend/events.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="customer_login">
<observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
</event>
</config>
Step 2 :
Create Vendor/Module/Observer/CustomerLogin.php
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
class CustomerLogin implements ObserverInterface
protected $_responseFactory;
protected $_url;
public function __construct(
MagentoFrameworkViewLayout $layout,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
)
$this->_layout = $layout;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
/*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('checkout/cart');
return $resultRedirect;*/
$RedirectUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
die();
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
2
bad idea because your observer will interrupt application flow usingdiefunction.
– Max
Oct 6 '17 at 16:38
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
add a comment |
For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.
Example
public function afterExecute(LoginPost $subject, ResultInterface $result)
$isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
if ($isCustomerLoggedIn)
$result = $this->resultRedirectFactory->create()
->setPath('checkout/cart');
return $result;
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
yes, you also need to change behavior ofMagento/Checkout/view/frontend/web/js/view/authentication.jscomponent for redirect to custom url during login via checkout page
– Max
Oct 9 '17 at 7:48
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
add a comment |
Create events.xml from Module/etc/frontend/ folder and paste it below code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="customer_login">
<observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
</event>
</config>
And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.
<?php
namespace ThemeVendorNameObserver;
class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
/**
* @var MagentoFrameworkAppResponseInterface
*/
protected $_response;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* @param MagentoFrameworkUrlInterface $url
* @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
*/
public function __construct
(
MagentoFrameworkUrlInterface $url,
MagentoStoreModelStoreManagerInterface $storeManagerInterface
)
$this->_storeManager = $storeManagerInterface;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
$storeObj = $this->_storeManager->getStore(1);
$BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
$url = $BaseURL . 'customer/account/login';
$this->_response->setRedirect($url)->sendResponse();
Feel free to ask if any.
1
bad idea because your observer will interrupt application flow usingexitfunction.
– Max
Oct 6 '17 at 16:38
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
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%2f196170%2fmagento-2-redirect-on-cart-page-after-login%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Step 1 : Create
Vendor/Module/etc/frontend/events.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="customer_login">
<observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
</event>
</config>
Step 2 :
Create Vendor/Module/Observer/CustomerLogin.php
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
class CustomerLogin implements ObserverInterface
protected $_responseFactory;
protected $_url;
public function __construct(
MagentoFrameworkViewLayout $layout,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
)
$this->_layout = $layout;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
/*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('checkout/cart');
return $resultRedirect;*/
$RedirectUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
die();
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
2
bad idea because your observer will interrupt application flow usingdiefunction.
– Max
Oct 6 '17 at 16:38
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
add a comment |
Step 1 : Create
Vendor/Module/etc/frontend/events.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="customer_login">
<observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
</event>
</config>
Step 2 :
Create Vendor/Module/Observer/CustomerLogin.php
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
class CustomerLogin implements ObserverInterface
protected $_responseFactory;
protected $_url;
public function __construct(
MagentoFrameworkViewLayout $layout,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
)
$this->_layout = $layout;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
/*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('checkout/cart');
return $resultRedirect;*/
$RedirectUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
die();
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
2
bad idea because your observer will interrupt application flow usingdiefunction.
– Max
Oct 6 '17 at 16:38
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
add a comment |
Step 1 : Create
Vendor/Module/etc/frontend/events.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="customer_login">
<observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
</event>
</config>
Step 2 :
Create Vendor/Module/Observer/CustomerLogin.php
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
class CustomerLogin implements ObserverInterface
protected $_responseFactory;
protected $_url;
public function __construct(
MagentoFrameworkViewLayout $layout,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
)
$this->_layout = $layout;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
/*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('checkout/cart');
return $resultRedirect;*/
$RedirectUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
die();
Step 1 : Create
Vendor/Module/etc/frontend/events.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="customer_login">
<observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
</event>
</config>
Step 2 :
Create Vendor/Module/Observer/CustomerLogin.php
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
class CustomerLogin implements ObserverInterface
protected $_responseFactory;
protected $_url;
public function __construct(
MagentoFrameworkViewLayout $layout,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
)
$this->_layout = $layout;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
/*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('checkout/cart');
return $resultRedirect;*/
$RedirectUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
die();
answered Oct 6 '17 at 10:57
Dinesh YadavDinesh Yadav
4,0831937
4,0831937
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
2
bad idea because your observer will interrupt application flow usingdiefunction.
– Max
Oct 6 '17 at 16:38
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
add a comment |
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
2
bad idea because your observer will interrupt application flow usingdiefunction.
– Max
Oct 6 '17 at 16:38
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.
– Sneha Panchal
Oct 6 '17 at 11:47
2
2
bad idea because your observer will interrupt application flow using
die function.– Max
Oct 6 '17 at 16:38
bad idea because your observer will interrupt application flow using
die function.– Max
Oct 6 '17 at 16:38
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
@SnehaPanchal its working with the same version
– SagarPPanchal
Sep 18 '18 at 6:11
add a comment |
For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.
Example
public function afterExecute(LoginPost $subject, ResultInterface $result)
$isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
if ($isCustomerLoggedIn)
$result = $this->resultRedirectFactory->create()
->setPath('checkout/cart');
return $result;
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
yes, you also need to change behavior ofMagento/Checkout/view/frontend/web/js/view/authentication.jscomponent for redirect to custom url during login via checkout page
– Max
Oct 9 '17 at 7:48
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
add a comment |
For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.
Example
public function afterExecute(LoginPost $subject, ResultInterface $result)
$isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
if ($isCustomerLoggedIn)
$result = $this->resultRedirectFactory->create()
->setPath('checkout/cart');
return $result;
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
yes, you also need to change behavior ofMagento/Checkout/view/frontend/web/js/view/authentication.jscomponent for redirect to custom url during login via checkout page
– Max
Oct 9 '17 at 7:48
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
add a comment |
For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.
Example
public function afterExecute(LoginPost $subject, ResultInterface $result)
$isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
if ($isCustomerLoggedIn)
$result = $this->resultRedirectFactory->create()
->setPath('checkout/cart');
return $result;
For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.
Example
public function afterExecute(LoginPost $subject, ResultInterface $result)
$isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
if ($isCustomerLoggedIn)
$result = $this->resultRedirectFactory->create()
->setPath('checkout/cart');
return $result;
answered Oct 6 '17 at 16:36
MaxMax
2,846818
2,846818
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
yes, you also need to change behavior ofMagento/Checkout/view/frontend/web/js/view/authentication.jscomponent for redirect to custom url during login via checkout page
– Max
Oct 9 '17 at 7:48
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
add a comment |
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
yes, you also need to change behavior ofMagento/Checkout/view/frontend/web/js/view/authentication.jscomponent for redirect to custom url during login via checkout page
– Max
Oct 9 '17 at 7:48
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.
– Sneha Panchal
Oct 9 '17 at 6:19
yes, you also need to change behavior of
Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page– Max
Oct 9 '17 at 7:48
yes, you also need to change behavior of
Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page– Max
Oct 9 '17 at 7:48
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
Can I use something else for module development? Because we need to install the module on different instances. Thank You!
– Sneha Panchal
Oct 9 '17 at 10:20
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
– Max
Oct 9 '17 at 10:28
add a comment |
Create events.xml from Module/etc/frontend/ folder and paste it below code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="customer_login">
<observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
</event>
</config>
And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.
<?php
namespace ThemeVendorNameObserver;
class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
/**
* @var MagentoFrameworkAppResponseInterface
*/
protected $_response;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* @param MagentoFrameworkUrlInterface $url
* @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
*/
public function __construct
(
MagentoFrameworkUrlInterface $url,
MagentoStoreModelStoreManagerInterface $storeManagerInterface
)
$this->_storeManager = $storeManagerInterface;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
$storeObj = $this->_storeManager->getStore(1);
$BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
$url = $BaseURL . 'customer/account/login';
$this->_response->setRedirect($url)->sendResponse();
Feel free to ask if any.
1
bad idea because your observer will interrupt application flow usingexitfunction.
– Max
Oct 6 '17 at 16:38
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
add a comment |
Create events.xml from Module/etc/frontend/ folder and paste it below code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="customer_login">
<observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
</event>
</config>
And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.
<?php
namespace ThemeVendorNameObserver;
class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
/**
* @var MagentoFrameworkAppResponseInterface
*/
protected $_response;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* @param MagentoFrameworkUrlInterface $url
* @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
*/
public function __construct
(
MagentoFrameworkUrlInterface $url,
MagentoStoreModelStoreManagerInterface $storeManagerInterface
)
$this->_storeManager = $storeManagerInterface;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
$storeObj = $this->_storeManager->getStore(1);
$BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
$url = $BaseURL . 'customer/account/login';
$this->_response->setRedirect($url)->sendResponse();
Feel free to ask if any.
1
bad idea because your observer will interrupt application flow usingexitfunction.
– Max
Oct 6 '17 at 16:38
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
add a comment |
Create events.xml from Module/etc/frontend/ folder and paste it below code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="customer_login">
<observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
</event>
</config>
And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.
<?php
namespace ThemeVendorNameObserver;
class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
/**
* @var MagentoFrameworkAppResponseInterface
*/
protected $_response;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* @param MagentoFrameworkUrlInterface $url
* @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
*/
public function __construct
(
MagentoFrameworkUrlInterface $url,
MagentoStoreModelStoreManagerInterface $storeManagerInterface
)
$this->_storeManager = $storeManagerInterface;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
$storeObj = $this->_storeManager->getStore(1);
$BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
$url = $BaseURL . 'customer/account/login';
$this->_response->setRedirect($url)->sendResponse();
Feel free to ask if any.
Create events.xml from Module/etc/frontend/ folder and paste it below code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="customer_login">
<observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
</event>
</config>
And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.
<?php
namespace ThemeVendorNameObserver;
class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
/**
* @var MagentoFrameworkAppResponseInterface
*/
protected $_response;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* @param MagentoFrameworkUrlInterface $url
* @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
*/
public function __construct
(
MagentoFrameworkUrlInterface $url,
MagentoStoreModelStoreManagerInterface $storeManagerInterface
)
$this->_storeManager = $storeManagerInterface;
$this->_url = $url;
public function execute(MagentoFrameworkEventObserver $observer)
$storeObj = $this->_storeManager->getStore(1);
$BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
$url = $BaseURL . 'customer/account/login';
$this->_response->setRedirect($url)->sendResponse();
Feel free to ask if any.
edited Jun 27 '18 at 6:22
Dhaduk Mitesh
656218
656218
answered Oct 6 '17 at 10:38
BojjaiahBojjaiah
2,5132875
2,5132875
1
bad idea because your observer will interrupt application flow usingexitfunction.
– Max
Oct 6 '17 at 16:38
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
add a comment |
1
bad idea because your observer will interrupt application flow usingexitfunction.
– Max
Oct 6 '17 at 16:38
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
1
1
bad idea because your observer will interrupt application flow using
exit function.– Max
Oct 6 '17 at 16:38
bad idea because your observer will interrupt application flow using
exit function.– Max
Oct 6 '17 at 16:38
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
It is not working for me :(
– Sneha Panchal
Oct 9 '17 at 10:21
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
@SnehaPanchal let me check
– Bojjaiah
Oct 9 '17 at 10:37
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%2f196170%2fmagento-2-redirect-on-cart-page-after-login%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