bitExpert / magento2-force-login

Force Customer Login Module for Magento 2
https://marketplace.magento.com/bitexpert-magento2-force-customer-login.html
Apache License 2.0
166 stars 73 forks source link

After Login Redirect is missing query parameters #133

Closed squeegy06 closed 5 years ago

squeegy06 commented 5 years ago

Query parameters are missing from the redirect URL sent after login. We have marketing emails that are losing their tracking information because the forced login is stripping the query parameters from the URL when it sets the redirect URL.

Magento Version : 2.2.5CE Force Login Module Version : 3.0.1

Steps to reproduce

  1. Ensure force login is enabled and that you are currently not logged in on the frontend.
  2. Visit any URL that has query parameters that you must first be logged in to view, example www.mystore.com/some-product?utm_campaign=123456789
  3. After being redirected to the login page, complete the login.
  4. Observe

Expected result

I expected to be redirected to /some-product?utm_campaign=123456789

Actual result

I get redirected to /some-product

I'm open to other ideas on how to remedy this problem. For now I've written a plugin to the LoginCheck controller and it does what I need it to do. But I feel this feature may be important to other users of your module.

    public function afterExecute(\BitExpert\ForceCustomerLogin\Controller\LoginCheck $subject, $result) 
    {
        /**
         * If the LoginCheck has initiated a redirect to the login page.
         */
        if(false !== $result && $this->_helper->moduleEnabled()) {
            $url = $this->_url->getCurrentUrl();
            $urlParts = \parse_url($url);
            $redirect = $urlParts['path'];
            if(isset($urlParts['query']) && !empty($urlParts['query'])) {
                $redirect .= '?' . $urlParts['query'];
            }
            $this->_session->setAfterLoginReferer($redirect);
        }

        return $result;
    }
der-workfloh commented 5 years ago

Hi @squeegy06 ,

thanks for your feedback and contribution. May you want to provide this by pull request? If not, we can add this feature of course, but would be nice to see you as the contributor ;) Maybe some adaptions on the tests are required. Just let us know and thanks!

Best regards!

squeegy06 commented 5 years ago

Sure, I can write a pull request some time today. I appreciate it!