From 5a79db30152a125529c222d0a49f50a221ae5c09 Mon Sep 17 00:00:00 2001 From: TheCoreDev Date: Wed, 4 Sep 2024 21:46:00 +0200 Subject: [PATCH] =?UTF-8?q?[04/09/2024]=20Installation=20du=20module=20For?= =?UTF-8?q?cePhone=20pour=20rendre=20le=20t=C3=A9l=C3=A9phone=20obligatoir?= =?UTF-8?q?e=20=C3=A0=20la=20cr=C3=A9ation=20du=20compte.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local/modules/ForcePhone/CHANGELOG.md | 9 + .../Command/UpdatePhoneNumberCommand.php | 70 +++++ local/modules/ForcePhone/Config/config.xml | 28 ++ local/modules/ForcePhone/Config/module.xml | 32 +++ local/modules/ForcePhone/Config/routing.xml | 18 ++ .../Constraints/AtLeastOnePhone.php | 19 ++ .../Constraints/AtLeastOnePhoneValidator.php | 41 +++ .../Constraints/CheckPhoneFormat.php | 19 ++ .../Constraints/CheckPhoneFormatValidator.php | 71 +++++ .../ForcePhone/Controller/ApiController.php | 83 ++++++ .../Controller/ConfigureController.php | 87 ++++++ .../ForcePhoneEventListener.php | 271 ++++++++++++++++++ local/modules/ForcePhone/ForcePhone.php | 36 +++ local/modules/ForcePhone/Form/ConfigForm.php | 78 +++++ local/modules/ForcePhone/Hook/HookManager.php | 49 ++++ .../I18n/backOffice/default/en_US.php | 6 + .../I18n/backOffice/default/fr_FR.php | 6 + local/modules/ForcePhone/I18n/en_US.php | 14 + local/modules/ForcePhone/I18n/fr_FR.php | 14 + local/modules/ForcePhone/Readme.md | 40 +++ local/modules/ForcePhone/composer.json | 12 + .../force-phone/module-configuration.html | 60 ++++ 22 files changed, 1063 insertions(+) create mode 100644 local/modules/ForcePhone/CHANGELOG.md create mode 100644 local/modules/ForcePhone/Command/UpdatePhoneNumberCommand.php create mode 100644 local/modules/ForcePhone/Config/config.xml create mode 100644 local/modules/ForcePhone/Config/module.xml create mode 100644 local/modules/ForcePhone/Config/routing.xml create mode 100644 local/modules/ForcePhone/Constraints/AtLeastOnePhone.php create mode 100644 local/modules/ForcePhone/Constraints/AtLeastOnePhoneValidator.php create mode 100644 local/modules/ForcePhone/Constraints/CheckPhoneFormat.php create mode 100644 local/modules/ForcePhone/Constraints/CheckPhoneFormatValidator.php create mode 100644 local/modules/ForcePhone/Controller/ApiController.php create mode 100644 local/modules/ForcePhone/Controller/ConfigureController.php create mode 100644 local/modules/ForcePhone/EventListeners/ForcePhoneEventListener.php create mode 100644 local/modules/ForcePhone/ForcePhone.php create mode 100644 local/modules/ForcePhone/Form/ConfigForm.php create mode 100644 local/modules/ForcePhone/Hook/HookManager.php create mode 100644 local/modules/ForcePhone/I18n/backOffice/default/en_US.php create mode 100644 local/modules/ForcePhone/I18n/backOffice/default/fr_FR.php create mode 100644 local/modules/ForcePhone/I18n/en_US.php create mode 100644 local/modules/ForcePhone/I18n/fr_FR.php create mode 100644 local/modules/ForcePhone/Readme.md create mode 100644 local/modules/ForcePhone/composer.json create mode 100644 local/modules/ForcePhone/templates/backOffice/default/force-phone/module-configuration.html diff --git a/local/modules/ForcePhone/CHANGELOG.md b/local/modules/ForcePhone/CHANGELOG.md new file mode 100644 index 00000000..4df7bc9b --- /dev/null +++ b/local/modules/ForcePhone/CHANGELOG.md @@ -0,0 +1,9 @@ +# 1.2.1 +- check if phones are not empty before formatting +- save cell phones on international format too +- remove forget log warning + +# 1.2 +- fix missing form '.thelia_customer_update' +- add check phones format (enable/disable it in config) +- save phones on international format \ No newline at end of file diff --git a/local/modules/ForcePhone/Command/UpdatePhoneNumberCommand.php b/local/modules/ForcePhone/Command/UpdatePhoneNumberCommand.php new file mode 100644 index 00000000..b34ce009 --- /dev/null +++ b/local/modules/ForcePhone/Command/UpdatePhoneNumberCommand.php @@ -0,0 +1,70 @@ +setName("module:ForcePhone:update") + ->setDescription("Update phone number of all addresses"); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->initRequest(); + $addresses = AddressQuery::create()->find(); + + foreach ($addresses as $address){ + if ($phone = $address->getPhone()){ + $phone = $this->updatePhone($phone, $address->getCountry()->getIsoalpha2(), $address->getCustomer(), $output); + if ($phone !== null){ + $address + ->setPhone($phone) + ->save(); + } + } + if ($cellphone = $address->getCellphone()){ + $cellphone = $this->updatePhone($cellphone, $address->getCountry()->getIsoalpha2(), $address->getCustomer(), $output); + if ($cellphone !== null) { + $address + ->setCellphone($cellphone) + ->save(); + } + } + } + + $output->writeln('Success'); + } + + protected function updatePhone($phoneNumber, $isoalpha2, Customer $customer, OutputInterface $output) + { + $phoneUtil = PhoneNumberUtil::getInstance(); + + try { + $phoneNumberProto = $phoneUtil->parse($phoneNumber, $isoalpha2); + }catch (\Exception $e){ + Tlog::getInstance()->error('Phone number '.$phoneNumber.' for customer '.$customer->getRef().' is invalid'); + $output->writeln('Error : Phone number '.$phoneNumber.' for customer '.$customer->getRef().' is invalid'); + return null; + } + + if ($phoneUtil->isValidNumber($phoneNumberProto)) { + return $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + } + return $phoneNumber; + } +} diff --git a/local/modules/ForcePhone/Config/config.xml b/local/modules/ForcePhone/Config/config.xml new file mode 100644 index 00000000..9afe266b --- /dev/null +++ b/local/modules/ForcePhone/Config/config.xml @@ -0,0 +1,28 @@ + + + + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/local/modules/ForcePhone/Config/module.xml b/local/modules/ForcePhone/Config/module.xml new file mode 100644 index 00000000..4707546e --- /dev/null +++ b/local/modules/ForcePhone/Config/module.xml @@ -0,0 +1,32 @@ + + + ForcePhone\ForcePhone + + Require the customer to enter its home phone number, mobile phone number or both + + + Oblige le client à laisser un numéro de téléphone fixe, mobile ou les deux + + + en_US + fr_FR + + 1.2.5 + + + Etienne Perriere + eperriere@openstudio.fr + + + Franck Allimant + CQFDev + franck@cqfdev.fr + www.cqfdev.fr + + + classic + 2.1.0 + beta + diff --git a/local/modules/ForcePhone/Config/routing.xml b/local/modules/ForcePhone/Config/routing.xml new file mode 100644 index 00000000..cf65fd9b --- /dev/null +++ b/local/modules/ForcePhone/Config/routing.xml @@ -0,0 +1,18 @@ + + + + + + ForcePhone\Controller\ConfigureController::configure + + + + ForcePhone\Controller\ApiController::checkPhoneOrder + + + + ForcePhone\Controller\ApiController::reformatPhoneNumber + + diff --git a/local/modules/ForcePhone/Constraints/AtLeastOnePhone.php b/local/modules/ForcePhone/Constraints/AtLeastOnePhone.php new file mode 100644 index 00000000..455f6241 --- /dev/null +++ b/local/modules/ForcePhone/Constraints/AtLeastOnePhone.php @@ -0,0 +1,19 @@ +context->getRoot()->getData(); + + if (empty($data["phone"]) && empty($data["cellphone"])) { + $this->context->addViolationAt( + "phone", + Translator::getInstance()->trans("Please enter at least one phone number.", [], ForcePhone::DOMAIN_NAME) + ); + } + } +} diff --git a/local/modules/ForcePhone/Constraints/CheckPhoneFormat.php b/local/modules/ForcePhone/Constraints/CheckPhoneFormat.php new file mode 100644 index 00000000..4af1d954 --- /dev/null +++ b/local/modules/ForcePhone/Constraints/CheckPhoneFormat.php @@ -0,0 +1,19 @@ +context->getRoot()->getData(); + + if (!empty($value)) { + try { + if (!isset($data['country']) || empty($data['country'])) { + throw new \Exception('No country ID for checking phone format'); + } + + $country = CountryQuery::create()->findOneById($data['country']); + + if (!$country) { + throw new \Exception('Country not found for checking phone format'); + } + + $phoneUtil = PhoneNumberUtil::getInstance(); + + $phoneNumberProto = $phoneUtil->parse($value, $country->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + } catch (\Exception $exception) { + $isValid = false; + + Tlog::getInstance()->warning($exception->getMessage()); + } + + if (!$isValid) { + $this->context->addViolation( + Translator::getInstance()->trans( + 'Please enter a valid phone number', + [], + ForcePhone::DOMAIN_NAME + ) + ); + } + } + } +} diff --git a/local/modules/ForcePhone/Controller/ApiController.php b/local/modules/ForcePhone/Controller/ApiController.php new file mode 100644 index 00000000..86ec6ca1 --- /dev/null +++ b/local/modules/ForcePhone/Controller/ApiController.php @@ -0,0 +1,83 @@ +filterById($orderId)->findOne(); + + if (null === $order) { + return new JsonResponse('Order not found', 400); + } + + $phoneUtil = PhoneNumberUtil::getInstance(); + + $address = $order->getOrderAddressRelatedByDeliveryOrderAddressId(); + + if (!empty($address->getPhone())) { + + $phoneNumberProto = $phoneUtil->parse($address->getPhone(), $address->getCountry()->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if (!$isValid) { + return new JsonResponse('Wrong phone number', 400); + } + } + + if (!empty($address->getCellphone())) { + + $phoneNumberProto = $phoneUtil->parse($address->getCellphone(), $address->getCountry()->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if (!$isValid) { + return new JsonResponse('Wrong cellphone number', 400); + } + } + + if ( + ForcePhone::getConfigValue('force_one', false) && + empty($address->getCellphone()) && empty($address->getPhone()) + ) { + return new JsonResponse('No phone number found', 400); + } + + return new JsonResponse('Success', 200); + } + + public function reformatPhoneNumber($phone, $countryId) + { + $phoneUtil = PhoneNumberUtil::getInstance(); + $country = CountryQuery::create()->filterById($countryId)->findOne(); + + if (!$country){ + return new JsonResponse('Invalid country id', 400); + } + + $phoneNumberProto = $phoneUtil->parse($phone, $country->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if (!$isValid) { + return new JsonResponse('Invalid phone number', 400); + } + $phone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + + return new JsonResponse($phone, 200); + } + +} \ No newline at end of file diff --git a/local/modules/ForcePhone/Controller/ConfigureController.php b/local/modules/ForcePhone/Controller/ConfigureController.php new file mode 100644 index 00000000..d532406b --- /dev/null +++ b/local/modules/ForcePhone/Controller/ConfigureController.php @@ -0,0 +1,87 @@ +checkAuth(AdminResources::MODULE, 'forcephone', AccessManager::UPDATE)) { + return $response; + } + + $configurationForm = $this->createForm('forcephone_configuration'); + + $message = null; + + try { + $form = $this->validateForm($configurationForm); + + // Get the form field values + $data = $form->getData(); + + foreach ($data as $name => $value) { + if (is_array($value)) { + $value = implode(';', $value); + } + + ForcePhone::setConfigValue($name, $value); + } + + // Log configuration modification + $this->adminLogAppend( + "forcephone.configuration.message", + AccessManager::UPDATE, + "ForcePhone configuration updated" + ); + + // Redirect to the success URL, + if ($this->getRequest()->get('save_mode') == 'stay') { + // If we have to stay on the same page, redisplay the configuration page/ + $url = '/admin/module/ForcePhone'; + } else { + // If we have to close the page, go back to the module back-office page. + $url = '/admin/modules'; + } + + return $this->generateRedirect(URL::getInstance()->absoluteUrl($url)); + } catch (FormValidationException $ex) { + $message = $this->createStandardFormValidationErrorMessage($ex); + } catch (\Exception $ex) { + $message = $ex->getMessage(); + } + + $this->setupFormErrorContext( + $this->getTranslator()->trans("ForcePhone configuration", [], ForcePhone::DOMAIN_NAME), + $message, + $configurationForm, + $ex + ); + + // Before 2.2, the errored form is not stored in session + if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { + return $this->render('module-configure', [ 'module_code' => 'ForcePhone' ]); + } else { + return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/ForcePhone')); + } + } +} diff --git a/local/modules/ForcePhone/EventListeners/ForcePhoneEventListener.php b/local/modules/ForcePhone/EventListeners/ForcePhoneEventListener.php new file mode 100644 index 00000000..45eb4071 --- /dev/null +++ b/local/modules/ForcePhone/EventListeners/ForcePhoneEventListener.php @@ -0,0 +1,271 @@ + + */ +class ForcePhoneEventListener implements EventSubscriberInterface +{ + protected $request; + + /** + * ForcePhoneEventListener constructor. + * @param Request $request + */ + public function __construct(Request $request) + { + $this->request = $request; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + TheliaEvents::FORM_AFTER_BUILD . '.thelia_customer_create' => ['forcePhoneInput', 128], + TheliaEvents::FORM_AFTER_BUILD . '.thelia_customer_update' => ['forcePhoneInput', 128], + TheliaEvents::FORM_AFTER_BUILD . '.thelia_address_update' => ['forcePhoneInput', 128], + TheliaEvents::FORM_AFTER_BUILD . '.thelia_address_creation' => ['forcePhoneInput', 128], + TheliaEvents::AFTER_CREATECUSTOMER => ['customerPhoneUpdate', 125], + TheliaEvents::AFTER_UPDATECUSTOMER => ['customerPhoneUpdate', 125], + TheliaEvents::BEFORE_UPDATEADDRESS => ['addressPhoneUpdate', 125], + TheliaEvents::BEFORE_CREATEADDRESS => ['addressPhoneUpdate', 125], + 'open_api_model_validation_address' => ['validateOpenApiAddress', 125] + ]; + } + + /** + * @param TheliaFormEvent $event + */ + public function forcePhoneInput(TheliaFormEvent $event) + { + if ($this->request->fromApi() === false) { + $constraints = []; + + if (ForcePhone::getConfigValue('force_one', false)) { + $constraints[] = new AtLeastOnePhone(); + } + + $validateFormat = ForcePhone::getConfigValue('validate_format', false); + + if ($validateFormat) { + $constraints[] = new CheckPhoneFormat(); + } + + $forcePhone = ForcePhone::getConfigValue('force_phone', false); + + if (!empty($constraints) || $forcePhone) { + $event->getForm()->getFormBuilder() + ->remove('phone') + ->add( + 'phone', + 'text', + [ + 'constraints' => $forcePhone ? array_merge([new NotBlank()], $constraints) : $constraints, + 'label' => Translator::getInstance()->trans('Phone'), + 'label_attr' => ['for' => 'phone'], + 'required' => $forcePhone, + ] + ); + } + + $forceCellPhone = ForcePhone::getConfigValue('force_cellphone', false); + + if (!empty($constraints) || $forceCellPhone) { + $event->getForm()->getFormBuilder() + ->remove('cellphone') + ->add( + 'cellphone', + 'text', + [ + 'constraints' => $forceCellPhone ? array_merge([new NotBlank()], $constraints) : $constraints, + 'label' => Translator::getInstance()->trans('Cellphone'), + 'label_attr' => ['for' => 'cellphone'], + 'required' => $forceCellPhone, + ] + ); + } + } + } + + /** + * @param AddressEvent $addressEvent + */ + public function addressPhoneUpdate(AddressEvent $addressEvent) + { + $validateFormat = ForcePhone::getConfigValue('validate_format', false); + + if ($this->request->fromApi() === false && $validateFormat) { + $address = $addressEvent->getAddress(); + + try { + $phoneUtil = PhoneNumberUtil::getInstance(); + + if (!empty($address->getPhone())) { + $phoneNumberProto = $phoneUtil->parse($address->getPhone(), $address->getCountry()->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if ($isValid) { + $phone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + + $address->setPhone($phone); + } + } + + if (!empty($address->getCellphone())) { + $phoneNumberProto = $phoneUtil->parse($address->getCellphone(), $address->getCountry()->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if ($isValid) { + $phone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + + $address->setCellphone($phone); + } + } + + } catch (\Exception $exception) { + Tlog::getInstance()->warning('Error on update phone format'); + } + } + } + + /** + * @param CustomerEvent $customerEvent + */ + public function customerPhoneUpdate(CustomerEvent $customerEvent) + { + $validateFormat = ForcePhone::getConfigValue('validate_format', false); + + if ($this->request->fromApi() === false && $validateFormat) { + $address = $customerEvent->getCustomer()->getDefaultAddress(); + + try { + $phoneUtil = PhoneNumberUtil::getInstance(); + + if (!empty($address->getPhone())) { + $phoneNumberProto = $phoneUtil->parse($address->getPhone(), $address->getCountry()->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if ($isValid) { + $phone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + + $address->setPhone($phone)->save(); + } + } + + if (!empty($address->getCellphone())) { + $phoneNumberProto = $phoneUtil->parse($address->getCellphone(), $address->getCountry()->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if ($isValid) { + $phone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + + $address->setCellphone($phone)->save(); + } + } + } catch (\Exception $exception) { + Tlog::getInstance()->warning('Error on update phone format'); + } + } + } + + public function validateOpenApiAddress(ModelValidationEvent $event) + { + + if ($event->getGroups() === 'read' ) { + return; + } + + /** @var Address $address */ + $address = $event->getModel(); + $country = CountryQuery::create()->filterById($address->getCountryId())->findOne(); + $violations = $event->getViolations(); + + $phoneUtil = PhoneNumberUtil::getInstance(); + + if (!empty($address->getPhone())) { + try { + $phoneNumberProto = $phoneUtil->parse($address->getPhone(), $country->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if (!$isValid) { + throw new \Exception('Invalid phone number'); + } + + $phone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + $address->setPhone($phone); + }catch (\Exception $exception){ + $message = Translator::getInstance()->trans( + 'Please enter a valid phone number', + [], + ForcePhone::DOMAIN_NAME + ); + $violations['phoneNumber'] = $event->getModelFactory()->buildModel('SchemaViolation', ['message' => $message]); + } + } + + if (!empty($address->getCellphone())) { + try { + $phoneNumberProto = $phoneUtil->parse($address->getCellphone(), $country->getIsoalpha2()); + + $isValid = $phoneUtil->isValidNumber($phoneNumberProto); + + if (!$isValid) { + throw new \Exception('Invalid cellphone number'); + } + + $cellphone = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::INTERNATIONAL); + $address->setCellphone($cellphone); + }catch (\Exception $exception){ + $message = Translator::getInstance()->trans( + 'Please enter a valid phone number', + [], + ForcePhone::DOMAIN_NAME + ); + $violations['cellphoneNumber'] = $event->getModelFactory()->buildModel('SchemaViolation', ['message' => $message]); + } + } + + $event->setModel($address); + + $event->setViolations($violations); + } +} diff --git a/local/modules/ForcePhone/ForcePhone.php b/local/modules/ForcePhone/ForcePhone.php new file mode 100644 index 00000000..73562489 --- /dev/null +++ b/local/modules/ForcePhone/ForcePhone.php @@ -0,0 +1,36 @@ + + */ +class ForcePhone extends BaseModule +{ + /** @var string */ + const DOMAIN_NAME = 'forcephone'; + + + public function postActivation(ConnectionInterface $con = null) + { + // Define default values + if (null === self::getConfigValue('force_phone', null)) { + self::setConfigValue('force_phone', 1); + } + } +} diff --git a/local/modules/ForcePhone/Form/ConfigForm.php b/local/modules/ForcePhone/Form/ConfigForm.php new file mode 100644 index 00000000..ce0f8b66 --- /dev/null +++ b/local/modules/ForcePhone/Form/ConfigForm.php @@ -0,0 +1,78 @@ +formBuilder + ->add( + 'force_phone', + 'checkbox', + [ + 'required' => false, + 'label' => $this->translator->trans('Home phone number', [], ForcePhone::DOMAIN_NAME), + 'label_attr' => [ + 'for' => 'force_phone', + ] + ] + ) + ->add( + 'force_cellphone', + 'checkbox', + [ + 'required' => false, + 'label' => $this->translator->trans('Mobile phone number', [], ForcePhone::DOMAIN_NAME), + 'label_attr' => [ + 'for' => 'force_cellphone', + ] + ] + ) + ->add( + 'force_one', + 'checkbox', + [ + 'required' => false, + 'label' => $this->translator->trans('At least one phone number', [], ForcePhone::DOMAIN_NAME), + 'label_attr' => [ + 'for' => 'force_one', + ] + ] + ) + ->add( + 'validate_format', + 'checkbox', + [ + 'required' => false, + 'label' => $this->translator->trans('Check phone numbers format', [], ForcePhone::DOMAIN_NAME), + 'label_attr' => [ + 'for' => 'validate_format', + ] + ] + ) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'forcephone_config'; + } +} diff --git a/local/modules/ForcePhone/Hook/HookManager.php b/local/modules/ForcePhone/Hook/HookManager.php new file mode 100644 index 00000000..7725f624 --- /dev/null +++ b/local/modules/ForcePhone/Hook/HookManager.php @@ -0,0 +1,49 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ForcePhone\Hook; + +use ForcePhone\ForcePhone; +use Thelia\Core\Event\Hook\HookRenderEvent; +use Thelia\Core\Hook\BaseHook; +use Thelia\Model\ModuleConfig; +use Thelia\Model\ModuleConfigQuery; + +class HookManager extends BaseHook +{ + public function onModuleConfigure(HookRenderEvent $event) + { + $vars = []; + + if (null !== $params = ModuleConfigQuery::create()->findByModuleId(ForcePhone::getModuleId())) { + /** @var ModuleConfig $param */ + foreach ($params as $param) { + $vars[ $param->getName() ] = $param->getValue(); + } + } + + $event->add( + $this->render('force-phone/module-configuration.html', $vars) + ); + } +} diff --git a/local/modules/ForcePhone/I18n/backOffice/default/en_US.php b/local/modules/ForcePhone/I18n/backOffice/default/en_US.php new file mode 100644 index 00000000..e637ccec --- /dev/null +++ b/local/modules/ForcePhone/I18n/backOffice/default/en_US.php @@ -0,0 +1,6 @@ + 'Force Phone Configuration', + 'Please check below the phone numbers that must be mandatory in the customer and addresses forms' => 'Please check below the phone numbers that will be required in the customer and address forms', +); diff --git a/local/modules/ForcePhone/I18n/backOffice/default/fr_FR.php b/local/modules/ForcePhone/I18n/backOffice/default/fr_FR.php new file mode 100644 index 00000000..e7e7b8da --- /dev/null +++ b/local/modules/ForcePhone/I18n/backOffice/default/fr_FR.php @@ -0,0 +1,6 @@ + 'Configuration de Force Phone', + 'Please check below the phone numbers that must be mandatory in the customer and addresses forms' => 'Merci de cocher ci-dessous les numéros de téléphones qui doivent être obligatoirement saisis dans les formulaires client et addresse', +); diff --git a/local/modules/ForcePhone/I18n/en_US.php b/local/modules/ForcePhone/I18n/en_US.php new file mode 100644 index 00000000..0fdb5c93 --- /dev/null +++ b/local/modules/ForcePhone/I18n/en_US.php @@ -0,0 +1,14 @@ + 'At least one phone number', + 'Cellphone' => 'Cellphone', + 'ForcePhone configuration' => 'ForcePhone configuration', + 'Home phone number' => 'Home phone number', + 'Mobile phone number' => 'Mobile phone number', + 'Phone' => 'Phone', + 'Please enter a home or mobile phone number' => 'Please enter a home or mobile phone number', + 'Please enter at least one phone number.' => 'Please enter at least one phone number.', + 'Check phone numbers format' => 'Check phone numbers format', + 'Please enter a valid phone number' => 'Please enter a valid phone number', +); diff --git a/local/modules/ForcePhone/I18n/fr_FR.php b/local/modules/ForcePhone/I18n/fr_FR.php new file mode 100644 index 00000000..4e48a08d --- /dev/null +++ b/local/modules/ForcePhone/I18n/fr_FR.php @@ -0,0 +1,14 @@ + 'Au moins un des deux', + 'Cellphone' => 'Téléphone mobile', + 'ForcePhone configuration' => 'Configuration de Force Phone', + 'Home phone number' => 'Numéro de téléphone fixe', + 'Mobile phone number' => 'Numéro de téléphone mobile', + 'Phone' => 'Téléphone fixe', + 'Please enter a home or mobile phone number' => 'Merci d\'indiquer un numéro de téléphone fixe ou mobile', + 'Please enter at least one phone number.' => 'Merci d\'indiquer au moins un numéro de téléphone', + 'Check phone numbers format' => 'Vérifier le format de la saisie du téléphone', + 'Please enter a valid phone number' => 'Merci d\'indiquer un numéro de téléphone valide', +); diff --git a/local/modules/ForcePhone/Readme.md b/local/modules/ForcePhone/Readme.md new file mode 100644 index 00000000..90da009a --- /dev/null +++ b/local/modules/ForcePhone/Readme.md @@ -0,0 +1,40 @@ +# Force Phone + +This module sets the mobile phone number, the home phone number, both or one of them as required in the customer and address forms. + +## Installation + +**Since 1.2 need to be installed by Composer** + +### Composer + +Add it in your main Thelia composer.json file + +``` +composer require thelia/force-phone-module:~1.2 +``` + +### Manually (only for version < 1.2) + +* Copy the module into ```/local/modules/``` directory and be sure that the name of the module is ForcePhone. +* Activate it in your Thelia administration panel + +## Usage + +Activate the module and the home phone number becomes required in the customer and address forms. +Go to module configuration to select which phone numbers (home, mobile, both or one of them) should be required. + +Affected pages : +- register +- create address +- update address + +## Other + +Be sure to set proper translations for phone inputs' labels. + +You can find translation for the mandatory input in your administration panel: +` Configuration --> Translation --> Modules --> Set the phone input mandatory for the customer --> Core files ` + +Translation for the second phone input is in: +` Configuration --> Translation --> Thelia core ` diff --git a/local/modules/ForcePhone/composer.json b/local/modules/ForcePhone/composer.json new file mode 100644 index 00000000..47ca5307 --- /dev/null +++ b/local/modules/ForcePhone/composer.json @@ -0,0 +1,12 @@ +{ + "name": "thelia/force-phone-module", + "license": "LGPL-3.0+", + "type": "thelia-module", + "require": { + "thelia/installer": "~1.1", + "giggsey/libphonenumber-for-php": "^8.10" + }, + "extra": { + "installer-name": "ForcePhone" + } +} \ No newline at end of file diff --git a/local/modules/ForcePhone/templates/backOffice/default/force-phone/module-configuration.html b/local/modules/ForcePhone/templates/backOffice/default/force-phone/module-configuration.html new file mode 100644 index 00000000..92e7ab43 --- /dev/null +++ b/local/modules/ForcePhone/templates/backOffice/default/force-phone/module-configuration.html @@ -0,0 +1,60 @@ +
+
+
+
+ {intl d='forcephone.bo.default' l="Force Phone Configuration"} +
+
+ +
+
+
+ {form name="forcephone_configuration"} + + {form_hidden_fields form=$form} + + {include file = "includes/inner-form-toolbar.html" + hide_flags = true + page_url = "{url path='/admin/module/ForcePhone'}" + close_url = "{url path='/admin/modules'}" + } + + {if $form_error} +
+
+
{$form_error_message}
+
+
+ {/if} + +
+
+

{intl d='forcephone.bo.default' l='Please check below the phone numbers that must be mandatory in the customer and addresses forms'}

+ {custom_render_form_field form=$form field="force_phone"} + + {$label} + {/custom_render_form_field} + + {custom_render_form_field form=$form field="force_cellphone"} + + {$label} + {/custom_render_form_field} + + {custom_render_form_field form=$form field="force_one"} + + {$label} + {/custom_render_form_field} + + {custom_render_form_field form=$form field="validate_format"} + + {$label} + {/custom_render_form_field} +
+
+ + {/form} +
+
+
+
+
\ No newline at end of file