girl_dev Posted September 6, 2016 Share Posted September 6, 2016 I am using prestashop 1.6.1.2 with mutistore option. I have a shop for professional customers . I would like to set the company field and "VAT NUMBER" field ,which I added manually to B2B form ,to required, but it is required for all the shops . Link to comment Share on other sites More sharing options...
girl_dev Posted September 7, 2016 Author Share Posted September 7, 2016 any help please? Link to comment Share on other sites More sharing options...
rocky Posted September 8, 2016 Share Posted September 8, 2016 Unfortunately, the required fields are not multishop, so you can't have fields required for one shop, but not another. You'd have to hack a solution by finding the code that checks required fields and add some if statements that check the current shop ID. 1 Link to comment Share on other sites More sharing options...
girl_dev Posted September 8, 2016 Author Share Posted September 8, 2016 finally I find the solution :in controllers/AuthController.phpin the function public function postProcessI added: $id_shop = $this->context->shop->id;then in this bloc :if (Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) {I added:if($id_shop==3){ if (Tools::getValue('company') == '') { $this->errors[] = Tools::displayError('company is required.'); } if (Tools::getValue('vatnumber') == '') { $this->errors[] = Tools::displayError('vatnumber is required.'); } } I hope it helps someone else 1 Link to comment Share on other sites More sharing options...
mktm20111 Posted July 4 Share Posted July 4 On 9/8/2016 at 10:33 AM, girl_dev said: finally I find the solution : in controllers/AuthController.php in the function public function postProcess I added: $id_shop = $this->context->shop->id; then in this bloc :if (Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) { I added: if($id_shop==3){ if (Tools::getValue('company') == '') { $this->errors[] = Tools::displayError('company is required.'); } if (Tools::getValue('vatnumber') == '') { $this->errors[] = Tools::displayError('vatnumber is required.'); } } I hope it helps someone else 2025 and still the same with 8.2 that's crazy. What did you exactly do? (if you remember) 😁 because i am not pro dev and really need this to be removed on my non B2B shops. Link to comment Share on other sites More sharing options...
mktm20111 Posted July 4 Share Posted July 4 (edited) ok so i find the solution for prestashop 8.2 for anyone who needs it. first of all make sure both company and VAT number are unchecked in back office (this code will do it just for a specific store) In controllers/front/RegistrationController.phpchange this public function initContent() { $register_form = $this ->makeCustomerForm() ->setGuestAllowed(false) ->fillWith(Tools::getAllValues()); // If registration form was submitted if (Tools::isSubmit('submitCreate')) { $hookResult = array_reduce( Hook::exec('actionSubmitAccountBefore', [], null, true), function ($carry, $item) { return $carry && $item; }, true ); // If no problem occured in the hook, let's get the user redirected if ($hookResult && $register_form->submit() && !$this->ajax) { // First option - redirect the customer to desired URL specified in 'back' parameter // Before that, we need to check if 'back' is legit URL that is on OUR domain, with the right protocol $back = rawurldecode(Tools::getValue('back')); if (Tools::urlBelongsToShop($back)) { return $this->redirectWithNotifications($back); } // Second option - we will redirect him to authRedirection if set if ($this->authRedirection) { return $this->redirectWithNotifications($this->authRedirection); } // Third option - we will redirect him to home URL return $this->redirectWithNotifications(__PS_BASE_URI__); } } $this->context->smarty->assign([ 'register_form' => $register_form->getProxy(), 'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop'), ]); $this->setTemplate('customer/registration'); parent::initContent(); } by this but make sure you add the id of your store correctly public function initContent() { $register_form = $this ->makeCustomerForm() ->setGuestAllowed(false) ->fillWith(Tools::getAllValues()); $id_shop = $this->context->shop->id; // If registration form was submitted if (Tools::isSubmit('submitCreate')) { // ✅ Custom validation for shop ID 3 if ($id_shop == 3) { $company = Tools::getValue('company'); $vat = Tools::getValue('vat_number'); // PrestaShop uses "vat_number" internally if (empty($company)) { $register_form->getField('company')->addError( $this->trans('Company is required.', [], 'Shop.Notifications.Error') ); } if (empty($vat)) { $register_form->getField('vat_number')->addError( $this->trans('VAT number is required.', [], 'Shop.Notifications.Error') ); } } // Keep the hook and original logic $hookResult = array_reduce( Hook::exec('actionSubmitAccountBefore', [], null, true), function ($carry, $item) { return $carry && $item; }, true ); if ($hookResult && $register_form->submit() && !$this->ajax) { $back = rawurldecode(Tools::getValue('back')); if (Tools::urlBelongsToShop($back)) { return $this->redirectWithNotifications($back); } if ($this->authRedirection) { return $this->redirectWithNotifications($this->authRedirection); } return $this->redirectWithNotifications(__PS_BASE_URI__); } } $this->context->smarty->assign([ 'register_form' => $register_form->getProxy(), 'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop'), ]); $this->setTemplate('customer/registration'); parent::initContent(); } 😁😁😁😁 Edited July 4 by mktm20111 (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now