Jump to content

How to modify dni/nif/nie field to accept other type of data?


Salus
 Share

Recommended Posts

Hi everyone, I need some help again, truly, this php is killing me.

 

I would like to modify dni field from adresses to be able to accept other type of data -  I have to modify it to accept other formats with more characters. So far the dni field is restricted to some kind of spanish registration number, which is 9 digits long only. I have to modify it to accept 20 digits long mixed characters, like J12/3568/1992/something

I found out it has something to do with validate.php,  and again objectmodel.php, but really dunno what to modify in those files to get the desired result. I tried to modify the lenght of field dierctly in ps_adress table to varchar(20), but obviously that was not enough. Please HELP!

 

Thanks a lot in advance and happpy holidays to everyone.

 

PS:

my other urgent unresolved topic follows:

 

http://www.prestashop.com/forums/topic/388174-how-to-use-a-truefalse-value-for-showing-product-availability-on-screen/?do=findComment&comment=1899317

 

Share this post


Link to post
Share on other sites

Thank you, M4, you saved my day again, it's working, i can input the field value on front office :)

 

BUT: it is not stored neither on the My account side of the client's account page-My adresses, neither on the admin back-panel. The ideea would be to be able to put the data on the receipt...

if the client pushes "actualize my adress" it is not stored, I get an empty field again. So it' s not getting stored anywhere :(

Share this post


Link to post
Share on other sites

Any ideeas why it is not getting stored in the database? what else do I have to modify? have to make some overrides in controllers or what?

 

I have cleaned the cache by removing cache/class_index.php and classes/class_index.php

Edited by Salus (see edit history)

Share this post


Link to post
Share on other sites

Ok, please someone help me out with this, couse I`m going crazy.

I gave up on modifying anything on existing fields, instead I created new field manually in the ps_adress table. I followed ever possible tutorial on how to make it visible on back office, some ppl even say you dont have to make any override, it will be shown. I tried everything, made override as instructed, or not, clearing controller cache, restoring database and home directory to a previous state, everything, still, the data field added DOES NOT SHOW UP where is shoud: localization -> countries ->mycountry ->edit -> adress format -> add fields form list. I use prestashop 1.5.6.1. I have 3 new fields added, none of them are shown into back office. So pelase someone tell me what am I missing here

Some screenshots about table BO. We are talking about last 4 records, from id 25-28

post-759375-0-10682300-1418910988_thumb.jpg post-759375-0-38027600-1418910978_thumb.jpg

 

Compilaton is on forced, cache disabled in performance tab. 

I aint got no class_index.php to delete anywhere in classes folder, before you ask.

 

THANKS.

Edited by Salus (see edit history)

Share this post


Link to post
Share on other sites

 

Thank you, nemo, I already did look into that tutorial, but in version 1.5.6, which I am using, the thing was implemented in another way. As yourself stated in the above tutorial, 


Please notice that this definition comes from Prestashop 1.6.0.5, and I therefore recommend to use your own from the original Address class, in case you have a different Prestashop version.

 

 

 

i already did the first step, my adress.php looks like this:

public static $definition = array(
'table' => 'address',
'primary' => 'id_address',
'fields' => array(
'id_customer' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_manufacturer' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_supplier' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_warehouse' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_country' =>  array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_state' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
'alias' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'company' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
'lastname' =>  array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'firstname' =>  array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'vat_number' =>   array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'address1' =>  array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
'address2' =>  array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
'postcode' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
'city' =>  array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
'other' =>  array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
'phone' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
'phone_mobile' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
'dni' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 16),
'deleted' =>  array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'date_add' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
'date_upd' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
'testJ' =>   array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
),
);

bolded the changes

At this point, the changed field and the new field should be visible in lcalization->country, isnt it? The modify of adminadresscontroller.php would be the next step, for visualization of the fields, but I never get to this since my fields dont even show up...

Edited by Salus (see edit history)

Share this post


Link to post
Share on other sites

A small test. WHerever you want in the front office, php file, do this, using a valid address id;

$test = new Address(1);

$test->testJ.

 

If it  gives error, the override is not taking place. Erase the class_index and retry.  Or, modify the core file directly and retry. If it works, try modifying the  back office address controller as well and check that it works. WHen it does, go back and see if the new field popped out

Share this post


Link to post
Share on other sites

A small test. WHerever you want in the front office, php file, do this, using a valid address id;

 

$test = new Address(1);

$test->testJ.

 

If it  gives error, the override is not taking place. Erase the class_index and retry.  Or, modify the core file directly and retry. If it works, try modifying the back office address controller as well and check that it works. WHen it does, go back and see if the new field popped out

 

Ok, I`m not sure i`m following you, but let me put it down what I comprehend of what you said:

 

I take adress.php for example, and put the two lines somewhere, outside of any function, using a valid adress id, like this?

 

public static $definition = array(
'table' => 'address',
'primary' => 'id_address',
'fields' => array(
'id_customer' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_manufacturer' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_supplier' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_warehouse' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_country' =>  array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_state' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
'alias' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'company' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
'lastname' =>  array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'firstname' =>  array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'vat_number' =>   array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'address1' =>  array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
'address2' =>  array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
'postcode' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
'city' =>  array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
'other' =>  array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
'phone' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
'phone_mobile' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
'dni' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 16),
'deleted' =>  array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'date_add' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
'date_upd' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
'testJ' =>   array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
),
);

$test = 102;
$test->testJ

..and see if anythig happens?

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
 Share

×
×
  • Create New...

Important Information

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