shaft Posted February 17, 2015 Share Posted February 17, 2015 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 More sharing options...
Dh42 Posted February 17, 2015 Share Posted February 17, 2015 It would not really be a simple change, it is something that would take a lot of time basically and might include changing payment modules to, depending on what modules you are using. Link to comment Share on other sites More sharing options...
shaft Posted February 17, 2015 Author Share Posted February 17, 2015 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 More sharing options...
Strky Posted March 2, 2015 Share Posted March 2, 2015 I have the same problem. It takes something like if (Tools::getValue('company')!= '') but what next? Any ideas? Link to comment Share on other sites More sharing options...
Strky Posted March 5, 2015 Share Posted March 5, 2015 (edited) 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 March 5, 2015 by Strky (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts