Jump to content
derailed

[SOLVED] Adding new fields to NEW ACCOUNT

Recommended Posts

Hello !

I want to add more fields ( company registration info ) to the New account registration form. I want the entry in the field to make it's way to the database and also be viewable in the back office accounts management.

From what I figured I added this entry in authentification.tpl:


{l s='C.U.I.'}
<input type="text" class="text" id="cui" name="cui" value="{if isset($smarty.post.cui)}{$smarty.post.cui}{/if}" />



and I also added in /classes/Adress.php:

/** @var string C.U.I. (optional) */
public $cui;
.
Now what ?

I think I will try adding mannualy a "cui" row in the ps_address in the prestashop database. Is that enough to make the field register?
What is needed to make it appear in back office ?

Thank you

Share this post


Link to post
Share on other sites

Ok. This is what I needed to achieve and how I did it.
WARNING! Moderate HTML/PHP and MySql knowhow needed. Don't try to do this unless you know what you are doing, it might make your shop unusable. Try first on a test server.
Paths to files might be different depending on your install. MySql prefix for the table might also be different.
Italic text is the code you need add.


I needed 1 custom field in the registration form. This field request company registration info from the client. This information needs to make it's way to the shop database and from there be accessible by the back office and also be presented on the invoice.

There are 4 files needed to be edited:

/themes/prestashop/authentification.tpl - this adds the actual fields in the registration form
/classes/Address.php - this makes the addresses management, it tells the form how to handle the submitted info
/admin/tabs/AdminAddresses.php - this allows the back office to retrieve and edit the submitted info
/classes/PDF.php - this handles the on request construction of pdf invoices

1. /themes/prestashop/authentification.tpl

This is an example of a custom textfield added. You need to add this between two paragraphs as needed, in the account-creation_form form.


{l s='C.I.F.'}
<input type="text" class="text" id="cif" name="cif" value="{if isset($smarty.post.cif)}{$smarty.post.cif}{/if}" />



2. /classes/Address.php

In this file there are several places in witch code needs to be added:

In class "Address extends ObjectModel" you need to add :

/** @var string C.I.F. (optional) */
public $cif;

In "protected $fieldsSize = array" you need to add:

'cif'=>32

In "protected "$fieldsValidate" you need to add:

'cif' => 'isGenericName'

In "public function getFields()
{
parent::validateFields();
if (isset($this->id))"

you need to add:

$fields['cif'] = pSQL($this->cif);

3. /admin/tabs/AdminAddresses.php

You need to add in the code that makes the form for the BackOffice address management, in my case line 238, after the Company text field:

'.$this->l('C.I.F.').'

<input type="text" size="33" name="cif" value="'.htmlentities($this->getFieldValue($obj, 'cif'), ENT_COMPAT, 'UTF-8').'" />
'.$this->l('Invalid characters:').' <>;=#{} 


4. /classes/PDF.php

You need to add in " /* Display address information */" and position as needed, in my case after the company name, after this :
{
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->company), 0, 'L');
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->company), 0, 'L');
$pdf->Ln(5);
}

add this:

$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->cif), 0, 'L');
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->cif), 0, 'L');
$pdf->Ln(5);
.

To make this work you also need to add a new field in the "ps_address" table in the prestashop mysql database:
Using phpMyAdmin, navigate to the prestashop database, ps_address table, Structure tab. At the bottom of the structure table select: Add 1 fields At The End Of The Table. In the new page add "cif" in the Field section, VARCHAR for type, 32 for Length/Values, select null and type" NULL" in the Default field.

This should be it.
  • Like 1

Share this post


Link to post
Share on other sites

I've been trying to do this exact same thing but with a different type of field. A "description_mini" field, which is just text with a maximum of 10 words. Can you please help me? I added the field in the ps_product_lang table but can't use it in the front office unless i edit the files in prestashop and i tried finding every "description_short" field and rename it as "description_mini" just to test, but it doesn't come up with calling it on the website, nothing comes up!

I'm seriously pulling my hair out here! please help a brother out! thanks

Share this post


Link to post
Share on other sites

Derailed . You have 2 errors in your site

Warning: require_once(/home/autodotr/public_html/config/../classes/MailAlerts.php) [function.require-once]: failed to open stream: No such file or directory in /home/autodotr/public_html/config/config.inc.php on line 20

Fatal error: require_once() [function.require]: Failed opening required '/home/autodotr/public_html/config/../classes/MailAlerts.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/autodotr/public_html/config/config.inc.php on line 20

In http://www.autodot.ro/modules/mailalerts/myalerts.php

And the second it`s that you can not make or edit your old Adress

Acasa>Contul meu>Adresele mele

Add an adress link to http://www.autodot.ro/address.php When it should be http://www.autodot.ro/addresses.php

Btw did you make that you can add or edit your adress from withing user panel that yu can modify the CIF, IBAN, etc ?

On http://www.mobila-online.biz/ when i click on modify my adress from the Front Office it`s show the standard settings.



