Jump to content
vm0824

How to make phone number mandatory

Recommended Posts

Hello,

   I am looking to learn a bit of development for my site. One small project, is I'd like for the phone number field to be mandatory in my address blocks. Here are the steps taken so far.

  1. I was able to look in the theme and find that checkout/_partials/address-form.tpl seems to be responsible for the the checkout portion. It extends customer/_partials/address-form.tpl.
  2. customer/_partials/address-form.tpl however does not seem to list out the fields here. Instead of iterates over a $formFields variable and then creates the fields from that. 
  3. This is where I am stuck. 

Question: How do I find out where the $formFields variable is defined? And how can I edit it in a way that does not affect updates\upgrades and follows the best coding standards?

Share this post


Link to post
Share on other sites

This used to be a configuration option, however it looks like yet another feature that Prestashop has removed.  I thought maybe they moved the option to the Country settings (similar to the postal code and states), but not there either. 

 

Looks like you will need to research the following in classes\form

CustomerAddressForm.php

CustomerAddressFormatter.php

CustomerAddressPersister.php

Share this post


Link to post
Share on other sites

Thanks! was able to find the settings. A bit hidden, but its still there in 1.7

Share this post


Link to post
Share on other sites

Customers > Addresses > Set required fields for this section > Phone_mobile

 

Make sure youre added in locations > countries > phone_mobile 

 

You need to know about issue connected with the option "Set required fields for this section" from Back Office (at least in 1.7.1.1). 

 

Eg.: when you set the 'phone' field as 'required' and you have already customers in database who did not enter phone number during last orders, they will not able to make new orders

They will get Error 500 screen.

My customers was not able to find out why they havegot this nic error...

 

IMHO the option should has the warning about consequences it or there should check all entries in database before save new set of required fields.

  • Like 1

Share this post


Link to post
Share on other sites

If you have an account and the phone is not insert, the page of order will get Error 500.

Share this post


Link to post
Share on other sites
Guest mmismail

Thanks! was able to find the settings. A bit hidden, but its still there in 1.7

Can you please let me know where is that hidden settings ?

Share this post


Link to post
Share on other sites

as Vilius said 
Customers > Addresses > Set required fields for this section > Phone_mobile

Make sure youre added in locations > countries > phone_mobile 

Share this post


Link to post
Share on other sites

Hi Varma,

Have you solved this issue? I faced same problems - PS 1.7.2.4. If phone field is set as mandatory PS returns error 500.

Many thanks

Karol

Share this post


Link to post
Share on other sites
On 6/8/2017 at 10:36 AM, luca82 said:

If you have an account and the phone is not insert, the page of order will get Error 500.

 

likely that you already have accounts created without phone numbers. you'll have to populate them

Share this post


Link to post
Share on other sites

what exactly are you expecting prestashop to fix?  Did you report some kind of issue to prestashop using their forge?r

Share this post


Link to post
Share on other sites

If you get error 500 this is because your country/countries doesn't have the mandatory field you want to add, that's why you are getting error 500.

What happens if you want to add a mandatory field for DELIVERY ONLY or INVOICE ONLY???

 

Any ideas or where to edit? I'm not really familiar with php.

 

Regards

Share this post


Link to post
Share on other sites

Guys, I would like to ask you this:

Is there a way to manually add a phone (or others) field in the "already-registered-customer" page? I mean, if we can add the wanted field in the customer information's page, we could "ask" them to update their infos. So, if people updates all the required fields, they shouldn't have problems.

Now, i know that saying that is simple, the problem is to find the way to "add" this field. Is there someone that knows something about that?

Share this post


Link to post
Share on other sites
1 hour ago, Marco said:

Is there a way to manually add a phone (or others) field in the "already-registered-customer" page?

Could elaborate on what this means exactly?  What is an 'already registered customer page' ?  Perhaps provide a screen shot

Share this post


Link to post
Share on other sites

Hey guys.....This is SOLVED PS 1.7xx !!

I found the answer to this question, I was having the same issue with the phone number, I wanted the phone # mandatory.

No coding need, just a simple checked mark is needed.

In your BO > Customers > Addresses>   @ the bottom of your customer list

there is " + set required fields for this section"    click that button.

Check all fields you need, including phone number!!

Only took me 2 weeks to figure this out. I couldn't find this anywhere.

Hope this help. 

 

 

 

Edited by DEN
not solved

Share this post


Link to post
Share on other sites

Sorry guys

Changing this give me an 500 error.

Im working on this. if and when I find a fix, I will post.

  • Like 1

Share this post


Link to post
Share on other sites

Alright Guys, this will make the phone number mandatory in your checkout/cart

I got this to work. Hope this fix works for you.

1st go here.

In your BO > Customers > Addresses>   @ the bottom of your customer list

there is " + set required fields for this section"    click that button.

UNCHECK ALL>>>> save!!  

Next, go here>>> International>> Locations>> Countries >> for me, edit " USA "   (I only sell in the USA. This part can get tricky, for ALL the countries you have in your checkout/cart, you must do this to.)

This is how mine is setup:

firstname lastname
company
address1
address2
State:name
postcode city
phone
Country:name

SAVE YOUR WORK!!!

After setting this up, make sure this works in the checkout/cart. (for all counties) with OUT errors. Do some testing. At this point , phone will still be optional.  Again , make sure it works before moving on, very important!!!

Next >> go back to

In your BO > Customers > Addresses>   @ the bottom of your customer list

there is " + set required fields for this section"    click that button.

Now check mark ONLY the phone,   SAVE! This makes it Mandatory.

For some reason, my screen shots would not upload, sorry.

Now this is SOLVED!   Hope this help ya.

Share this post


Link to post
Share on other sites

But its not solved still...

I populate all pre-existing addresses in database so they dont have blank/null phone fields.

Submit address during test checkout with phone number and it goes to 500 page. No error reporting anywhere either.

Share this post


Link to post
Share on other sites

Further debugging.. when phone is set as required, form submit says id_country is not set

Share this post


Link to post
Share on other sites

 I don't get this error anymore, seems to be fixed now.

I am running 1.7.4.4 and if I add the telephone as required field, existing customers that do not have that field populated, are warned that there is a field missing and the continue button is greyed out until they add it.

I simply added the mandatory field through: BO > Customers > Addresses>   @ the bottom of your customer list there is " + set required fields for this section"  click that button.

 

 

Share this post


Link to post
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

×

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More