3

Can anyone tell me how to edit customer account confirmation link in magento?

It is from the account controller AccountController.php and Action confirmAction

URL in template is as follows.

{{store url="customer/account/confirm/" _query_id=$customer.id _query_key=$customer.confirmation _query_back_url=$back_url}}

I need to redirect my customer to the url that they had visited before coming to the registration page. If they dint visit any other page then I need to redirect them to the home page. Account confirmation should also happen.

By default, customer is redirected to My Account Dashboard once the account confirmation link is clicked. My requirement was to change this URL and redirect to Home Page for the time being.

4
  • What do you want to achieve? Sep 21, 2015 at 10:35
  • I need to redirect my customer to the url that they had visited before coming to the registration page. If they dint visit any other page then I need to redirect them to the home page. Account confirmation should also happen.
    – Swetha
    Sep 21, 2015 at 10:50
  • I would assume this already happens? This is what _query_back_url is for. Sep 21, 2015 at 11:07
  • By default, customer is redirected to My Account Dashboard once the account confirmation link is clicked. My requirement was to change this URL and redirect to Home Page for the time being.
    – Swetha
    Sep 21, 2015 at 14:31

3 Answers 3

2

Edited the confirmAction() in AccountController.php as follows:

public function confirmAction()
    {
        $session = $this->_getSession();
        if ($session->isLoggedIn()) {
            $this->_getSession()->logout()->regenerateSessionId();
        }
        try {
            $id      = $this->getRequest()->getParam('id', false);
            $key     = $this->getRequest()->getParam('key', false);
            $backUrl = $this->getRequest()->getParam('back_url', false);
            if (empty($id) || empty($key)) {
                throw new Exception($this->__('Bad request.'));
            }

            // load customer by id (try/catch in case if it throws exceptions)
            try {
                $customer = $this->_getModel('customer/customer')->load($id);
                if ((!$customer) || (!$customer->getId())) {
                    throw new Exception('Failed to load customer by id.');
                }
            }
            catch (Exception $e) {
                throw new Exception($this->__('Wrong customer account specified.'));
            }

            // check if it is inactive
            if ($customer->getConfirmation()) {
                if ($customer->getConfirmation() !== $key) {
                    throw new Exception($this->__('Wrong confirmation key.'));
                }

                // activate customer
                try {
                    $customer->setConfirmation(null);
                    $customer->save();
                }
                catch (Exception $e) {
                    throw new Exception($this->__('Failed to confirm customer account.'));
                }

                $session->renewSession();
                // log in and send greeting email, then die happy
                $session->setCustomerAsLoggedIn($customer);
                $successUrl = $this->_welcomeCustomer($customer, true);
                $customUrl =  $this->_redirectSuccess(Mage::getBaseUrl());
                $this->_redirectSuccess($customUrl ? $customUrl : $successUrl);
                return;
            }

            // die happy
            $this->_redirectSuccess($this->_getUrl('*/*/index', array('_secure' => true)));
            return;
        }
        catch (Exception $e) {
            // die unhappy
            $this->_getSession()->addError($e->getMessage());
            $this->_redirectError($this->_getUrl('*/*/index', array('_secure' => true)));
            return;
        }
    }

$customUrl contains URL where I need to redirect the customer after clicking the confirmation link and confirm their account as well.

1
  • I want to redirect to login page how to achieve it
    – User0434
    Jun 13, 2020 at 18:31
1

This can be easily done in email template content itself. Just give "home" in the place of $backUrl in _query_back_url parameter. And tadaa ul be redirected to home page on clicking confirmation link from the email ;)

Change this:

<a href="{{store url="customer/account/confirm/" _query_id=$customer.id _query_key=$customer.confirmation _query_back_url=$back_url}}">

To this:

<a href="{{store url="customer/account/confirm/" _query_id=$customer.id _query_key=$customer.confirmation _query_back_url=home}}">
0

Take the back_url out of the query and append it with '&' and pass the url where you cant to redirect the customer after account confirmation.

<a href="{{var this.getUrl($store,'customer/account/confirm/',[_query:[id:$customer.id,key:$customer.confirmation,_nosid:1])}}&back_url={{store url='checkout/cart'}}" target="_blank">{{trans "Confirm Your Account"}}</a>

I tested and it successfully redirects me to the cart page after clicking on the confirmation link in email.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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