1

I have done some changes in user registration like add a field group_id and save its values to DB. Code was done and working successfully but It was in core controller. Now I wantr to put taht controller on local. To do ths I followed some guids and stackoverflow answers but everytinme I am nit able to get the desired output. Please help. my code is

app/code/local/Dev/Customcustomer/etc/config.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Dev_Customcustomer>
            <version>1.0.0</version>
        </Dev_Customcustomer>
    </modules>
    <!-- start of override Customer AccountController -->

    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                    <customcustomer before="Mage_Customer">Dev_Customcustomer</customcustomer>
                    </modules>
                </args>
            </customer>
        </routers>
        <layout>
            <updates>
                <customcustomer>
                    <file>customcustomer.xml</file>
                </customcustomer>
            </updates>
        </layout>
    </frontend>
    <!-- helper -->
    <global>
        <helpers>
            <customcustomer>
                <class>Dev_Customcustomer_Helper</class>
            </customcustomer>
        </helpers>
    </global>
</config>

Account controller app/code/local/Dev/Customcustomer/controllers/AccountController.php

<?php
require_once Mage::getModuleDir('controllers','Mage_Customer').DS."AccountController.php";
class Dev_Customcustomer_AccountController extends Mage_Customer_AccountController{
    /**
     * Action predispatch
     *
     * Check customer authentication for some actions
     */
    public function preDispatch()
    {

        $action = $this->getRequest()->getActionName();
        $ExitsopenActions = array(
            'create',
            'login',
            'logoutsuccess',
            'forgotpassword',
            'forgotpasswordpost',
            'resetpassword',
            'resetpasswordpost',
            'confirm',
            'confirmation'
        );
        $newOpenAction=array('vendor','vendorcreate','vendorcreatePost','vendorloginPost');

        $allActions=array_merge($ExitsopenActions,$newOpenAction);

        /* check custom action */
        $Custompattern = '/^(' . implode('|', $newOpenAction) . ')/i';


        if (preg_match($Custompattern, $action)) {
            /* if match then set Current action to create for skip  parent::preDispatch(); */
            $this->getRequest()->setActionName('create');
        }
        parent::preDispatch();

           /**
            * Parent check is complete, reset request action name to origional value
            */
           if ($action != $this->getRequest()->getActionName())
           {
            $this->getRequest()->setActionName($action);
           }
           if (!$this->getRequest()->isDispatched()) {
            return;
           }

        $mypattern = '/^(' . implode('|', $allActions) . ')/i';

        if (!preg_match($mypattern, $action)) {
            if (!$this->_getSession()->authenticate($this)) {
                $this->setFlag('', 'no-dispatch', true);
            }
        } else {
            $this->_getSession()->setNoReferer(true);
        }



    }




    /* wholeSaler Login */
    public function vendorAction(){
            if ($this->_getSession()->isLoggedIn()) {
                $this->_redirect('*/*/');
                return;
            }
            $this->getResponse()->setHeader('Login-Required', 'true');
            $this->loadLayout();
            $this->_initLayoutMessages('customer/session');
            $this->_initLayoutMessages('catalog/session');
            $this->renderLayout();

    }
/* whole Sales customer create login */
    public function vendorcreateAction()
    {
        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*');
            return;
        }

        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->renderLayout();
    }

        /**
     * Login post action
     */
    public function vendorloginPostAction()
    {
        if (!$this->_validateFormKey()) {
            $this->_redirect('*/*/');
            return;
        }

        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*/');
            return;
        }
        $session = $this->_getSession();

        if ($this->getRequest()->isPost()) {
            $login = $this->getRequest()->getPost('login');
            if (!empty($login['username']) && !empty($login['password'])) {
                try {
                    $session->login($login['username'], $login['password']);
                    if ($session->getCustomer()->getIsJustConfirmed()) {
                        $this->_welcomeCustomer($session->getCustomer(), true);
                    }
                } catch (Mage_Core_Exception $e) {
                    switch ($e->getCode()) {
                        case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                            $value = $this->_getHelper('customer')->getEmailConfirmationUrl($login['username']);
                            $message = $this->_getHelper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                            break;
                        case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                            $message = $e->getMessage();
                            break;
                        default:
                            $message = $e->getMessage();
                    }
                    $session->addError($message);
                    $session->setUsername($login['username']);
                     $this->_redirect('*/*/vendor');
                    return;
                } catch (Exception $e) {
                    // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
                    $this->_redirect('*/*/vendor');
                    return;

                }
            } else {
                $session->addError($this->__('Login and password are required.'));
                     $this->_redirect('*/*/vendor');
                    return;

            }
        }
        //echo      'demo@gmail.com'.$session->getCustomerGroupId();
        //die();
        if($session->isLoggedIn()&& ($session->getCustomerGroupId()==4)){
            $this->gotorental();
            }
        elseif($session->isLoggedIn()&& ($session->getCustomerGroupId()==2)){
            $this->gotowholesale();
        }else{
        $this->_loginPostRedirect();
        }
    }



    /**
     * Create customer account action
     */
    public function vendorcreatePostAction()
    {
        /** @var $session Mage_Customer_Model_Session */
        $session = $this->_getSession();
        if ($session->isLoggedIn()) {
            $this->_redirect('*/*/');
            return;
        }
        $session->setEscapeMessages(true); // prevent XSS injection in user input
        if (!$this->getRequest()->isPost()) {
            $errUrl = $this->_getUrl('*/*/vendorcreate', array('_secure' => true));
            $this->_redirectError($errUrl);
            return;
        }

        $customer = $this->_getCustomer();

         $customer->setGroupId($vendorCustomeraGroup);

        try {
            $errors = $this->_getCustomerErrors($customer);

            if (empty($errors)) {
                $customer->save();
                $this->_dispatchRegisterSuccess($customer);
                $this->_RestsuccessProcessRegistration($customer);
                return;
            } else {
                $this->_addSessionError($errors);
            }
        } catch (Mage_Core_Exception $e) {
            $session->setCustomerFormData($this->getRequest()->getPost());
            if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
                $url = $this->_getUrl('customer/account/forgotpassword');
                $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
                $session->setEscapeMessages(false);
            } else {
                $message = $e->getMessage();
            }
            $session->addError($message);
        } catch (Exception $e) {
            $session->setCustomerFormData($this->getRequest()->getPost())
                ->addException($e, $this->__('Cannot save the  Whole Saller customer.'));
        }
        $errUrl = $this->_getUrl('*/*/vendorcreate', array('_secure' => true));
        $this->_redirectError($errUrl);
    }
