From 12cd6c325546522c2c526edef9bb73823bf33f88 Mon Sep 17 00:00:00 2001 From: Da Silva Mendonca Thomas Date: Wed, 23 Nov 2022 09:18:28 +0100 Subject: [PATCH 1/2] push ReplacedOrderModule --- Config/config.xml | 22 +++++ Config/module.xml | 28 +++++++ Config/routing.xml | 10 +++ Config/schema.xml | 12 +++ Config/sqldb.map | 2 + Config/thelia.sql | 22 +++++ Controller/ReplacedOrderModule.php | 44 ++++++++++ Form/ReplacedOrderModuleForm.php | 52 ++++++++++++ Hook/ConfigurationHook.php | 14 ++++ I18n/en_US.php | 4 + I18n/fr_FR.php | 4 + Model/ReplacedModule.php | 20 +++++ Model/ReplacedModuleQuery.php | 20 +++++ README.md | 25 +++++- ReplacedOrderModule.php | 28 +++++++ Service/ReplacedOrderModuleService.php | 81 +++++++++++++++++++ composer.json | 12 +++ .../default/module_configuration.html | 37 +++++++++ 18 files changed, 436 insertions(+), 1 deletion(-) create mode 100644 Config/config.xml create mode 100644 Config/module.xml create mode 100644 Config/routing.xml create mode 100644 Config/schema.xml create mode 100644 Config/sqldb.map create mode 100644 Config/thelia.sql create mode 100644 Controller/ReplacedOrderModule.php create mode 100644 Form/ReplacedOrderModuleForm.php create mode 100644 Hook/ConfigurationHook.php create mode 100644 I18n/en_US.php create mode 100644 I18n/fr_FR.php create mode 100644 Model/ReplacedModule.php create mode 100644 Model/ReplacedModuleQuery.php create mode 100644 ReplacedOrderModule.php create mode 100644 Service/ReplacedOrderModuleService.php create mode 100644 composer.json create mode 100644 templates/backOffice/default/module_configuration.html diff --git a/Config/config.xml b/Config/config.xml new file mode 100644 index 0000000..bfa5fbf --- /dev/null +++ b/Config/config.xml @@ -0,0 +1,22 @@ + + + + + +
+ + + + + + + + + + + + + + diff --git a/Config/module.xml b/Config/module.xml new file mode 100644 index 0000000..fe57b1e --- /dev/null +++ b/Config/module.xml @@ -0,0 +1,28 @@ + + + ReplacedOrderModule\ReplacedOrderModule + + Replaced Payment and Delivery Module in Order + + + Remplacement des Modules de Livraison et de Payments des Commandes + + + en_US + fr_FR + + 1.0.0 + + + thomas da silva mendonca + tdasilva@openstudio + + + classic + 2.4.4 + other + 0 + 0 + diff --git a/Config/routing.xml b/Config/routing.xml new file mode 100644 index 0000000..8e01831 --- /dev/null +++ b/Config/routing.xml @@ -0,0 +1,10 @@ + + + + + + ReplacedOrderModule\Controller\ReplacedOrderModule::replaceOrderModule + + diff --git a/Config/schema.xml b/Config/schema.xml new file mode 100644 index 0000000..f470e88 --- /dev/null +++ b/Config/schema.xml @@ -0,0 +1,12 @@ + + + + + + + + +
+
diff --git a/Config/sqldb.map b/Config/sqldb.map new file mode 100644 index 0000000..63a93ba --- /dev/null +++ b/Config/sqldb.map @@ -0,0 +1,2 @@ +# Sqlfile -> Database map +thelia.sql=thelia diff --git a/Config/thelia.sql b/Config/thelia.sql new file mode 100644 index 0000000..06ef60f --- /dev/null +++ b/Config/thelia.sql @@ -0,0 +1,22 @@ + +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- replaced_module +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `replaced_module`; + +CREATE TABLE `replaced_module` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `code` VARCHAR(255), + `title` VARCHAR(255), + `created_at` DATETIME, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/Controller/ReplacedOrderModule.php b/Controller/ReplacedOrderModule.php new file mode 100644 index 0000000..402fe82 --- /dev/null +++ b/Controller/ReplacedOrderModule.php @@ -0,0 +1,44 @@ +checkAuth([AdminResources::MODULE], ["CustomerTools"], AccessManager::UPDATE)) { + return $response; + } + + $form = $this->createForm('replaced_order_module_form'); + + try { + $data = $this->validateForm($form)->getData(); + + /** @var ReplacedOrderModuleService $replacedOrderModuleService */ + $replacedOrderModuleService = $this->getContainer()->get('action.replace.order.module.service'); + + $module = $replacedOrderModuleService->getModule($data["modules"]); + + $replacedOrderModuleService->saveModule($module); + $replacedOrderModuleService->updateOrder($module); + + return $this->generateSuccessRedirect($form); + } catch (\Exception $e) { + $error_message = $e->getMessage(); + } + + $form->setErrorMessage($error_message); + + $this->getParserContext() + ->addForm($form) + ->setGeneralError($error_message); + + return $this->generateErrorRedirect($form); + } +} \ No newline at end of file diff --git a/Form/ReplacedOrderModuleForm.php b/Form/ReplacedOrderModuleForm.php new file mode 100644 index 0000000..e575244 --- /dev/null +++ b/Form/ReplacedOrderModuleForm.php @@ -0,0 +1,52 @@ +initModulesList(); + $this->formBuilder + ->add('modules', + ChoiceType::class, + [ + 'required' => true, + 'choices' => $this->initModulesList(), + 'label' => Translator::getInstance()->trans('Replaced Module'), + ]); + } + + public function getName(){ + return 'replaced_order_form'; + } + + private function initModulesList(){ + $choices = []; + + $modules = ModuleQuery::create() + ->filterByType(2) + ->_or() + ->filterByType(3) + ->find(); + + foreach ($modules as $module) { + try { + $choices[$module->getId()] = $module->getCode(); + } catch (PropelException $e) { + Tlog::getInstance()->error($e->getMessage()); + } + } + return $choices; + } +} \ No newline at end of file diff --git a/Hook/ConfigurationHook.php b/Hook/ConfigurationHook.php new file mode 100644 index 0000000..45243cf --- /dev/null +++ b/Hook/ConfigurationHook.php @@ -0,0 +1,14 @@ +add(($this->render("module_configuration.html"))); + } +} \ No newline at end of file diff --git a/I18n/en_US.php b/I18n/en_US.php new file mode 100644 index 0000000..0b4fa14 --- /dev/null +++ b/I18n/en_US.php @@ -0,0 +1,4 @@ + 'The displayed english string', +); diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php new file mode 100644 index 0000000..3708624 --- /dev/null +++ b/I18n/fr_FR.php @@ -0,0 +1,4 @@ + 'La traduction française de la chaine', +); diff --git a/Model/ReplacedModule.php b/Model/ReplacedModule.php new file mode 100644 index 0000000..8099eeb --- /dev/null +++ b/Model/ReplacedModule.php @@ -0,0 +1,20 @@ +/local/modules/``` directory and be sure that the name of the module is ReplacedOrderModule. +* Activate it in your thelia administration panel + +### Composer + +Add it in your main thelia composer.json file + +``` +composer require thelia/replaced-order-module-module:~1.0 +``` + +## Usage + +This module add a selector in the config where you can choose the delivery or payment module you want to replace \ No newline at end of file diff --git a/ReplacedOrderModule.php b/ReplacedOrderModule.php new file mode 100644 index 0000000..c3a0bea --- /dev/null +++ b/ReplacedOrderModule.php @@ -0,0 +1,28 @@ +findOneByCode('ReplacedOrderModule'); + } + + /** + * @param int $id + * @return Module + */ + public function getModule(int $id): Module + { + return ModuleQuery::create() + ->useI18nQuery() + ->endUse() + ->groupById() + ->findOneById($id); + } + + /** + * @param $module + * @return void + * @throws PropelException + */ + public function saveModule(Module $module) + { + $replacedModule = new ReplacedModule(); + $replacedModule->setCode($module->getCode()); + $replacedModule->setTitle($module->getTitle()); + $replacedModule->setCreatedAt(new \DateTime("now")); + $replacedModule->save(); + } + + /** + * @param $module + * @return void + * @throws PropelException + */ + public function updateOrder(Module $module) + { + $orders = OrderQuery::create(); + $replacedOrderModule = $this->getReplacedOrderModule(); + + if ($module->getCategory() == 'payment') { + $orders->filterByPaymentModuleId($module->getId()) + ->find(); + foreach ($orders as $order) { + $order->setPaymentModuleId($replacedOrderModule->getId()); + $order->save(); + } + } + + if ($module->getCategory() == 'delivery') { + $orders = OrderQuery::create() + ->filterByDeliveryModuleId($module->getId()) + ->find(); + + foreach ($orders as $order) { + $order->setDeliveryModuleId($replacedOrderModule->getId()); + $order->save(); + } + } + } +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bcd8eca --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ +{ + "name": "thelia/replaced-order-module-module", + "description": "ReplacedOrderModule module for Thelia", + "license": "LGPL-3.0-or-later", + "type": "thelia-module", + "require": { + "thelia/installer": "~1.1" + }, + "extra": { + "installer-name": "ReplacedOrderModule" + } +} \ No newline at end of file diff --git a/templates/backOffice/default/module_configuration.html b/templates/backOffice/default/module_configuration.html new file mode 100644 index 0000000..3c708f2 --- /dev/null +++ b/templates/backOffice/default/module_configuration.html @@ -0,0 +1,37 @@ +
+
+ +
+ {intl l='replacedordermodule.title' d='replacedordermodule.bo.default'} +
+ +
+
+ {form name="replaced_order_module_form"} + + + {render_form_field field="success_url" value={url path='/admin/module/ReplacedOrderModule'}} + {render_form_field field="error_url" value={url path='/admin/module/ReplacedOrderModule'}} + {form_hidden_fields } + + {if $form_error} +
+
+
{$form_error_message}
+
+
+ {/if} + +
+ {render_form_field field='modules'} +
+
+ +
+ + {/form} + +
+
+
+
From 61c89a606eaec2173e723c089b878f173f2b9985 Mon Sep 17 00:00:00 2001 From: Da Silva Mendonca Thomas Date: Wed, 23 Nov 2022 09:34:05 +0100 Subject: [PATCH 2/2] add I18n --- I18n/backOffice/default/fr_FR.php | 6 ++++++ I18n/fr_FR.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 I18n/backOffice/default/fr_FR.php diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php new file mode 100644 index 0000000..d39f552 --- /dev/null +++ b/I18n/backOffice/default/fr_FR.php @@ -0,0 +1,6 @@ + 'Remplacer le Module', + 'replacedordermodule.title' => 'Replaced Order Module', +); diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php index 3708624..5bf56e4 100644 --- a/I18n/fr_FR.php +++ b/I18n/fr_FR.php @@ -1,4 +1,5 @@ 'La traduction française de la chaine', + 'Replaced Module' => 'Module à Remplacer', );