0

i there any way i can add reffer like, so user can be redirected to that url after login, something like below

http://example.com/customer/account/login?u=product-page-url

i have already set below from admin

enter image description here

1
  • So you want to redirect specific product URL OR current Product URL after login?
    – kunj
    Feb 18, 2020 at 12:33

2 Answers 2

0

Note: In admin Customer redirect option should be set to "No":As you've already done it as per above image.

Create a new module or in existing module: /Vendor/Module/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="vendor_module_loginpostplugin" type="\Vendor\Module\Plugin\LoginPostPlugin" sortOrder="1" />
</type>
</config>

/Vendor/Module/Plugin/LoginPostPlugin.php

<?php

/**
*
*/
namespace Vendor\Module\Plugin;

/**
*
*/
class LoginPostPlugin
{

/**
 * Change redirect after login to home instead of dashboard.
 *
 * @param \Magento\Customer\Controller\Account\LoginPost $subject
 * @param \Magento\Framework\Controller\Result\Redirect $result
 */
    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        $result->setPath('/'); // Change Here to where you want to redirect
        return $result;
    }

}
0

Your case plugin is a better solution And i have tested and showing below code your helpful

I have create the simple module

Custom/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="Custom_Redirect_loginpostplugin" type="Custom\Redirect\Plugin\LoginPostPlugin" sortOrder="1" />
  </type>
</config>

Custom/Redirect/Plugin/LoginPostPlugin.php

<?php

namespace Custom\Redirect\Plugin;

class LoginPostPlugin
{

    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        $result->setPath('YourURL/'); // Change this to what you want
        return $result;
    }

}

Custom/Redirect/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Custom_Redirect',
    __DIR__
);

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.