Gfinfo web Posted January 31, 2023 Share Posted January 31, 2023 So I am trying to add a number field to adress form. This is becaus Brazilian norm of adress writing begin with street name, then the house number. Ex: Rua Dom Pedro, 133 Due to it, people usally forget to add, number unless it has a separeted number field. Very comon on brazilian ecommerce. Follows a print of what i am trying. If anyone has an idea please share. Thank you for your time. Link to comment Share on other sites More sharing options...
ps8modules Posted February 1, 2023 Share Posted February 1, 2023 Hi, no additional field is needed, but it is enough to check if there is a number in the text. Please write your version of Prestashop and I will give you instructions. Link to comment Share on other sites More sharing options...
ps8modules Posted February 1, 2023 Share Posted February 1, 2023 Prestashop 1.7.0.0 > 1. edit ./classes/CustomerAddressForm.php => validate() function before: public function validate() { $is_valid = true; $postcode = $this->getField('postcode'); if ($postcode && $postcode->isRequired()) { $country = $this->formatter->getCountry(); if (!$country->checkZipCode($postcode->getValue())) { $postcode->addError($this->translator->trans( 'Invalid postcode - should look like "%zipcode%"', ['%zipcode%' => $country->zip_code_format], 'Shop.Forms.Errors' )); $is_valid = false; } } if (($hookReturn = Hook::exec('actionValidateCustomerAddressForm', ['form' => $this])) !== '') { $is_valid &= (bool) $hookReturn; } return $is_valid && parent::validate(); } after: * change $controlledCountries, to the list of id countries where you want to check if there is a number in the address public function validate() { $is_valid = true; $postcode = $this->getField('postcode'); if ($postcode && $postcode->isRequired()) { $country = $this->formatter->getCountry(); if (!$country->checkZipCode($postcode->getValue())) { $postcode->addError($this->translator->trans( 'Invalid postcode - should look like "%zipcode%"', ['%zipcode%' => $country->zip_code_format], 'Shop.Forms.Errors' )); $is_valid = false; } } $controlledCountries = array(58, 59, 60, 61, 16, 21); // (Brazil, Brunei, Burkina Faso, Myanmar, Czechia, United States) $getSelectedCountry = $this->getField('id_country')->getValue(); $address1 = $this->getField('address1'); if ($address1) { $int_var = (int)filter_var($address1->getValue(), FILTER_SANITIZE_NUMBER_INT); if (!$int_var && (in_array($getSelectedCountry, $controlledCountries))) { $address1->addError($this->translator->trans( 'Invalid address - missing house number', [], 'Shop.Forms.Errors' )); $is_valid = false; } } if (($hookReturn = Hook::exec('actionValidateCustomerAddressForm', ['form' => $this])) !== '') { $is_valid &= (bool) $hookReturn; } return $is_valid && parent::validate(); } Result: Link to comment Share on other sites More sharing options...
Gfinfo web Posted February 1, 2023 Author Share Posted February 1, 2023 Hello Ps8, thank you for your response. My prestashop version is: 1.7.8.8 Link to comment Share on other sites More sharing options...
ps8modules Posted February 1, 2023 Share Posted February 1, 2023 Hi. Thanks for adding the version. The above modification is valid for your Prestashop version. 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