<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; registration</title>
	<atom:link href="https://nemops.com/tag/registration/feed/" rel="self" type="application/rss+xml" />
	<link>https://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Get email notifications for new customers registrations</title>
		<link>https://nemops.com/email-notifications-new-customers/</link>
		<comments>https://nemops.com/email-notifications-new-customers/#comments</comments>
		<pubDate>Mon, 05 Jan 2015 11:38:16 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[customers]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[registration]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2264</guid>
		<description><![CDATA[<p>In this quick tip we will see how to enable email notifications for when a new client registers to our shop. The Plan Since we want to be informed when a new user registers, we need to add our code snippets right where the user itself is notified about it. For this reason, we will [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://nemops.com/email-notifications-new-customers/">Get email notifications for new customers registrations</a> appeared first on <a rel="nofollow" href="https://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In this quick tip we will see how to enable email notifications for when a new client registers to our shop.</p>
<p><span id="more-2264"></span></p>
<h2>The Plan</h2>
<p>Since we want to be informed when a new user registers, we need to add our code snippets right where the user itself is notified about it. For this reason, we will be extending the <strong>sendConfirmationMail</strong> method of the AuthController.php file, and create a new email template as well.</p>
<div class="separator"></div>
<h2>The AuthController override</h2>
<p>As always it&#8217;s good practice to use overrides instead of modifying core files directly (to preserve changes after updates). Therefore, create a new file called <strong>AuthController.php</strong> inside <em>override/controllers/front</em>. Inside php tags, paste the following override code:</p>
<pre class="brush: php; title: ; notranslate">
Class AuthController extends AuthControllerCore
{

	
}
</pre>
<p>As mentioned above, we need to extend the default <strong>sendConfirmationMail</strong> method, so let&#8217;s grab it from the original controller and paste it inside our override (this is from Prestashop 1.6.0.9):</p>
<pre class="brush: php; title: ; notranslate">
Class AuthController extends AuthControllerCore
{
	protected function sendConfirmationMail(Customer $customer)
	{
		if (!Configuration::get('PS_CUSTOMER_CREATION_EMAIL'))
			return true;

		return Mail::Send(
			$this-&gt;context-&gt;language-&gt;id,
			'account',
			Mail::l('Welcome!'),
			array(
				'{firstname}' =&gt; $customer-&gt;firstname,
				'{lastname}' =&gt; $customer-&gt;lastname,
				'{email}' =&gt; $customer-&gt;email,
				'{passwd}' =&gt; Tools::getValue('passwd')),
			$customer-&gt;email,
			$customer-&gt;firstname.' '.$customer-&gt;lastname
		);
	}
	
}
</pre>
<p>Just in case, let&#8217;s make sure emails still work. Erase the <strong>class_index.php</strong> located in the <em>cache/</em> folder. Then, try registering a new user and make sure you get the confirmation email. If you do, it&#8217;s time to add another rule to inform the admin; right before the return, add:</p>
<pre class="brush: php; title: ; notranslate">
Mail::Send(
			Configuration::get('PS_LANG_DEFAULT'),
			'account_for_admin',
			Mail::l('New client!'),
			array(
				'{firstname}' =&gt; $customer-&gt;firstname,
				'{lastname}' =&gt; $customer-&gt;lastname,
				'{email}' =&gt; $customer-&gt;email
				),
			Configuration::get('PS_SHOP_EMAIL'),
			Configuration::get('PS_SHOP_NAME')
		);
</pre>
<p><strong>Explanation:</strong> we just copied the returned code and adapted it to our needs;  first, instead of using the customer language to grab the email template, we use the shop&#8217;s default one. This way we don&#8217;t need to create multiple/translated templates. Then, we pass in &#8216;account_for_admin&#8217; as email template name; it doesn&#8217;t exist yet so don&#8217;t try running a new registration or it won&#8217;t work. Then, to preserve the user&#8217;s credentials we get rid of the password. Lastly we set the &#8220;to&#8221; parameter to the shop&#8217;s email, and set the receiver to the shop&#8217;s name. That&#8217;s all there is to it. Let&#8217;s now create that template.</p>
<div class="separator"></div>
<h2>Creating a new email template</h2>
<p>Instead of proceeding from scratch, I generally copy an existing html template, to have them all uniform. Let&#8217;s use that user welcome as base. Reach <em>mails/en</em> (or whatever your default language&#8217;s ISO is, you can check it in the back office, localization, languages); <strong>Clone both account.html and account.txt, and then rename them to account_for_admin.html and account_for_admin.txt</strong>. Open up the .txt file, it will look something like:</p>
<pre class="brush: xml; title: ; notranslate">


[{shop_url}] 

Hi {firstname} {lastname},

Thank you for creating a customer account at {shop_name}. 

Here are your login details:

E-MAIL ADDRESS: {email}

PASSWORD: {passwd} 		 

Important Security Tips:

* Always keep your account details safe.

* Never disclose your login details to anyone.

* Change your password regularly.

* Should you suspect someone is using your account illegally, please
notify us immediately.

You can now place orders on our shop: {shop_name}
[{shop_url}] 

{shop_name} [{shop_url}] powered by
PrestaShop(tm) [http://www.prestashop.com/] 


</pre>
<p>Let&#8217;s modify it so to fit our needs:</p>
<pre class="brush: xml; title: ; notranslate">


[{shop_url}] 

Hi!

A new customer just signed up for an account at {shop_name}. 

Here are the details:

E-MAIL ADDRESS: {email}

NAME: {firstname} {lastname}

</pre>
<p>Then, apply the same modifications to the html file (please note I am only copying relevant parts of the template):</p>
<pre class="brush: xml; title: ; notranslate">

&lt;tr&gt;
	&lt;td align=&quot;center&quot; class=&quot;titleblock&quot; style=&quot;padding:7px 0&quot;&gt;
		&lt;font size=&quot;2&quot; face=&quot;Open-sans, sans-serif&quot; color=&quot;#555454&quot;&gt;
			&lt;span class=&quot;title&quot; style=&quot;font-weight:500;font-size:28px;text-transform:uppercase;line-height:33px&quot;&gt;Hi {firstname} {lastname},&lt;/span&gt;&lt;br/&gt;
			&lt;span class=&quot;subtitle&quot; style=&quot;font-weight:500;font-size:16px;text-transform:uppercase;line-height:25px&quot;&gt;Thank you for creating a customer account at {shop_name}.&lt;/span&gt;
		&lt;/font&gt;
	&lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>To</p>
<pre class="brush: xml; title: ; notranslate">

&lt;tr&gt;
	&lt;td align=&quot;center&quot; class=&quot;titleblock&quot; style=&quot;padding:7px 0&quot;&gt;
		&lt;font size=&quot;2&quot; face=&quot;Open-sans, sans-serif&quot; color=&quot;#555454&quot;&gt;
			&lt;span class=&quot;title&quot; style=&quot;font-weight:500;font-size:28px;text-transform:uppercase;line-height:33px&quot;&gt;Hi!&lt;/span&gt;&lt;br/&gt;
			&lt;span class=&quot;subtitle&quot; style=&quot;font-weight:500;font-size:16px;text-transform:uppercase;line-height:25px&quot;&gt;A new customer just signed up for an account at {shop_name}.&lt;/span&gt;
		&lt;/font&gt;
	&lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>Then</p>
<pre class="brush: xml; title: ; notranslate">

&lt;tr&gt;
	&lt;td class=&quot;box&quot; style=&quot;border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0&quot;&gt;
		&lt;table class=&quot;table&quot; style=&quot;width:100%&quot;&gt;
			&lt;tr&gt;
				&lt;td width=&quot;10&quot; style=&quot;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
				&lt;td style=&quot;padding:7px 0&quot;&gt;
					&lt;font size=&quot;2&quot; face=&quot;Open-sans, sans-serif&quot; color=&quot;#555454&quot;&gt;
						&lt;p data-html-only=&quot;1&quot; style=&quot;border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px&quot;&gt;
							Your {shop_name} login details						&lt;/p&gt;
						&lt;span style=&quot;color:#777&quot;&gt;
							Here are your login details:&lt;br /&gt; 
							&lt;span style=&quot;color:#333&quot;&gt;&lt;strong&gt;E-mail address: &lt;a href=&quot;mailto:{email}&quot; style=&quot;color:#337ff1&quot;&gt;{email}&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
							&lt;span style=&quot;color:#333&quot;&gt;&lt;strong&gt;Password:&lt;/strong&gt;&lt;/span&gt; {passwd}
						&lt;/span&gt;
					&lt;/font&gt;
				&lt;/td&gt;
				&lt;td width=&quot;10&quot; style=&quot;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;
	&lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>To</p>
<pre class="brush: xml; title: ; notranslate">

&lt;tr&gt;
	&lt;td class=&quot;box&quot; style=&quot;border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0&quot;&gt;
		&lt;table class=&quot;table&quot; style=&quot;width:100%&quot;&gt;
			&lt;tr&gt;
				&lt;td width=&quot;10&quot; style=&quot;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
				&lt;td style=&quot;padding:7px 0&quot;&gt;
					&lt;font size=&quot;2&quot; face=&quot;Open-sans, sans-serif&quot; color=&quot;#555454&quot;&gt;
						&lt;p data-html-only=&quot;1&quot; style=&quot;border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px&quot;&gt;
							Your {shop_name} login details						&lt;/p&gt;
						&lt;span style=&quot;color:#777&quot;&gt;
							Here are your login details:&lt;br /&gt; 
							&lt;span style=&quot;color:#333&quot;&gt;&lt;strong&gt;E-mail address: &lt;a href=&quot;mailto:{email}&quot; style=&quot;color:#337ff1&quot;&gt;{email}&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
							&lt;span style=&quot;color:#333&quot;&gt;&lt;strong&gt;Password:&lt;/strong&gt;&lt;/span&gt; {passwd}
						&lt;/span&gt;
					&lt;/font&gt;
				&lt;/td&gt;
				&lt;td width=&quot;10&quot; style=&quot;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;
	&lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>Lastly, you can get rid of this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;tr&gt;
	&lt;td class=&quot;space_footer&quot; style=&quot;padding:0!important&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td class=&quot;box&quot; style=&quot;border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0&quot;&gt;
		&lt;table class=&quot;table&quot; style=&quot;width:100%&quot;&gt;
			&lt;tr&gt;
				&lt;td width=&quot;10&quot; style=&quot;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
				&lt;td style=&quot;padding:7px 0&quot;&gt;
					&lt;font size=&quot;2&quot; face=&quot;Open-sans, sans-serif&quot; color=&quot;#555454&quot;&gt;
						&lt;p style=&quot;border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px&quot;&gt;Important Security Tips:&lt;/p&gt;
						&lt;ol style=&quot;margin-bottom:0&quot;&gt;
							&lt;li&gt;Always keep your account details safe.&lt;/li&gt;
							&lt;li&gt;Never disclose your login details to anyone.&lt;/li&gt;
							&lt;li&gt;Change your password regularly.&lt;/li&gt;
							&lt;li&gt;Should you suspect someone is using your account illegally, please notify us immediately.&lt;/li&gt;
						&lt;/ol&gt;
					&lt;/font&gt;
				&lt;/td&gt;
				&lt;td width=&quot;10&quot; style=&quot;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;
	&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td class=&quot;space_footer&quot; style=&quot;padding:0!important&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td class=&quot;linkbelow&quot; style=&quot;padding:7px 0&quot;&gt;
		&lt;font size=&quot;2&quot; face=&quot;Open-sans, sans-serif&quot; color=&quot;#555454&quot;&gt;
			&lt;span&gt;You can now place orders on our shop: &lt;a href=&quot;{shop_url}&quot; style=&quot;color:#337ff1&quot;&gt;{shop_name}&lt;/a&gt;&lt;/span&gt;
		&lt;/font&gt;
	&lt;/td&gt;
&lt;/tr&gt;

						&lt;tr&gt;
							&lt;td class=&quot;space_footer&quot; style=&quot;padding:0!important&quot;&gt;&amp;nbsp;&lt;/td&gt;
						&lt;/tr&gt;
						&lt;tr&gt;
							&lt;td class=&quot;footer&quot; style=&quot;border-top:4px solid #333333;padding:7px 0&quot;&gt;
								&lt;span&gt;&lt;a href=&quot;{shop_url}&quot; style=&quot;color:#337ff1&quot;&gt;{shop_name}&lt;/a&gt; powered by &lt;a href=&quot;http://www.prestashop.com/&quot; style=&quot;color:#337ff1&quot;&gt;PrestaShop&amp;trade;&lt;/a&gt;&lt;/span&gt;
							&lt;/td&gt;
						&lt;/tr&gt;
					&lt;/table&gt;
				&lt;/td&gt;
				&lt;td class=&quot;space&quot; style=&quot;width:20px;padding:7px 0&quot;&gt;&amp;nbsp;&lt;/td&gt;
			&lt;/tr&gt;

</pre>
<p>And it&#8217;s done! Time to test the outcome!</p>
<div class="separator"></div>
<h2>Troubleshooting</h2>
<p>When dealing with emails and Prestashop, there is a high chance of failure. Don&#8217;t be discouraged if if doesn&#8217;t work at the first attempt, and check the following:</p>
<ul>
<li>- Send out a test email from advanced parameters -> emails to your mail address</li>
<li>- Make sure it didn&#8217;t end up in the spam folder</li>
<li>- Double-check the new template name, it must be <strong>account_for_admin</strong> everywhere</li>
<li>- Make sure you added the template to the correct iso folder. If unsure, clone it to every of them</li>
</ul>
<p>If you still don&#8217;t receive the email, it&#8217;s worth trying to kill the Mail::Send method in case of failure, by using the following code instead:</p>
<pre class="brush: php; title: ; notranslate">
Mail::Send(
			Configuration::get('PS_LANG_DEFAULT'),
			'account_for_admin',
			Mail::l('New client!'),
			array(
				'{firstname}' =&gt; $customer-&gt;firstname,
				'{lastname}' =&gt; $customer-&gt;lastname,
				'{email}' =&gt; $customer-&gt;email
				),
			Configuration::get('PS_SHOP_EMAIL'),
			Configuration::get('PS_SHOP_NAME'),
			null,null,null,null,_PS_MAIL_DIR_,true
		);
</pre>
<p>The last parameter I passed in is telling the method to die in case of failure. If that happens, you should be given more info about what went wrong.</p>
<p>The post <a rel="nofollow" href="https://nemops.com/email-notifications-new-customers/">Get email notifications for new customers registrations</a> appeared first on <a rel="nofollow" href="https://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://nemops.com/email-notifications-new-customers/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to add new fields to the customer address in Prestashop</title>
		<link>https://nemops.com/new-customer-address-fields-prestashop/</link>
		<comments>https://nemops.com/new-customer-address-fields-prestashop/#comments</comments>
		<pubDate>Tue, 22 Apr 2014 09:21:30 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[new fields]]></category>
		<category><![CDATA[overrides]]></category>
		<category><![CDATA[prestashop 1.6]]></category>
		<category><![CDATA[registration]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=1949</guid>
		<description><![CDATA[<p>In today&#8217;s tutorial, we will see how to add new fields to the customer address in Prestashop. UPDATE! If you prefer a simple solution, I created a module that automates the process and does much more, find it here Version used: Prestashop 1.6 (compatible with Prestashop 1.5) Plan of action In order to add a [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://nemops.com/new-customer-address-fields-prestashop/">How to add new fields to the customer address in Prestashop</a> appeared first on <a rel="nofollow" href="https://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In today&#8217;s tutorial, we will see how to add new fields to the customer address in Prestashop.</p>
<p><span id="more-1949"></span></p>
<p><strong>UPDATE! If you prefer a simple solution, I created a module that automates the process and does much more, find it <a href="http://store.nemops.com/modules/45-prestashop-address-fields.html#.WhvflkqWaUk" title="PrestaShop Address Fields Module">here</a></strong></p>
<a class="download-files button style1" href="http://nemops.com/wp-content/uploads/2014/04/new_registration_fields.zip" title="Download Project Files">Download Project Files</a>
<ul>
<li>Version used: Prestashop 1.6 (compatible with Prestashop 1.5)</li>
</ul>
<h2>Plan of action</h2>
<p>In order to add a new field to the address registration form, we will be adding a couple of overrides, as well as creating a new database field and modifying the address template file. If you are not familiar with Prestashop overrides, check out my article on <a href="http://nemops.com/extending-prestashop-objects/#.U1WG4Pna6r0" title="how to extend Prestashop objects" target="_blank">how to extend Prestashop objects</a> (although we will have to use a slightly different technique).</p>
<div class="separator"></div>
<h2>The address class and database table</h2>
<p>First things first, we need something to play with. We want the customer to be able to fill in a field which doesn&#8217;t currently exist, therefore let&#8217;s login to the database, access the <strong>ps_address</strong> table and create a new field: <strong>my_custom_field</strong>. I made it a 64 long VARCHAR field.</p>
<p>Next we need to tell the address object (class) that it has a new field to deal with. Create a new file inside <em>override/classes/</em> and call it <strong>Address.php</strong>. Add the following inside php tags:</p>
<pre class="brush: php; title: ; notranslate">



class Address extends AddressCore
{

	public $my_custom_field;


	public static $definition = array(
		'table' =&gt; 'address',
		'primary' =&gt; 'id_address',
		'fields' =&gt; array(
			'id_customer' =&gt; 		array('type' =&gt; self::TYPE_INT, 'validate' =&gt; 'isNullOrUnsignedId', 'copy_post' =&gt; false),
			'id_manufacturer' =&gt; 	   array('type' =&gt; self::TYPE_INT, 'validate' =&gt; 'isNullOrUnsignedId', 'copy_post' =&gt; false),
			'id_supplier' =&gt; 		array('type' =&gt; self::TYPE_INT, 'validate' =&gt; 'isNullOrUnsignedId', 'copy_post' =&gt; false),
			'id_warehouse' =&gt; 		array('type' =&gt; self::TYPE_INT, 'validate' =&gt; 'isNullOrUnsignedId', 'copy_post' =&gt; false),
			'id_country' =&gt; 		array('type' =&gt; self::TYPE_INT, 'validate' =&gt; 'isUnsignedId', 'required' =&gt; true),
			'id_state' =&gt; 			array('type' =&gt; self::TYPE_INT, 'validate' =&gt; 'isNullOrUnsignedId'),
			'alias' =&gt; 				array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isGenericName', 'required' =&gt; true, 'size' =&gt; 32),
			'company' =&gt; 			array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isGenericName', 'size' =&gt; 64),
			'lastname' =&gt; 			array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isName', 'required' =&gt; true, 'size' =&gt; 32),
			'firstname' =&gt; 			array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isName', 'required' =&gt; true, 'size' =&gt; 32),
			'vat_number' =&gt;	 		array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isGenericName'),
			'address1' =&gt; 			array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isAddress', 'required' =&gt; true, 'size' =&gt; 128),
			'address2' =&gt; 			array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isAddress', 'size' =&gt; 128),
			'postcode' =&gt; 			array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isPostCode', 'size' =&gt; 12),
			'city' =&gt; 				array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isCityName', 'required' =&gt; true, 'size' =&gt; 64),
			'other' =&gt; 				array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isMessage', 'size' =&gt; 300),
			'phone' =&gt; 				array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isPhoneNumber', 'size' =&gt; 32),
			'phone_mobile' =&gt; 		array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isPhoneNumber', 'size' =&gt; 32),
			'dni' =&gt; 				array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isDniLite', 'size' =&gt; 16),
			'deleted' =&gt; 			array('type' =&gt; self::TYPE_BOOL, 'validate' =&gt; 'isBool', 'copy_post' =&gt; false),
			'date_add' =&gt; 			array('type' =&gt; self::TYPE_DATE, 'validate' =&gt; 'isDateFormat', 'copy_post' =&gt; false),
			'date_upd' =&gt; 			array('type' =&gt; self::TYPE_DATE, 'validate' =&gt; 'isDateFormat', 'copy_post' =&gt; false),
			'my_custom_field' =&gt; 	array('type' =&gt; self::TYPE_STRING, 'validate' =&gt; 'isGenericName', 'size' =&gt; 64),

		),
	);
}
</pre>
<p><strong>Explanation:</strong> if you read my article on how to extend Prestashop Objects, you will notice I approached this override a little differently. I am not assigning the new field upon instance creation, but <strong>I am directly overriding its definition</strong>. The reason is simple: the Address definition is called statically when creating a new address in the front office, and if we added the new field in the construct method, we would have missed it from the list.</p>
<p>Please notice that this definition comes from <strong>Prestashop 1.6.0.5</strong>, and I therefore recommend to use your own from the original Address class, in case you have a different Prestashop version.</p>
<div class="separator"></div>
<h2>The back office Address Controller</h2>
<p>We are half the way through already, and at this point we need to override the back office controller responsible for displaying the address modification form for each customer.</p>
<p>Create a new file named <strong>AdminAddressesController.php</strong> in <em>override/controllers/admin/</em>. We need to extend the renderForm() method; thus, head over the main <em>controllers/admin</em> folder, open up the original <strong>AdminAddressesController.php</strong>, locate the <strong>renderForm()</strong> method and copy it. Then, add the following inside php tags in our <strong>new</strong> controller override:</p>
<pre class="brush: php; title: ; notranslate">

Class AdminAddressesController extends AdminAddressesControllerCore
{

}

</pre>
<p>And paste the renderForm() code inside the class. Here is how mine looks like, taken from Prestashop 1.6.0.5:</p>
<pre class="brush: php; title: ; notranslate">

Class AdminAddressesController extends AdminAddressesControllerCore
{


	public function renderForm()
	{
		$this-&gt;fields_form = array(
			'legend' =&gt; array(
				'title' =&gt; $this-&gt;l('Addresses'),
				'icon' =&gt; 'icon-envelope-alt'
			),
			'input' =&gt; array(
				array(
					'type' =&gt; 'text_customer',
					'label' =&gt; $this-&gt;l('Customer'),
					'name' =&gt; 'id_customer',
					'required' =&gt; false,
				),
				array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Identification Number'),
					'name' =&gt; 'dni',
					'required' =&gt; false,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('DNI / NIF / NIE')
				),			
				array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Address alias'),
					'name' =&gt; 'alias',
					'required' =&gt; true,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('Invalid characters:').' &amp;lt;&amp;gt;;=#{}'
				),
				array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Home phone'),
					'name' =&gt; 'phone',
					'required' =&gt; false,
					'col' =&gt; '4',
					'hint' =&gt; Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this-&gt;l('You must register at least one phone number.')) : ''
				),
				array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Mobile phone'),
					'name' =&gt; 'phone_mobile',
					'required' =&gt; false,
					'col' =&gt; '4',
					'hint' =&gt; Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this-&gt;l('You must register at least one phone number.')) : ''
				),
				array(
					'type' =&gt; 'textarea',
					'label' =&gt; $this-&gt;l('Other'),
					'name' =&gt; 'other',
					'required' =&gt; false,
					'cols' =&gt; 15,
					'rows' =&gt; 3,
					'hint' =&gt; $this-&gt;l('Forbidden characters:').' &amp;lt;&amp;gt;;=#{}'
				),
			),
			'submit' =&gt; array(
				'title' =&gt; $this-&gt;l('Save'),
			)
		);
		$id_customer = (int)Tools::getValue('id_customer');
		if (!$id_customer &amp;&amp; Validate::isLoadedObject($this-&gt;object))
			$id_customer = $this-&gt;object-&gt;id_customer;
		if ($id_customer)
		{
			$customer = new Customer((int)$id_customer);
			$token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this-&gt;context-&gt;employee-&gt;id);
		}

		$this-&gt;tpl_form_vars = array(
			'customer' =&gt; isset($customer) ? $customer : null,
			'tokenCustomer' =&gt; isset ($token_customer) ? $token_customer : null
		);

		// Order address fields depending on country format
		$addresses_fields = $this-&gt;processAddressFormat();
		// we use  delivery address
		$addresses_fields = $addresses_fields['dlv_all_fields'];

		$temp_fields = array();

		foreach ($addresses_fields as $addr_field_item)
		{
			if ($addr_field_item == 'company')
			{
				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Company'),
					'name' =&gt; 'company',
					'required' =&gt; false,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('Invalid characters:').' &amp;lt;&amp;gt;;=#{}'
				);
				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('VAT number'),
					'col' =&gt; '2',
					'name' =&gt; 'vat_number'
				);
			}
			else if ($addr_field_item == 'lastname')
			{
				if (isset($customer) &amp;&amp;
					!Tools::isSubmit('submit'.strtoupper($this-&gt;table)) &amp;&amp;
					Validate::isLoadedObject($customer) &amp;&amp;
					!Validate::isLoadedObject($this-&gt;object))
					$default_value = $customer-&gt;lastname;
				else
					$default_value = '';

				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Last Name'),
					'name' =&gt; 'lastname',
					'required' =&gt; true,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('Invalid characters:').' 0-9!&amp;amp;lt;&amp;amp;gt;,;?=+()@#&quot;�{}_$%:',
					'default_value' =&gt; $default_value,
				);
			}
			else if ($addr_field_item == 'firstname')
			{
				if (isset($customer) &amp;&amp;
					!Tools::isSubmit('submit'.strtoupper($this-&gt;table)) &amp;&amp;
					Validate::isLoadedObject($customer) &amp;&amp;
					!Validate::isLoadedObject($this-&gt;object))
					$default_value = $customer-&gt;firstname;
 	 	 	 	else
 	 	 	 		$default_value = '';

				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('First Name'),
					'name' =&gt; 'firstname',
					'required' =&gt; true,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('Invalid characters:').' 0-9!&amp;amp;lt;&amp;amp;gt;,;?=+()@#&quot;�{}_$%:',
					'default_value' =&gt; $default_value,
				);
			}
			else if ($addr_field_item == 'address1')
			{
				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Address'),
					'name' =&gt; 'address1',
					'col' =&gt; '6',
					'required' =&gt; true,
				);
			}
			else if ($addr_field_item == 'address2')
			{
				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Address').' (2)',
					'name' =&gt; 'address2',
					'col' =&gt; '6',
					'required' =&gt; false,
				);
			}
			elseif ($addr_field_item == 'postcode')
			{
				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Zip/Postal Code'),
					'name' =&gt; 'postcode',
					'col' =&gt; '2',
					'required' =&gt; true,
				);
			}
			else if ($addr_field_item == 'city')
			{
				$temp_fields[] = array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('City'),
					'name' =&gt; 'city',
					'col' =&gt; '4',
					'required' =&gt; true,
				);
			}
			else if ($addr_field_item == 'country' || $addr_field_item == 'Country:name')
			{
				$temp_fields[] = array(
					'type' =&gt; 'select',
					'label' =&gt; $this-&gt;l('Country'),
					'name' =&gt; 'id_country',
					'required' =&gt; false,
					'col' =&gt; '4',
					'default_value' =&gt; (int)$this-&gt;context-&gt;country-&gt;id,
					'options' =&gt; array(
						'query' =&gt; Country::getCountries($this-&gt;context-&gt;language-&gt;id),
						'id' =&gt; 'id_country',
						'name' =&gt; 'name'
					)
				);
				$temp_fields[] = array(
					'type' =&gt; 'select',
					'label' =&gt; $this-&gt;l('State'),
					'name' =&gt; 'id_state',
					'required' =&gt; false,
					'col' =&gt; '4',
					'options' =&gt; array(
						'query' =&gt; array(),
						'id' =&gt; 'id_state',
						'name' =&gt; 'name'
					)
				);
			}
		}

		// merge address format with the rest of the form
		array_splice($this-&gt;fields_form['input'], 3, 0, $temp_fields);

		return parent::renderForm();
	}
	
}

