Charles 01 Posted October 25, 2023 Share Posted October 25, 2023 (edited) Good morning, work on a prestashop, I got a module which allows you to limit certain postal codes (I would like to exclude certain areas like Corsica or overseas territories for delivery in France) The module works really well and limits Dom Tom postal codes (all postal codes between 96000 and 98000). I would like to edit the module so that it also limits the postal codes of Corsica (postal codes between 20000 and 25000). Here is the code present in the module PHP file, could you tell me how to edit this file so that they also limit postal codes between 20000 and 25000 please? /** * Check Post code for France and DOM-TOM * * @param array $params * @return bool|void */ public function hookActionValidateCustomerAddressForm($params) { if ( Configuration::get(strtoupper($this->name) . '_ENABLE_POSTCODE_RESTRICTION') && Configuration::get(strtoupper($this->name) . '_COUNTRY_ID_FR') ) { $is_valid = true; $form = $params['form']; $country = $form->getField("id_country"); $id_country = $country->getValue(); if ($id_country == (int) Configuration::get(strtoupper($this->name) . '_COUNTRY_ID_FR')) { $zip = $form->getField("postcode"); $zipcode = (int)$zip->getValue(); if ($zipcode > self::DOM_TOM_POSTCODE_RANGE_START && $zipcode != 98000) { $zip->addError($this->l('Invalid country according to zip code - should be a DOM TOM one')); $is_valid = false; } } return $is_valid; } } Sincerely. Edited October 25, 2023 by endriu107 (see edit history) Link to comment Share on other sites More sharing options...
Knowband Plugins Posted October 26, 2023 Share Posted October 26, 2023 On 10/25/2023 at 2:55 PM, Charles 01 said: Good morning, work on a prestashop, I got a module which allows you to limit certain postal codes (I would like to exclude certain areas like Corsica or overseas territories for delivery in France) The module works really well and limits Dom Tom postal codes (all postal codes between 96000 and 98000). I would like to edit the module so that it also limits the postal codes of Corsica (postal codes between 20000 and 25000). Here is the code present in the module PHP file, could you tell me how to edit this file so that they also limit postal codes between 20000 and 25000 please? Hello, To limit the postal codes for Corsica (between 20000 and 25000) along with the existing restriction for DOM-TOM postal codes (between 96000 and 98000), you can modify the hookActionValidateCustomerAddressForm function as follows: Define constants for the Corsica postal code range at the top of your class. Modify the condition in the if statement to check if the postal code lies in the Corsica range. Here's the modified code: // ... const CORSICA_POSTCODE_RANGE_START = 20000; const CORSICA_POSTCODE_RANGE_END = 25000; // ... public function hookActionValidateCustomerAddressForm($params) { if ( Configuration::get(strtoupper($this->name) . '_ENABLE_POSTCODE_RESTRICTION') && Configuration::get(strtoupper($this->name) . '_COUNTRY_ID_FR') ) { $is_valid = true; $form = $params['form']; $country = $form->getField("id_country"); $id_country = $country->getValue(); if ($id_country == (int) Configuration::get(strtoupper($this->name) . '_COUNTRY_ID_FR')) { $zip = $form->getField("postcode"); $zipcode = (int)$zip->getValue(); if ( ($zipcode >= self::DOM_TOM_POSTCODE_RANGE_START && $zipcode <= self::DOM_TOM_POSTCODE_RANGE_END && $zipcode != 98000) || ($zipcode >= self::CORSICA_POSTCODE_RANGE_START && $zipcode <= self::CORSICA_POSTCODE_RANGE_END) ) { $zip->addError($this->l('Invalid postal code for delivery.')); $is_valid = false; } } return $is_valid; } } This will ensure that any postal codes from both the Corsica and DOM-TOM ranges are limited as per your requirements. We hope these suggestions help simplify the process for you. Let us know if you have any more questions or need further assistance. We're here to help! Link to comment Share on other sites More sharing options...
Charles 01 Posted October 30, 2023 Author Share Posted October 30, 2023 Good morning, Thank you for the solution, however, I'm not sorry but where should I integrate this piece of code into which file? Sincerely, Link to comment Share on other sites More sharing options...
Knowband Plugins Posted October 31, 2023 Share Posted October 31, 2023 On 10/30/2023 at 3:49 PM, Charles 01 said: Good morning, Thank you for the solution, however, I'm not sorry but where should I integrate this piece of code into which file? Sincerely Good morning, I apologize for any confusion. To integrate the provided code, you should follow these steps: 1. Open your PrestaShop module's main PHP file. This file typically has the same name as your module and is located in the root folder of your module. 2. Locate the `hookActionValidateCustomerAddressForm` function within this file. This function handles the validation of customer addresses. 3. Insert the code provided at the top of the module's main PHP file to define the constants for the Corsica postal code range. Place it just above the `hookActionValidateCustomerAddressForm` function. 4. Modify the `hookActionValidateCustomerAddressForm` function as shown in the provided code, adjusting the conditions as needed. 5. Save the changes and upload the updated module to your PrestaShop installation. This should ensure that the code is correctly integrated into your module, and it will restrict postal codes according to your specified requirements for Corsica and DOM-TOM. If you encounter any issues or have further questions, please don't hesitate to reach out. We're here to assist you. Link to comment Share on other sites More sharing options...
Charles 01 Posted November 2, 2023 Author Share Posted November 2, 2023 (edited) Good morning, Would you be so kind as to rewrite this code with the function please? Because even if I insert the code in the PHP file, it doesn't work. Thanks. Edited November 2, 2023 by endriu107 removed code (see edit history) Link to comment Share on other sites More sharing options...
endriu107 Posted November 2, 2023 Share Posted November 2, 2023 @Charles 01 please do not post all code, only required parts and also please add it by using "code" option. 1 Link to comment Share on other sites More sharing options...
Charles 01 Posted November 2, 2023 Author Share Posted November 2, 2023 Thank you, your answer helps me a lot! otherwise instead of moderating could you help me? THANKS Link to comment Share on other sites More sharing options...
endriu107 Posted November 2, 2023 Share Posted November 2, 2023 I could help you but I waste my time to moderate forum instead helping people. I think you understand... 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