Adding Address Fields to the Registeration form in Prestashop

Viewed 3582

When a customer or user registers, 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 to the ps_address table , how to do this?enter image description here

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 I am calling processPostAddress from processSubmitAccount() in controller/front/Authcontroller.php page before the redirection to the account page.

 $this->processPostAddress(); //// custom function call 
 Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account'));

Below is the custom function which i created in controller/front/Authcontroller.php page

      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 should add the address to the addresss table             }
    }

Please help me or tell me if I am doing anything wrong or how to achieve this

1 Answers
Related