</pre>
<p>We must edit the $this->fields_form variable to add a new input field; right after this:</p>
<pre class="brush: php; title: ; notranslate">
				array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('Identification Number'),
					'name' =&gt; 'dni',
					'required' =&gt; false,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('DNI / NIF / NIE')
				),	
</pre>
<p>Add the following</p>
<pre class="brush: php; title: ; notranslate">
				array(
					'type' =&gt; 'text',
					'label' =&gt; $this-&gt;l('My custom field'),
					'name' =&gt; 'my_custom_field',
					'required' =&gt; false,
					'col' =&gt; '4',
					'hint' =&gt; $this-&gt;l('Just a custom field!')
				),	
</pre>
<p><strong>Note:</strong> make sure the &#8220;name&#8221; matches the one of the new attribute previously added to both the database and Address class object!</p>
<p>Lastly, at the end of the method, change:</p>
<pre class="brush: php; title: ; notranslate">
return parent::renderForm();
</pre>
<p>To</p>
<pre class="brush: php; title: ; notranslate">
return AdminController::renderForm();
</pre>
<p>So that the new fields list is not replaced by the original one.</p>
<p>If the Address class or/and controller were not previously overridden, at this point you must reach	the <em>cache/</em> folder and erase <strong>class_index.php</strong>; as always. After doing it, overrides will take place.</p>
<div class="separator"></div>
<h2>The Front Office Address Template</h2>
<p>As very last step, let&#8217;s now add the custom field to the front office template, so it can be filled in by clients when they register. Open up <strong>address.tpl</strong>, located in the theme folder. I am using the default bootstrap template, so your file might look differently in case you have a custom one! Locate:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

			{if $field_name eq 'vat_number'}
				&lt;div id=&quot;vat_area&quot;&gt;
					&lt;div id=&quot;vat_number&quot;&gt;
						&lt;div class=&quot;form-group&quot;&gt;
							&lt;label for=&quot;vat-number&quot;&gt;{l s='VAT number'}&lt;/label&gt;
							&lt;input type=&quot;text&quot; class=&quot;form-control validate&quot; data-validate=&quot;{$address_validation.$field_name.validate}&quot; id=&quot;vat-number&quot; name=&quot;vat_number&quot; value=&quot;{if isset($smarty.post.vat_number)}{$smarty.post.vat_number}{else}{if isset($address-&gt;vat_number)}{$address-&gt;vat_number|escape:'html':'UTF-8'}{/if}{/if}&quot; /&gt;
						&lt;/div&gt;
					&lt;/div&gt;
				&lt;/div&gt;
			{/if}