public function createPostAction()
    {
        echo 'here1234';exit;
        echo 'here123';exit;
        $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));

        if (!$this->_validateFormKey()) {
            $this->_redirectError($errUrl);
            return;
        }

        /** @var $session Mage_Customer_Model_Session */
        $session = $this->_getSession();
        if ($session->isLoggedIn()) {
            $this->_redirect('*/*/');
            return;
        }

        if (!$this->getRequest()->isPost()) {
            $this->_redirectError($errUrl);
            return;
        }

        $customer = $this->_getCustomer();
/*$ek = $this->getRequest()->getPost();
print_r($ek);exit;*/
        try {
            $errors = $this->_getCustomerErrors($customer);

            if (empty($errors)) 
            {
                 if($this->getRequest()->getPost('group_id'))
                { 
                    $customer->setGroupId($this->getRequest()->getPost('group_id'));
                }                   
                else 
                {
                    $customer->getGroupId(); 
                }
                $customer->cleanPasswordsValidationData();
                $customer->save();
                $this->_dispatchRegisterSuccess($customer);
                $this->_successProcessRegistration($customer);
                return;
            } else {
                $this->_addSessionError($errors);
            }
        } catch (Mage_Core_Exception $e) {
            $session->setCustomerFormData($this->getRequest()->getPost());
            if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
                $url = $this->_getUrl('customer/account/forgotpassword');
                $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
            } else {
                $message = $this->_escapeHtml($e->getMessage());
            }
            $session->addError($message);
        } catch (Exception $e) {
            $session->setCustomerFormData($this->getRequest()->getPost());
            $session->addException($e, $this->__('Cannot save the customer.'));
        }

        $this->_redirectError($errUrl);
    }

}
Helper class
app/code/local/Dev/Customcustomer/Helper/data.php
<?php
class Dev_Customcustomer_Helper_Data extends Mage_Customer_Helper_Data
{
      public function getWLoginPostUrl()
    {
        $params = array();
        if ($this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME)) {
            $params = array(
                self::REFERER_QUERY_PARAM_NAME => $this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME)
            );
        }
        return $this->_getUrl('customer/account/vendorloginPost', $params);
    }
    public function getwLoginUrl()
    {
        return $this->_getUrl('customer/account/vendorlogin' ,$this->getLoginUrlParams());
    }
        public function getwRegisterUrl()
    {
        return $this->_getUrl('customer/account/vendorcreate' ,$this->getLoginUrlParams());
    }
    }
}

module XML app/etc/modules/Dev_Customcustomer.xml

<?xml version="1.0"?>
<!--we need to enable this module as any other if-->
<!--you wish to do it as standalone module extension-->
<config>
<modules>
<Dev_Customcustomer>
<active>true</active>
<codepool>local</codepool>
</Dev_Customcustomer>
</modules>
</config>
2

Issue in syntax in Dev_Customcustomer.xml.

The xml tag codepool should be codePool.

codepool's P should be in upper case .

Also suggestion to add depend at

Dev_Customcustomer.xml

<config>
    <modules>
        <Dev_Customcustomer>
            <active>true</active>
            <!-- codepool's p should uppercase letter -->
            <codePool>local</codePool> 
            <!-- add depends module -->
            <depends>
                <Mage_Customer/>
            </depends>
        </Dev_Customcustomer>
    </modules>
</config>

Also, you can checkout this link AccountController override not working on new Action and doing 302 redirection redirection issue

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.