PrestaCraft on Facebook

Please like our page on Facebook to get notifications about new tutorials :)


PrestaCraft

PrestaCraft on Facebook

Please like our page on Facebook to get notifications about new tutorials :)


PrestaCraft

After quite big success of my tutorial about adding new fields to the registration form in PrestaShop 1.6 I’ve decided to create one for 1.7. There are some similarities according to 1.6 version.

Warning

I’m aware that this solution may not work for PrestaShop 1.7.6+ versions. That’s due to PrestaShop 1.7 changing architecture. If you use this version or newer, you should consider looking for a module which is reponsible for adding new fields to the registration form. I have plans to release such module, however due to my limited time I don’t know when. Thanks for understanding!

Looking for PrestaShop 1.6 version of this tutorial? Click here!
Before any changes, please remember to do a backup of all your files! I don’t take any responsibility for presumable inconveniences or bugs which may occur after those modifications.

FrontOffice modifications

Let’s start with adding new columns called my_field and my_field_required to the ps_customer table . Go to your phpMyAdmin and execute the following SQL command.

Edit: classes/form/CustomerFormatter.php

Now it’s time to edit CustomerFormatter class to make our fields visible in the registration form.

Find:

Add before:

Of course, you can change the position of new fields and put it wherever you want.

Edit: classes/Customer.php

Now, extend your Customer model by adding new columns. You can also add there a validation and determine if the field must be required.

Find:

Add after:

Find:

Add after:

Save the file and go to your customer registration form page. You should see something like this:

Remeber that your customers are now able to edit values of those fields in the Information section in the My account page. In the form you can see after clicking on:

That’s enough – time for the backoffice.

BackOffice modifications

Let’s display our fields in the BackOffice > Customer Settings > Customer Settings.

First, you must just add new form fields in the Admin Customers Controller. Look at the code.

Edit: controllers/admin/AdminCustomersController.php

Find:

Add after:

Now if you go to the customer creation/edit form you are going to see two new fields:

Time to display the data in backoffice customer page.

Edit: adminXXX/themes/default/template/controllers/customers/helpers/view/view.tpl
Find:

Add after:

Now your values are visible as you can see below:

Add your new field to the BackOffice Customer table

If you wish to display your field in BackOffice Customer table (in the Customer Settings -> Customer Settings tab), you must edit AdminCustomersController and make it aware of the new field.

Edit: controllers/admin/AdminCustomersController.php
Find:

Add after:

Find:

Add after:

Save the file and you’ll see new columns in this table:

Set overrides

Last and very important thing is to move all Your changes to override/ directory.
1. Copy and paste files:


Source Destination
controllers/admin/AdminCustomersController.php override/controllers/admin/AdminCustomersController.php
classes/Customer.php override/classes/Customer.php
classes/form/CustomerFormatter.php override/classes/form/CustomerFormatter.php

2. Replace in DESTINATION files:
class AdminCustomersControllerCore extends AdminController replace with class AdminCustomersController extends AdminCustomersControllerCore
class CustomerCore extends ObjectModel replace with class Customer extends CustomerCore
class CustomerFormatterCore implements FormFormatterInterface replace with class CustomerFormatter extends CustomerFormatterCore

3. Purge cache:
Remove /app/cache/ directory.

That’s it. Thanks for reading. If you face any problem or just want to say “thank you”, leave a comment here. If you like my articles and modules, please consider donation.

Leave a comment

Your email address will not be published.

34 comments

Leave a comment

Your email address will not be published.