Jump to content

override/controllers/AuthController preProcess for adding custom field to $customer


EQ10000

Recommended Posts

I added a custom field 'mobilephone' to table customer. The field should be required when registration.

  1. executed a SQL to alter table customer, add the field.
    ALTER TABLE customer ADD mobilephone VARCHAR(8) NOT NULL AFTER lastname, ADD INDEX mobilephone_idx (mobilephone);


  2. created a override class customer, assign a new array to protected $fieldsRequired, and function getFields()
  3. modified templates authentication.tpl & modules/ in theme.

However, when I try to override the AuthController.php, I don't know where to place the

parent::preProcess();

in the function preProcess(). The parent declared the object $customer, and $customer->add() to database together inside same function.

 

Here is my override AuthController.php

public function preProcess()
{
 parent::preProcess(); /* place here for declaring object $customer */

 /** Create A/C */
 if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount'))
 {
  echo "submitAccount"; /*show if run ... but never show ?*/

  if (Tools::getValue('mobilephone'))
   $customer->mobilephone = Tools::getValue('mobilephone'); /* assign in object */
  else
   $this->errors[] = Tools::displayError('Please input mobilephone number for registration');
 }

 parent::preProcess(); /* place here for $customer->add() after assigned */

}

 

thanks

ML

Link to comment
Share on other sites

Place all content of

if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount'))

{

}

condition with in preProcess() method of overriden class.

and do something like this.

 

public function preProscess(){

if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount'))

{

}

else

parent::preProcess();

}

Link to comment
Share on other sites

OK. I see. Thanks!

 

Well, but I found that I didnt need to override identityController.php and update end-user profile mobilephone sucessfully.

I just overrided classes/customer.php, added a input in the form in the themes/*/identity.tpl

 

Do I need to really override the function preProcess() in AuthController.php to make it work for registration? But I got the following message still even I already input the mobilephone number.

Fatal error (Customer->mobilephone is empty)
Link to comment
Share on other sites

Hi, please allow me to ask a simple and stupid question.

 

Inside classes/Customer.php, there is a declare on the variable.

protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email');

 

As there is no _construct() function. How to append more elements to the array in the override classes/customer.php?

 

Thanks.

Link to comment
Share on other sites

Fatal error (Customer->mobilephone is empty)

It can be solved in creating cutomer by placing $fieldsValidate in overriding class customer also.

And there is no need to modify or override authController.php

 

So, there is a potential bug that identify.php does not use $fieldsValidate and no error produced if it was missed in override.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...