It`s the same to edit ?

Good luck and maybe you will make a module that people can add or substract lines from the registration.

Share this post


Link to post
Share on other sites

Hello !

Thank you for the error reports. The 1'st error I am aware of and actually can't seem to figure out what is the problem. It's not permissions related , and no modifications had been made to the mailalerts module, so I guess it must be database related. Maybe in my many shop upgrades something went wrong.

The 2'nd error was caused by a missing address.php file, and now it's fixed. Thank you ! No the file name is correct , there is a address.php and one adresses.php file.

Yes I have added the posibility to edit the CIF and Recom entries from within Front office and also Back office. I will post soon the steps to do it.

I don't think it's posibble to make a module that will handle extra entries in the registration form since it requires modifyng core files. Maybe if someone would implement this feature in the official release.

Marius

Share this post


Link to post
Share on other sites

To add editable custom entries in the user cp you must edit two files : address.tpl and addresses.tpl in your theme's folder:

1. address.tpl:

In the form declaration you must add the following two fieldsets ( modify names as needed):


<input type="hidden" name="token" value="{$token}" />
{l s='CIF'}
<input type="text" id="cif" name="cif" value="{if isset($smarty.post.cif)}{$smarty.post.cif}{else}{$address->cif|escape:'htmlall':'UTF-8'}{/if}" />




<input type="hidden" name="token" value="{$token}" />
{l s='Recom'}
<input type="text" id="recom" name="recom" value="{if isset($smarty.post.recom)}{$smarty.post.recom}{else}{$address->recom|escape:'htmlall':'UTF-8'}{/if}" />



2. addresses.tpl

Just after : " {if $address.company}{$address.company}{/if} " on line 21 ( i guess ) you must add :

{if $address.cif}{$address.cif}{/if}
{if $address.recom}{$address.recom}{/if}


ATTENTION: Follow all thread and make this modifications only after adding the custom columns to the mysql database.

Share this post


Link to post
Share on other sites

Hello here are the files modified . The files contain these fields: CUI; NR REG COM; IBAN. Make changes only in phpmyadmin. 10x derailed

Share this post


Link to post
Share on other sites

Hi all,

alex 84, where are the modified files? I guess you made 3 modification in database, ca you please tell us how you made-it?

thanks in advance.

catalin

Share this post


Link to post
Share on other sites

derailed, thank you very much for these tips.

I only have one problem:
In backoffice, text fields are empty (where values should be displayed). Does your code for backoffice work for you?

Share this post


Link to post
Share on other sites

cam ciudat mod de modificare a datelor unei firme ... ma refer la cui , iban etc etc etc ... le-am gasit la adresa ... nimeni nu le cauta acolo ... nu poate face o midificare sa fie puse la datele de indentificare , ca sa nu vorbesc de un alt mod de inregistrare a PJ ? ... din pagina de inregistrare sa se poate selecta PF sau PJ si in consecinta sa se introduca datele ... merci

propun sa mutam discutia pe forumul romanesc ... banuiesc ca numai pe noi ne intereseaza modul acesta de inregistrare

Share this post


Link to post
Share on other sites

Romaneste: eu am gasit o rezolvare , desi recunosc ca nu e cea mai potrivita ergonomic vorbind. Din pacate sunt doar programator de ocazie, mai mult designer si integrator. Eu am identificat legaturile, fisierele si modalitatea de editare, acum ar fi potrivit sa intervina un programator profi ca sa realizeze ce spui tu.

English: I found the way to adress this issue, but I admitt it's not the most easy and ergonomic way to do it. I am an designer and integrater. I pointed the links, files and the way to modify the files, now it is time for a real programmer to step in and make what you requested: a way for the client to select it's status : company or individual.

Let's hope someone in the prestashop staff will notice this request and adress it in feature versions.

Share this post


Link to post
Share on other sites

nu ma descurc in engleza asa ca o sa comunic numai in romaneste ...

intuitia m-a dus sa inecrc sa modific alte 2 fisiere ... indentity.php si indentity.tpl ... toate bune si frumoase numai ca in Fo in fereastra de indentificare nu imi aduce nimic din spate ... ramin aceleasi lucruri : nume, prenume si email ... poate totusi cu cunostintele tale reusesti sa ma pilotezi cum anume sa fac macar sa aduca din db cimpurile noi ...merci

Share this post


Link to post
Share on other sites

This has been very helpful for me..Thanks

I have added a custom field to customer info as id# by following the posts here. It works fine. Needed to update identity.tpl as well.

Now I'll delve into adding a drop down list for address for choosing city region..Will post when finished.

Share this post


Link to post
Share on other sites

I am using the customerRegistration module to require my customers to enter a valid code to gain access to a group. http://www.prestashop.com/forums/viewthread/10305/third_party_modules/module_customerregistration_management

I am trying to get that code they enter to pass through and show up in the backend. I've tried the methods described in this forum but I can't get it to work. I am wondering if that is because that input field was added on by a different module? It's all part of the same form so I'm not sure if that would matter. Any more tips or ways to pass a form input field into the Customer area of the back office?

Share this post


Link to post
Share on other sites

Hi - this has been very useful. Thank you


Instead of creating new customer fields, we want to create new product fields and these fields need to be visible when a customer is on our website looking to purchase a product.

Do the same principles apply?
thank you
Phyllis

Share this post


Link to post
Share on other sites

great solution! only I would like to note that there need to add fields in address.tlp, addresses.tlp and identity.tlp files.

Share this post


Link to post
Share on other sites

Dear all,
Reviving this thread as this is the best so far on the topic. I have managed to add a field at the account creation (a server serial number I need for key generation afterwards) and all is fine in English BUT as soon as I switch to an other langage, typically French in my case. I have the issue of the field not displayed and because I have made it mandatory, this is a blocker. I am trying to figure out how to make that flexible and localizable!
Anyone has done that by any chance?
Did I add the section in the wrong place in authentication.tpl?

Share this post


Link to post
Share on other sites

This topic is really interesting ! I had a look and I find very little (almost nothing) information about database customization.
Can somebody respond to the following question :
What are the implications in case of an update of Prestashop ?
I mean, when updating Prestashop, are the extra fields in the database going to remain there or the update is going to drop them ?
Also, are the modifications in the tpl and php files to be applied again and again, each time Prestashop comes with an update ?
Thanks.

Share this post


Link to post
Share on other sites

When you upgrade PrestaShop, it will simply add new fields and modify existing fields. It doesn't drop any tables. You shouldn't have any problem unless you've added a new field, then the next version of PrestaShop tries to add a field with the same name.

If you've modified PrestaShop's files, you will need to make those changes again whenever you upgrade the files. It's best to limit changes to your theme files and leave PrestaShop's PHP files alone.

Share this post


Link to post
Share on other sites

Hi, i have a huge problem, I've tried to add a custom field in the AdminProducts.php - it should be a drop down list with 4 options and the selected option should display next to the add to cart button. I appled similar steps as suggested here, but as soon as i add the adjusted code, the section "add product" dissapears. Any suggestions? Please? Pretty please?:)

Share this post


Link to post
Share on other sites

Hi, thanks for the help, but I have encountered a problem. I cannot view the new field I added from the Backoffice whilst clicking on a customer. It comes up empty. Typed in the correct field name.

What other file do I need to edit, besides the AdminAddresses.php

Share this post


Link to post
Share on other sites

I can't upgrade, because of file modified, many files.
I try this on PS 1.3.2.3 but it doesn't work, does'nt appear on authentication.php.
Any idea?
Please
I see new field in translation on backoffice, but I didn't see it in authentication

Share this post


Link to post
Share on other sites

thanks a lot, hints provided in this thread were quite useful.

I've managed to create my own fields in registration form (still being able to update/modify them from customer's point of view and back office as well) and use values from these fields in pdf invoice.

I can confirm that files needed to be modified are:

1. .../prestashop/classes/Address.php
2. .../prestashop/adminXXX/tabs/AdminAddresses.php
3. .../prestashop/themes/prestashop/address.tpl
4. .../prestashop/themes/prestashop/authentification.tpl
5. and your pdf template

Tested on PrestaShop 1.4.2.5!

Share this post


Link to post
Share on other sites

can't forget to mention,

besides the file modifications, also mysql modification is necessary!

If you want to add "field1" field into the registration form, keep on mind you need to have "field1" field added to your mysql database as well. As prestashop is storing/loading all these details form the database.

Say, you're using mysql database called "prestadb"

If you have shell access to mysql, use following commands:


mysql -u YOUR_MYSQL_USERNAME -p
(now mysql will ask you for your password, enter it)


use predstadb;
opens "prestadb" database


ALTER TABLE ps_address ADD field1 VARCHAR(60);
creates "field1" field in ps_address table


quit
gets you outta mysql :)

Could be helpful for somebody...

Share this post


Link to post
Share on other sites

Honestly there has to be an easier way? I'm trying to add the field "Company Phone" to the registration. I'm not sure why this isn't installed by default, but I'm in no way capable of editing the database or the php.

 

Is there any other way?

Share this post


Link to post
Share on other sites

I believe there exist some paid module to do that; however, speaking of free solution, you gotta go through all these "nasty" editing...

Share this post


Link to post
Share on other sites

Hi,

 

I've created module that will allow add extra fields to registration form. With that module you can easily create unlimited number of additional fields and sections on top and bottom of the registration form. The advantage of that module is that it doesn't override or change any core files.

 

Please check it here:

http://addons.presta...tom-fields.html

 

Regards,

modulesmarket.com

Share this post


Link to post
Share on other sites

Hi modulesmarket,

 

I bought yor module. Is it possible to include the added data in the confirmation email? If yes, how do i do that?

 

Thanks,

 

Barry

Share this post


Link to post
Share on other sites

Hi,

 

It's not possible by default but I can extend the module to met your requirement. I just need a details on that - please drop me the email with the details either by the Addons contact page or email - support@modulesmarket.com.

 

Regards,

Radek

Share this post


Link to post
Share on other sites

Hello friendz,

 

 

How to add new fields to the address in Prestashop 1.6.1.5

 

I have add two new field to address section in front office but i can't able add this process.

 

 

please help me 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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