</pre>
<p>And right after it, add:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

			{if $field_name eq 'my_custom_field'}
				&lt;div id=&quot;vat_area&quot;&gt;
					&lt;div id=&quot;my_custom_field&quot;&gt;
						&lt;div class=&quot;form-group&quot;&gt;
							&lt;label for=&quot;my-custom-field&quot;&gt;{l s='My Custom Field'}&lt;/label&gt;
							&lt;input type=&quot;text&quot; class=&quot;form-control validate&quot; data-validate=&quot;{$address_validation.$field_name.validate}&quot; id=&quot;my-custom-field&quot; name=&quot;my_custom_field&quot; value=&quot;{if isset($smarty.post.my_custom_field)}{$smarty.post.my_custom_field}{else}{if isset($address-&gt;my_custom_field)}{$address-&gt;my_custom_field|escape:'html':'UTF-8'}{/if}{/if}&quot; /&gt;
						&lt;/div&gt;
					&lt;/div&gt;
				&lt;/div&gt;
			{/if}
</pre>
<p>Save and refresh, we&#8217;re done!</p>
<p><strong>TIP:</strong> if you don&#8217;t see any change in the front office, make sure you turn on recompilation from <em>Advanced Parameters > Performance</em>, and clear Smarty cache as well</p>
<div class="separator"></div>
<h2>Optional: Making the new field mandatory</h2>
<p>If you really need your customers to input something in that new field, than another override is necessary. Create a new file within <em>override/controllers/front</em> and call it <strong>AddressController.php</strong>. Paste the following inside php tags, ad always:</p>
<pre class="brush: php; title: ; notranslate">

