Jump to content

How to set firstname and lastname not required if company is set


Recommended Posts

Hello,
 
I would need advice on how to set not required fields for first name and last name, if the customer fills the company field.
--------------------------------
For example 1:
 
The customer fills in the order:
Company: XYZ
First name: "empty"  // not required
Last name: "empty" // not required
Adress line: XYZ
ZIP CODE: XYZ
City: XYZ
State : XYZ
etc....
 
For example 2:
 
Company: XYZ
First name: XYZ // they can fill, but not required
Last name: XYZ // they can fill, but not required
Adress line: XYZ
ZIP CODE: XYZ
City: XYZ
State : XYZ
etc....

 

For example 3:
 
Company: "empty"
First name: XYZ //now it is required
Last name: XYZ //now it is required
Adress line: XYZ
ZIP CODE: XYZ
City: XYZ
State : XYZ
etc....
 
-----------
Anybody know, how to do that?
 
Prestashop version 1.6.0.7.
 
I think this will help more people.
 
Thank you, for your answer.
 
Best regards,
Shaft  :)

 

Link to comment
Share on other sites

I was trying do something in "controllers/front/AddressController.php" and "controllers/front/AuthController.php" like:

 

If company is set, no need to validate a first name and last name, else first name and last name is required. But withnout success... :/

Link to comment
Share on other sites

  • 2 weeks later...

Maybe I solved this...

First, make "firstname" and "lastname" not required.

 

In Customer.php and Address.php:

delete

'required' => true,

from

'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),

Then, in /controllers/front/AddressController.php add in function processSubmitAddress()

below

protected function processSubmitAddress()
	{
		$address = new Address();
		$this->errors = $address->validateController();
		$address->id_customer = (int)$this->context->customer->id;

		// Check page token
		if ($this->context->customer->isLogged() && !$this->isTokenValid())
			$this->errors[] = Tools::displayError('Invalid token.');

add this

if (Tools::getValue('company') == '') {
	       $nameone = Tools::getValue('firstname');
				if(empty($nameone))
					$this->errors[] = Tools::displayError('firstname is required');
	       $nametwo = Tools::getValue('lastname');
				if(empty($nametwo))
					$this->errors[] = Tools::displayError('lastname is required'); }

And the same code add in AuthController.php

below

protected function processSubmitAccount()
	{
		Hook::exec('actionBeforeSubmitAccount');
		$this->create_account = true;
		if (Tools::isSubmit('submitAccount'))
			$this->context->smarty->assign('email_create', 1);
		// New Guest customer
Edited by Strky (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...