Magento 2 - How to Redirect Customer for Checkout After Login when cart is not emptyException Plugin class doesn't existMagento 2 - Redirect customer to custom page after loginHow to check whether a product is in the cart?How to change or redirect home page to customer login?Redirect 'add to cart' button to the account login screen when customer is not loged inMake cart empty after loginHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderCustomer redirect issue with plugin method magento2Magento : Around Plugin for LoginPost
Ensuring all network services on a device use strong TLS cipher suites
Does travel insurance for short flight delays exist?
Are modern clipless shoes and pedals that much better than toe clips and straps?
Is for(( ... )) ... ; a valid shell syntax? In which shells?
Handling Disruptive Student on the Autistic Spectrum
Why were the crew so desperate to catch Truman and return him to Seahaven?
Was there ever a treaty between 2 entities with significantly different translations to the detriment of one party?
Would it be possible to have a GMO that produces chocolate?
Is there any method of inflicting the incapacitated condition and no other condition?
What are some interesting features that are common cross-linguistically but don't exist in English?
Confirming resignation after resignation letter ripped up
How to find multiple values on the same line in any permutation using Notepad++?
How to gently end involvement with an online community?
Compelling story with the world as a villain
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
Why do banks “park” their money at the European Central Bank?
How do I get a decreased-by-one x in a foreach loop?
Is using a hyperlink to close a modal a poor design decision?
Is “I am getting married with my sister” ambiguous?
How to respectfully refuse to assist co-workers with IT issues?
Justifying the use of directed energy weapons
Can a Rogue PC teach an NPC to perform Sneak Attack?
What is the difference between Major and Minor Bug?
Can you pop_back a vector and still use the iterator to the last element?
Magento 2 - How to Redirect Customer for Checkout After Login when cart is not empty
Exception Plugin class doesn't existMagento 2 - Redirect customer to custom page after loginHow to check whether a product is in the cart?How to change or redirect home page to customer login?Redirect 'add to cart' button to the account login screen when customer is not loged inMake cart empty after loginHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderCustomer redirect issue with plugin method magento2Magento : Around Plugin for LoginPost
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to redirect customers to the checkout page after login when the cart is not empty for the customer?
LoginpostRedirectetcfrontenddi.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
LoginpostRedirectPluginLoginPostPlugin.php
<?php
namespace LoginpostRedirectPlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Now I'm getting following error after adding this plugin to my project.
magento2 customer-account redirect
add a comment |
How to redirect customers to the checkout page after login when the cart is not empty for the customer?
LoginpostRedirectetcfrontenddi.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
LoginpostRedirectPluginLoginPostPlugin.php
<?php
namespace LoginpostRedirectPlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Now I'm getting following error after adding this plugin to my project.
magento2 customer-account redirect
add a comment |
How to redirect customers to the checkout page after login when the cart is not empty for the customer?
LoginpostRedirectetcfrontenddi.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
LoginpostRedirectPluginLoginPostPlugin.php
<?php
namespace LoginpostRedirectPlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Now I'm getting following error after adding this plugin to my project.
magento2 customer-account redirect
How to redirect customers to the checkout page after login when the cart is not empty for the customer?
LoginpostRedirectetcfrontenddi.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
LoginpostRedirectPluginLoginPostPlugin.php
<?php
namespace LoginpostRedirectPlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Now I'm getting following error after adding this plugin to my project.
magento2 customer-account redirect
magento2 customer-account redirect
edited Aug 13 at 9:25
ashanr
asked Aug 12 at 7:29
ashanrashanr
407 bronze badges
407 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use a plugin for your requirement.
Create a di.xml file /Vendor/Module/etc/frontend/di.xml
with below content
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php
with below content.
<?php
namespace VendorModulePlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Reference from
Magento 2 - Redirect customer to custom page after login
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
1
You need to create a new folder underapp/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example,/Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
1
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
1
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
|
show 8 more comments
you need to create observer that fire event after customer login.
Create observer as below
<?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
</event>
</config>
Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"
<?php
namespace YourPackageYourModleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkControllerResultFactory;
class RedirectCustommer implements ObserverInterface
/**
*@varMagentoQuoteModelQuoteFactory
*/
protected $quoteFactory;
public function __construct(
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoQuoteModelQuoteFactory $quoteFactory
)
$this->quoteFactory = $quoteFactory;
public function execute(MagentoFrameworkEventObserver $observer)
$customer = $observer->getEvent()->getCustomer();
$landingurl = $this->getRedirectUrl($customer->getId());
if ($landingurl)
$resultRedirect = $this->responseFactory->create();
$resultRedirect->setRedirect($landingurl)->sendResponse('200');
exit();
public function getRedirectUrl($customerId)
$quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
if($quote->getId())
return $block->getUrl('checkout', ['_secure' => true]);
return false;
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
1
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
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%2f285118%2fmagento-2-how-to-redirect-customer-for-checkout-after-login-when-cart-is-not-e%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
You can use a plugin for your requirement.
Create a di.xml file /Vendor/Module/etc/frontend/di.xml
with below content
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php
with below content.
<?php
namespace VendorModulePlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Reference from
Magento 2 - Redirect customer to custom page after login
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
1
You need to create a new folder underapp/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example,/Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
1
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
1
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
|
show 8 more comments
You can use a plugin for your requirement.
Create a di.xml file /Vendor/Module/etc/frontend/di.xml
with below content
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php
with below content.
<?php
namespace VendorModulePlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Reference from
Magento 2 - Redirect customer to custom page after login
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
1
You need to create a new folder underapp/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example,/Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
1
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
1
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
|
show 8 more comments
You can use a plugin for your requirement.
Create a di.xml file /Vendor/Module/etc/frontend/di.xml
with below content
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php
with below content.
<?php
namespace VendorModulePlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Reference from
Magento 2 - Redirect customer to custom page after login
You can use a plugin for your requirement.
Create a di.xml file /Vendor/Module/etc/frontend/di.xml
with below content
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
</type>
</config>
Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php
with below content.
<?php
namespace VendorModulePlugin;
class LoginPostPlugin
public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)
$result->setPath('/checkout');
return $result;
Reference from
Magento 2 - Redirect customer to custom page after login
answered Aug 12 at 7:44
SumitSumit
4361 silver badge14 bronze badges
4361 silver badge14 bronze badges
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
1
You need to create a new folder underapp/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example,/Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
1
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
1
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
|
show 8 more comments
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
1
You need to create a new folder underapp/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example,/Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
1
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
1
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?
– ashanr
Aug 12 at 8:33
1
1
You need to create a new folder under
app/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
You need to create a new folder under
app/code/[vendor_name]/[module_name]
. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php
– Sumit
Aug 12 at 9:22
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?
– ashanr
Aug 13 at 8:51
1
1
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml
– Sumit
Aug 13 at 8:53
1
1
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.
– Sumit
Aug 16 at 7:13
|
show 8 more comments
you need to create observer that fire event after customer login.
Create observer as below
<?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
</event>
</config>
Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"
<?php
namespace YourPackageYourModleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkControllerResultFactory;
class RedirectCustommer implements ObserverInterface
/**
*@varMagentoQuoteModelQuoteFactory
*/
protected $quoteFactory;
public function __construct(
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoQuoteModelQuoteFactory $quoteFactory
)
$this->quoteFactory = $quoteFactory;
public function execute(MagentoFrameworkEventObserver $observer)
$customer = $observer->getEvent()->getCustomer();
$landingurl = $this->getRedirectUrl($customer->getId());
if ($landingurl)
$resultRedirect = $this->responseFactory->create();
$resultRedirect->setRedirect($landingurl)->sendResponse('200');
exit();
public function getRedirectUrl($customerId)
$quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
if($quote->getId())
return $block->getUrl('checkout', ['_secure' => true]);
return false;
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
1
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
add a comment |
you need to create observer that fire event after customer login.
Create observer as below
<?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
</event>
</config>
Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"
<?php
namespace YourPackageYourModleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkControllerResultFactory;
class RedirectCustommer implements ObserverInterface
/**
*@varMagentoQuoteModelQuoteFactory
*/
protected $quoteFactory;
public function __construct(
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoQuoteModelQuoteFactory $quoteFactory
)
$this->quoteFactory = $quoteFactory;
public function execute(MagentoFrameworkEventObserver $observer)
$customer = $observer->getEvent()->getCustomer();
$landingurl = $this->getRedirectUrl($customer->getId());
if ($landingurl)
$resultRedirect = $this->responseFactory->create();
$resultRedirect->setRedirect($landingurl)->sendResponse('200');
exit();
public function getRedirectUrl($customerId)
$quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
if($quote->getId())
return $block->getUrl('checkout', ['_secure' => true]);
return false;
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
1
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
add a comment |
you need to create observer that fire event after customer login.
Create observer as below
<?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
</event>
</config>
Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"
<?php
namespace YourPackageYourModleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkControllerResultFactory;
class RedirectCustommer implements ObserverInterface
/**
*@varMagentoQuoteModelQuoteFactory
*/
protected $quoteFactory;
public function __construct(
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoQuoteModelQuoteFactory $quoteFactory
)
$this->quoteFactory = $quoteFactory;
public function execute(MagentoFrameworkEventObserver $observer)
$customer = $observer->getEvent()->getCustomer();
$landingurl = $this->getRedirectUrl($customer->getId());
if ($landingurl)
$resultRedirect = $this->responseFactory->create();
$resultRedirect->setRedirect($landingurl)->sendResponse('200');
exit();
public function getRedirectUrl($customerId)
$quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
if($quote->getId())
return $block->getUrl('checkout', ['_secure' => true]);
return false;
you need to create observer that fire event after customer login.
Create observer as below
<?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
</event>
</config>
Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"
<?php
namespace YourPackageYourModleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkControllerResultFactory;
class RedirectCustommer implements ObserverInterface
/**
*@varMagentoQuoteModelQuoteFactory
*/
protected $quoteFactory;
public function __construct(
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoQuoteModelQuoteFactory $quoteFactory
)
$this->quoteFactory = $quoteFactory;
public function execute(MagentoFrameworkEventObserver $observer)
$customer = $observer->getEvent()->getCustomer();
$landingurl = $this->getRedirectUrl($customer->getId());
if ($landingurl)
$resultRedirect = $this->responseFactory->create();
$resultRedirect->setRedirect($landingurl)->sendResponse('200');
exit();
public function getRedirectUrl($customerId)
$quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
if($quote->getId())
return $block->getUrl('checkout', ['_secure' => true]);
return false;
edited Aug 12 at 8:23
answered Aug 12 at 7:46
Amitkumar solankiAmitkumar solanki
4722 silver badges16 bronze badges
4722 silver badges16 bronze badges
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
1
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
add a comment |
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
1
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Amit, Plugin is the best method to override Magento's functionality instead of using observer.
– Sumit
Aug 12 at 7:48
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
Considered,But plugin is what used for change argument behavior and return value.
– Amitkumar solanki
Aug 12 at 8:26
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
@Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.
– ashanr
Aug 12 at 8:29
1
1
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
Both will be fine. but in some cases you should consider loading time for both.
– Amitkumar solanki
Aug 12 at 8:35
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%2f285118%2fmagento-2-how-to-redirect-customer-for-checkout-after-login-when-cart-is-not-e%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