Jump to content

Adding A Addresss Fields When Registering The User In Prestashop


JERRY777

Recommended Posts

When a customer or user register I want to capture the address details in one click and save that in ps_address table , ie when he clicks on the register button his address details must be also saved , how to do this

I have managed to customize the registration form and able to plug the address details form to my registration form as shown in the attached image  :

  
Now what I am stuck with is : when am clicking on the Register button ,the address field details are not saved in the database and I am getting server error 
 

What i tried to do is ,I created  a new function called  processPostAddress and calling that function from Authcontroller.php page from
 

$this->processPostAddress(); //// custom function call  after a customer is created and before redirecting
 Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account'));
 
Below is the custom function which i created 
   public function processPostAddress()
    {
if($this->context->customer->id_customer!=''){
$address                = new Address();
$address->id_customer   = 40;        
$address->firstname     = trim(Tools::getValue('firstname'));
$address->lastname      = trim(Tools::getValue('lastname'));
$address->address1      = trim(Tools::getValue('address1'));
$address->address2      = trim(Tools::getValue('address2'));
$address->postcode      = trim(Tools::getValue('postcode'));
$address->city          = trim(Tools::getValue('city'));
$address->country       = trim(Tools::getValue('country'));
$address->state         = trim(Tools::getValue('state'));
$address->phone         = trim(Tools::getValue('phone'));
   $address->phone_mobile  = trim(Tools::getValue('phone_mobile'));
$address->add(); // This must add the address to the addresss table when customer registers first time
}
}
 
Please  help me  or tell me if am doing anything wrong 

post-1203432-0-36164700-1458198668_thumb.png

Edited by JERRY777 (see edit history)
Link to comment
Share on other sites

  • 5 months later...

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...