How to redirect customers to the checkout page after login when the cart is not empty for the customer?
Loginpost\Redirect\etc\frontend\di.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="\Magento\Customer\Controller\Account\LoginPost">
<plugin name="loginpost_redirect_loginpostplugin" type="\LoginPost\Redirect\Plugin\LoginPostPlugin" sortOrder="1" />
</type>
</config>
Loginpost\Redirect\Plugin\LoginPostPlugin.php
<?php
namespace Loginpost\Redirect\Plugin;
class LoginPostPlugin
{
public function afterExecute(
\Magento\Customer\Controller\Account\LoginPost $subject,
$result)
{
$result->setPath('/checkout');
return $result;
}
}
Now I'm getting following error after adding this plugin to my project.
Best Answer
You can use a plugin for your requirement.
Create a di.xml file
/Vendor/Module/etc/frontend/di.xml
with below contentCreate LoginPostPlugin.php file
/Vendor/Module/Plugin/LoginPostPlugin.php
with below content.