Jump to content

Prestashop 1.7 customizing address form


Recommended Posts

Can you be more specific about what you're trying to remove? If it's simply the phone numbers, you can go to Preferences > Customers and change "Phone number is mandatory" to "No" and then remove the phone number fields from the theme's TPL files.

 

You can also go to Localization > Countries to change the address format for a country. That will also change the fields and order when entering addresses. Note that some fields are required, so they can't be removed.

 

If you need to do more than that, you'll need to use overrides, since there are no hooks to change address fields.

Link to comment
Share on other sites

Hello and thank you for your response!

 

I could not find a good way to achieve this so I just edited address-form.tpl, but I was trying to avoid that method so I asked here.

        {if $field['name']|strstr:"id_country"}
         {continue}
        {/if}

        {if $field['name']|strstr:"address2"}
         {continue}
        {/if}

        {if $field['name']|strstr:"vat_number"}
         {continue}
        {/if}

        {if $field['name']|strstr:"company"}
         {continue}
        {/if}

I understand using overrides would be right way to do this but I'm not familiar with overrides. Is there any basic tutorial for that?

 

 

Also, additional notes field is removed from the order procedure in 1.7 so I will need to find a way to put that in.

Link to comment
Share on other sites

  • 9 months later...
  • 5 months later...
  • 10 months later...
On 3/2/2017 at 2:46 PM, telnett said:

I need to add/remove some fields in the address form, what would be the best approach?

 

Is there a hook that I could make use of for this matter?

I think the easiast way in prestashop 1.7.5 is to edit your country in

International -> zone géographique ->  pays

You can do approximately all you want there. Thank you Prestashop.

  • Thanks 3
Link to comment
Share on other sites

  • 7 months later...
On 3/27/2019 at 11:31 AM, romerson said:

I think the easiast way in prestashop 1.7.5 is to edit your country in

International -> zone géographique ->  pays

You can do approximately all you want there. Thank you Prestashop.

THANK YOU !!!!

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Creating function in your controller/module/class.

It's dummy way to create it rawly, better to use ForMbuilder of prestashop.

But anyway my code works:

public function createAddressCustom(){
        if (((bool)Tools::isSubmit('create_address_custom')) == true){
            $user_address_surname = Tools::getValue('adress_surname');
            $user_address_name = Tools::getValue('adress_name');
            $user_address_address = Tools::getValue('adress_adress');
            $user_address_complement = Tools::getValue('adress_complement');
            $user_address_postcode = Tools::getValue('adress_postcode');
            $user_address_city = Tools::getValue('adress_city');
            $user_address_country = Tools::getValue('adress_country');
            /*creating address*/
            $address = new Address(null, $this->context->language->id);
            $address->lastname = trim(ucfirst($user_address_surname)); 
            $address->firstname = trim(ucfirst($user_address_name));
            $address->address1 = ucfirst($user_address_address);
            $address->address2 = ucfirst($user_address_complement);
            $address->postcode = trim($user_address_postcode);
            $address->city = ($user_address_city);
            $address->id_customer = (int) $this->context->customer->id;
            $address->id_country = (int)19;
            $address->id_state = 0;
            $address->alias = 'Mon adresse'; 
            //dump($address);
            $address->save();       
        }
    }

And .tpl file below

<form>
  <div class="form-group">
    <label for="exampleInputEmail1">Nom</label>
    <input type="text" class="form-control text-capitalize" id="" name="user_surname"  placeholder="">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Prenom</label>
    <input type="text" class="form-control text-capitalize" id="" name="user_name"  placeholder="">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="" name="user_email" namearia-describedby="emailHelp" placeholder="Votre email">
    <small id="emailHelp" class="form-text text-muted">Nous ne partagerons jamais votre e-mail avec quelqu'un d'autre</small>
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="" name="user_password" placeholder="Password">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Numero de telephone</label>
    <input type="number" class="form-control" id="" name="user_phone" placeholder="Example:0041761234567">
    <small id="emailHelp" class="form-text text-muted"></small>
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Date de naissance</label>
    <input type="date" class="form-control" id="" name="user_birthdate" placeholder="jj/mm/aa">
    <small id="emailHelp" class="form-text text-muted">Date de votre naissance</small>
  </div>



  <button type="submit" class="btn btn-primary" name="create_user_custom" value="Save">Submit</button>
</form>

Dont forget to add phone number to ps_customer table, because I link the phone not to adress but to customer.

Also dont forget to link your tpl to the controller/module:

return $this->display(__FILE__, 'views/templates/front/create_order.tpl');
//or path you desire

P.S. just remember, you need to adapt the code to your needs, it's something as cheatsheet I wrote you and code was written to my needs. 

Edited by Amantha Bill (see edit history)
  • Like 1
Link to comment
Share on other sites

On 4/6/2020 at 10:04 AM, Amantha Bill said:

Creating function in your controller/module/class.

It's dummy way to create it rawly, better to use ForMbuilder of prestashop.

But anyway my code works:


public function createAddressCustom(){
        if (((bool)Tools::isSubmit('create_address_custom')) == true){
            $user_address_surname = Tools::getValue('adress_surname');
            $user_address_name = Tools::getValue('adress_name');
            $user_address_address = Tools::getValue('adress_adress');
            $user_address_complement = Tools::getValue('adress_complement');
            $user_address_postcode = Tools::getValue('adress_postcode');
            $user_address_city = Tools::getValue('adress_city');
            $user_address_country = Tools::getValue('adress_country');
            /*creating address*/
            $address = new Address(null, $this->context->language->id);
            $address->lastname = trim(ucfirst($user_address_surname)); 
            $address->firstname = trim(ucfirst($user_address_name));
            $address->address1 = ucfirst($user_address_address);
            $address->address2 = ucfirst($user_address_complement);
            $address->postcode = trim($user_address_postcode);
            $address->city = ($user_address_city);
            $address->id_customer = (int) $this->context->customer->id;
            $address->id_country = (int)19;
            $address->id_state = 0;
            $address->alias = 'Mon adresse'; 
            //dump($address);
            $address->save();       
        }
    }

And .tpl file below


<form>
  <div class="form-group">
    <label for="exampleInputEmail1">Nom</label>
    <input type="text" class="form-control text-capitalize" id="" name="user_surname"  placeholder="">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Prenom</label>
    <input type="text" class="form-control text-capitalize" id="" name="user_name"  placeholder="">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="" name="user_email" namearia-describedby="emailHelp" placeholder="Votre email">
    <small id="emailHelp" class="form-text text-muted">Nous ne partagerons jamais votre e-mail avec quelqu'un d'autre</small>
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="" name="user_password" placeholder="Password">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Numero de telephone</label>
    <input type="number" class="form-control" id="" name="user_phone" placeholder="Example:0041761234567">
    <small id="emailHelp" class="form-text text-muted"></small>
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Date de naissance</label>
    <input type="date" class="form-control" id="" name="user_birthdate" placeholder="jj/mm/aa">
    <small id="emailHelp" class="form-text text-muted">Date de votre naissance</small>
  </div>



  <button type="submit" class="btn btn-primary" name="create_user_custom" value="Save">Submit</button>
</form>

Dont forget to add phone number to ps_customer table, because I link the phone not to adress but to customer.

Also dont forget to link your tpl to the controller/module:


return $this->display(__FILE__, 'views/templates/front/create_order.tpl');
//or path you desire

P.S. just remember, you need to adapt the code to your needs, it's something as cheatsheet I wrote you and code was written to my needs. 

Sorry i'm a newbie... Could you specify what files we have to maintain exactly?

Thx

Link to comment
Share on other sites

  • 2 years 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...