Class AddressController extends AddressControllerCore
{

}
</pre>
<p>We need to override the <strong>processSubmitAddress()</strong> method. Therefore, if your Prestashop version is not 1.6.0.5, go ahead and copy your original one inside this new override; otherwise you can use the following:</p>
<pre class="brush: php; title: ; notranslate">

	protected function processSubmitAddress()
	{
		$address = new Address();
		$this-&gt;errors = $address-&gt;validateController();
		$address-&gt;id_customer = (int)$this-&gt;context-&gt;customer-&gt;id;

		// Check page token
		if ($this-&gt;context-&gt;customer-&gt;isLogged() &amp;&amp; !$this-&gt;isTokenValid())
			$this-&gt;errors[] = Tools::displayError('Invalid token.');

		// Check phone
		if (Configuration::get('PS_ONE_PHONE_AT_LEAST') &amp;&amp; !Tools::getValue('phone') &amp;&amp; !Tools::getValue('phone_mobile'))
			$this-&gt;errors[] = Tools::displayError('You must register at least one phone number.');
		if ($address-&gt;id_country)
		{
			// Check country
			if (!($country = new Country($address-&gt;id_country)) || !Validate::isLoadedObject($country))
				throw new PrestaShopException('Country cannot be loaded with address-&gt;id_country');

			if ((int)$country-&gt;contains_states &amp;&amp; !(int)$address-&gt;id_state)
				$this-&gt;errors[] = Tools::displayError('This country requires you to chose a State.');

			$postcode = Tools::getValue('postcode');		
			/* Check zip code format */
			if ($country-&gt;zip_code_format &amp;&amp; !$country-&gt;checkZipCode($postcode))
				$this-&gt;errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country-&gt;iso_code, str_replace('N', '0', str_replace('L', 'A', $country-&gt;zip_code_format))));
			elseif(empty($postcode) &amp;&amp; $country-&gt;need_zip_code)
				$this-&gt;errors[] = Tools::displayError('A Zip/Postal code is required.');
			elseif ($postcode &amp;&amp; !Validate::isPostCode($postcode))
				$this-&gt;errors[] = Tools::displayError('The Zip/Postal code is invalid.');

			// Check country DNI
			if ($country-&gt;isNeedDni() &amp;&amp; (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
				$this-&gt;errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
			else if (!$country-&gt;isNeedDni())
				$address-&gt;dni = null;
		}
		// Check if the alias exists
		if (!$this-&gt;context-&gt;customer-&gt;is_guest &amp;&amp; !empty($_POST['alias']) &amp;&amp; (int)$this-&gt;context-&gt;customer-&gt;id &gt; 0)
		{
			$id_address = Tools::getValue('id_address');
			if(Configuration::get('PS_ORDER_PROCESS_TYPE') &amp;&amp; (int)Tools::getValue('opc_id_address_'.Tools::getValue('type')) &gt; 0)
				$id_address = Tools::getValue('opc_id_address_'.Tools::getValue('type'));
 	
			if (Db::getInstance()-&gt;getValue('
				SELECT count(*)
				FROM '._DB_PREFIX_.'address
				WHERE `alias` = \''.pSql($_POST['alias']).'\'
				AND id_address != '.(int)$id_address.'
				AND id_customer = '.(int)$this-&gt;context-&gt;customer-&gt;id.'
				AND deleted = 0') &gt; 0)
				$this-&gt;errors[] = sprintf(Tools::displayError('The alias &quot;%s&quot; has already been used. Please select another one.'), Tools::safeOutput($_POST['alias']));
		}

		// Check the requires fields which are settings in the BO
		$this-&gt;errors = array_merge($this-&gt;errors, $address-&gt;validateFieldsRequiredDatabase());

		// Don't continue this process if we have errors !
		if ($this-&gt;errors &amp;&amp; !$this-&gt;ajax)
			return;

		// If we edit this address, delete old address and create a new one
		if (Validate::isLoadedObject($this-&gt;_address))
		{
			if (Validate::isLoadedObject($country) &amp;&amp; !$country-&gt;contains_states)
				$address-&gt;id_state = 0;
			$address_old = $this-&gt;_address;
			if (Customer::customerHasAddress($this-&gt;context-&gt;customer-&gt;id, (int)$address_old-&gt;id))
			{
				if ($address_old-&gt;isUsed())
					$address_old-&gt;delete();
				else
				{
					$address-&gt;id = (int)($address_old-&gt;id);
					$address-&gt;date_add = $address_old-&gt;date_add;
				}
			}
		}
		
		if ($this-&gt;ajax &amp;&amp; Tools::getValue('type') == 'invoice' &amp;&amp; Configuration::get('PS_ORDER_PROCESS_TYPE'))
		{
			$this-&gt;errors = array_unique(array_merge($this-&gt;errors, $address-&gt;validateController()));			
			if (count($this-&gt;errors))
			{
				$return = array(
					'hasError' =&gt; (bool)$this-&gt;errors,
					'errors' =&gt; $this-&gt;errors
				);
				die(Tools::jsonEncode($return));
			}
		}
		
		// Save address
		if ($result = $address-&gt;save())
		{			
			// Update id address of the current cart if necessary
			if (isset($address_old) &amp;&amp; $address_old-&gt;isUsed())
				$this-&gt;context-&gt;cart-&gt;updateAddressId($address_old-&gt;id, $address-&gt;id);
			else // Update cart address
				$this-&gt;context-&gt;cart-&gt;autosetProductAddress();

			if ((bool)(Tools::getValue('select_address', false)) == true OR (Tools::getValue('type') == 'invoice' &amp;&amp; Configuration::get('PS_ORDER_PROCESS_TYPE')))
				$this-&gt;context-&gt;cart-&gt;id_address_invoice = (int)$address-&gt;id;
			elseif (Configuration::get('PS_ORDER_PROCESS_TYPE'))
				$this-&gt;context-&gt;cart-&gt;id_address_invoice = (int)$this-&gt;context-&gt;cart-&gt;id_address_delivery;
			$this-&gt;context-&gt;cart-&gt;update();

			if ($this-&gt;ajax)
			{
				$return = array(
					'hasError' =&gt; (bool)$this-&gt;errors,
					'errors' =&gt; $this-&gt;errors,
					'id_address_delivery' =&gt; (int)$this-&gt;context-&gt;cart-&gt;id_address_delivery,
					'id_address_invoice' =&gt; (int)$this-&gt;context-&gt;cart-&gt;id_address_invoice
				);
				die(Tools::jsonEncode($return));
			}

			// Redirect to old page or current page
			if ($back = Tools::getValue('back'))
			{
				if ($back == Tools::secureReferrer(Tools::getValue('back')))
					Tools::redirect(html_entity_decode($back));
				$mod = Tools::getValue('mod');
				Tools::redirect('index.php?controller='.$back.($mod ? '&amp;back='.$mod : ''));
			}
			else
				Tools::redirect('index.php?controller=addresses');
		}		
		$this-&gt;errors[] = Tools::displayError('An error occurred while updating your address.');
	}
</pre>
<p>Right before the // CHeck Phone comment, add:</p>
<pre class="brush: php; title: ; notranslate">
		if ( !Tools::getValue('my_custom_field'))
			$this-&gt;errors[] = Tools::displayError('The custom field is mandatory!');
</pre>
<p>So that an error will be thrown if your clients leave that field empty!</p>
<p>Remember to erase the class index file again, of course.</p>
<div class="separator"></div>
<h2>Adding the new field to the address format in Prestashop</h2>
<p>As a side note, be aware that in order to display the new field we added we need to change the address format for each country. I am not currently aware of a simple way to apply address changes to all countries at once. Therefore, head over to <strong>Localization > Countries</strong>, click on a country name and add the new field to the address box:</p>
<p><a href="http://nemops.com/wp-content/uploads/2014/04/new_registration_fields_bo.jpg"><img src="http://nemops.com/wp-content/uploads/2014/04/new_registration_fields_bo-680x216.jpg" alt="Adding the new field to the address format in Prestashop" width="680" height="216" class="aligncenter size-large wp-image-1954" /></a></p>
<div class="separator"></div>
<h2>What for new Customer Fields?</h2>
<p>Throughout this tutorial, we added a new field to the Address object. However, it is also possible to create a new basic customer field, to sit along name, lastname and email in the very basic registration (even without an address). To do so, you can simply apply the same process to the <strong>Customer</strong> class, and relative controllers. Just be aware that you will need to edit a couple of different template files: <strong>identity.tpl</strong> and <strong>authentication.tpl</strong>, as well as <strong>order-opc-new-account.tpl</strong> if you use the one page checkout!</p>
<div class="separator"></div>
<p><strong>UPDATE! If you prefer a simple solution, I created a module that automates the process and does much more, find it <a href="http://store.nemops.com/modules/45-prestashop-address-fields.html#.WhvflkqWaUk" title="PrestaShop Address Fields Module">here</a></strong></p>
<h3>Additional Resources</h3>
<ul>
<li>
		<a href="http://nemops.com/extending-prestashop-objects/#.U1WG4Pna6r0" title="How to extend Prestashop objects" target="_blank">How to extend Prestashop objects</a>
	</li>
</ul>
<p>The post <a rel="nofollow" href="https://nemops.com/new-customer-address-fields-prestashop/">How to add new fields to the customer address in Prestashop</a> appeared first on <a rel="nofollow" href="https://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://nemops.com/new-customer-address-fields-prestashop/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
	</channel>
</rss>
