@@ -245,6 +245,7 @@ public function getCarriersContent()
245245 * @throws PrestaShopException
246246 * @throws ReflectionException
247247 * @throws \Packetery\Exceptions\DatabaseException
248+ * @throws \Packetery\Exceptions\ApiClientException
248249 */
249250 public function getContent ()
250251 {
@@ -299,36 +300,13 @@ public function getContent()
299300 }
300301
301302 if (Tools::isSubmit ('submit ' . $ this ->name )) {
302- if (!$ userPermissionHelper ->hasPermission (\Packetery \Tools \UserPermissionHelper::SECTION_CONFIG , \Packetery \Tools \UserPermissionHelper::PERMISSION_EDIT )) {
303- $ output .= $ this ->displayError ('You do not have permission to save configuration. ' );
303+ $ isSubmit = true ;
304+ /** @var \Packetery\Module\ConfigurationFormService $configurationFormService */
305+ $ configurationFormService = $ this ->diContainer ->get (\Packetery \Module \ConfigurationFormService::class);
306+ $ result = $ configurationFormService ->handleConfigurationSubmit ($ userPermissionHelper );
307+ $ output .= $ result ['output ' ];
308+ if ($ result ['error ' ]) {
304309 $ error = true ;
305- } else {
306- $ isSubmit = true ;
307- $ confOptions = $ this ->getConfigurationOptions ();
308- /** @var \Packetery\Module\Options $packeteryOptions */
309- $ packeteryOptions = $ this ->diContainer ->get (\Packetery \Module \Options::class);
310- foreach ($ confOptions as $ option => $ optionConf ) {
311- $ value = (string )Tools::getValue ($ option );
312- $ configValue = $ packeteryOptions ->formatOption ($ option , $ value );
313- $ errorMessage = $ packeteryOptions ->validate ($ option , $ configValue );
314- if ($ errorMessage !== false ) {
315- $ output .= $ this ->displayError ($ errorMessage );
316- $ error = true ;
317- } else {
318- \Packetery \Tools \ConfigHelper::update ($ option , $ configValue );
319- }
320- }
321- $ paymentRepository = $ this ->diContainer ->get (\Packetery \Payment \PaymentRepository::class);
322- $ paymentList = $ paymentRepository ->getListPayments ();
323- if ($ paymentList ) {
324- foreach ($ paymentList as $ payment ) {
325- if (Tools::getIsset ('payment_cod_ ' . $ payment ['module_name ' ])) {
326- $ paymentRepository ->setOrInsert (1 , $ payment ['module_name ' ]);
327- } else {
328- $ paymentRepository ->setOrInsert (0 , $ payment ['module_name ' ]);
329- }
330- }
331- }
332310 }
333311 }
334312
@@ -507,7 +485,7 @@ private function generateCronInfoBlock()
507485 return $ this ->context ->smarty ->fetch ($ this ->local_path . 'views/templates/admin/generateCronInfoBlock.tpl ' );
508486 }
509487
510- private function getConfigurationOptions ()
488+ public function getConfigurationOptions ()
511489 {
512490 return [
513491 'PACKETERY_APIPASS ' => [
0 commit comments