diff --git a/Config/config.xml b/Config/config.xml index 772ba0a..7165f35 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -61,6 +61,9 @@ + + + @@ -74,6 +77,7 @@ + @@ -89,6 +93,7 @@ +
diff --git a/Config/module.xml b/Config/module.xml index 20332d8..a024f0f 100755 --- a/Config/module.xml +++ b/Config/module.xml @@ -16,7 +16,7 @@ en_US fr_FR - 2.4.4 + 2.4.5 Penalver Antony apenalver@openstudio.fr diff --git a/Config/routing.xml b/Config/routing.xml index 9ce5775..8ed4205 100755 --- a/Config/routing.xml +++ b/Config/routing.xml @@ -23,6 +23,11 @@ \d+ + + + Dealer:Configure:configure + + Dealer:Contact:create diff --git a/Controller/ConfigureController.php b/Controller/ConfigureController.php new file mode 100644 index 0000000..728ea2c --- /dev/null +++ b/Controller/ConfigureController.php @@ -0,0 +1,81 @@ +checkAuth(AdminResources::MODULE, 'dealer', AccessManager::UPDATE)) { + return $response; + } + + $configurationForm = $this->createForm('dealer.configuration.form'); + $message = null; + + try { + $form = $this->validateForm($configurationForm); + + // Get the form field values + $data = $form->getData(); + + Dealer::setConfigValue('googlemapsapi_key',$data['googlemapsapi_key']); + + + // 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/Dealer'; + } 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("Dealer configuration", [], Dealer::MESSAGE_DOMAIN), + $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' => 'Dealer' ]); + } else { + return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Dealer')); + } + } +} diff --git a/Dealer.php b/Dealer.php index cd9dc75..9396fee 100755 --- a/Dealer.php +++ b/Dealer.php @@ -83,6 +83,11 @@ public function update($currentVersion, $newVersion, ConnectionInterface $con = ); } } + + if (!self::getConfigValue('is_initialized', false)) { + self::setConfigValue('googlemapsapi_key', ''); + self::setConfigValue('is_initialized', true); + } } public function getHooks() diff --git a/Form/Configuration.php b/Form/Configuration.php new file mode 100644 index 0000000..48c7005 --- /dev/null +++ b/Form/Configuration.php @@ -0,0 +1,53 @@ +formBuilder; + + $form->add( + "googlemapsapi_key", + "text", + array( + 'data' => Dealer::getConfigValue("googlemapsapi_key"), + 'label' => Translator::getInstance()->trans("Google Maps Api Key"), + 'label_attr' => array( + 'for' => "googlemapsapi_key" + ), + ) + ); + + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return "dealer_configuration"; + } + + +} \ No newline at end of file diff --git a/Hook/HookManager.php b/Hook/HookManager.php new file mode 100644 index 0000000..b84d51f --- /dev/null +++ b/Hook/HookManager.php @@ -0,0 +1,29 @@ +findByModuleId(Dealer::getModuleId())) { + /** @var ModuleConfig $param */ + foreach ($params as $param) { + $vars[ $param->getName() ] = $param->getValue(); + } + } + + $event->add( + $this->render('module-configuration.html', $vars) + ); + } +} diff --git a/Hook/InternalHook.php b/Hook/InternalHook.php index e9aff80..ad7e9c2 100644 --- a/Hook/InternalHook.php +++ b/Hook/InternalHook.php @@ -8,8 +8,10 @@ namespace Dealer\Hook; +use Dealer\Dealer; use Thelia\Core\Event\Hook\HookRenderEvent; use Thelia\Core\Hook\BaseHook; +use Dealer\Model\DealerQuery; /** @@ -61,4 +63,33 @@ public function insertProductJs(HookRenderEvent $event) { //$event->add($this->render("script/dealer-product-js.html", $event->getArguments())); } + + public function insertGoogleMapsApiJs(HookRenderEvent $event) + { + $address = ''; + if($this->getRequest()->query->has('dealer_id')) { + $dearler_id = $this->getRequest()->query->get('dealer_id'); + if($dearler_id != '') { + $dealer = DealerQuery::create()->findOneById($dearler_id); + $address = $dealer->getAddress1(); + if($dealer->getAddress2()) { + $address .= ', ' . $dealer->getAddress2(); + } + if($dealer->getAddress3()) { + $address .= ', ' . $dealer->getAddress3(); + } + $address .= ', ' . $dealer->getCity() . ', ' . $dealer->getZipcode() . ', ' . $dealer->getCountry()->getTitle(); + } + } + + $event->add( + $this->render( + "script/dealer-geo-js.html", + [ + 'address' => $address, + 'googlemapsapi_key' => Dealer::getConfigValue('googlemapsapi_key') + ] + ) + ); + } } \ No newline at end of file diff --git a/templates/backOffice/default/dealer-edit.html b/templates/backOffice/default/dealer-edit.html index 26511a4..2b9d611 100755 --- a/templates/backOffice/default/dealer-edit.html +++ b/templates/backOffice/default/dealer-edit.html @@ -144,7 +144,6 @@ {include file="script/dealer-contact-js.html"} {include file="script/dealer-contact-info-js.html"} {include file="script/dealer-schedules-js.html"} - {include file="script/dealer-geo-js.html"} {include file="script/dealer-admin-js.html"} {hook name="dealer.edit.js"} +{/block} + +{block name="javascript-last-call"} +{hook name="wysiwyg.js" location="wysiwyg-document-edit-js" } {/block} \ No newline at end of file diff --git a/templates/backOffice/default/dealers.html b/templates/backOffice/default/dealers.html index 1462bad..70903d2 100755 --- a/templates/backOffice/default/dealers.html +++ b/templates/backOffice/default/dealers.html @@ -244,4 +244,8 @@ }); {hook name="dealer.js"} +{/block} + +{block name="javascript-last-call"} +{hook name="wysiwyg.js" location="wysiwyg-document-edit-js" } {/block} \ No newline at end of file diff --git a/templates/backOffice/default/form/dealer-create.html b/templates/backOffice/default/form/dealer-create.html index ef3f086..78c7439 100644 --- a/templates/backOffice/default/form/dealer-create.html +++ b/templates/backOffice/default/form/dealer-create.html @@ -105,30 +105,9 @@ {/form_field} -{form_field form=$form field="description"} -
- - {form_error form=$form field="description"}{$message}{/form_error} +{render_form_field field="description" extra_class="wysiwyg" value=$DESCRIPTION} - -
-{/form_field} -{form_field form=$form field="access"} -
- +{render_form_field field="access" extra_class="wysiwyg" value=$ACCESS} - {form_error form=$form field="access"}{$message}{/form_error} - - -
-{/form_field} {/form} \ No newline at end of file diff --git a/templates/backOffice/default/form/dealer-geo.html b/templates/backOffice/default/form/dealer-geo.html index 653af7b..3d36576 100644 --- a/templates/backOffice/default/form/dealer-geo.html +++ b/templates/backOffice/default/form/dealer-geo.html @@ -39,11 +39,15 @@ {/form_field} {loop name="auth-create" type="auth" role="ADMIN" resource="admin.dealer.geo" access="UPDATE" module="Dealer"} +
+
+ + {/loop} {/loop} -{/form} \ No newline at end of file +{/form} diff --git a/templates/backOffice/default/module-configuration.html b/templates/backOffice/default/module-configuration.html new file mode 100644 index 0000000..9b921c5 --- /dev/null +++ b/templates/backOffice/default/module-configuration.html @@ -0,0 +1,52 @@ + + + +
+
+ +
+ {intl l='Edit your Google Maps API configuration.'} - ({intl l="Get API key" d="dealer.bo.default"}) +
+ +
+
+ + {form name="dealer.configuration.form"} +
+ + {form_hidden_fields} + + {form_field field='googlemapsapi_key'} +
+ + +
+ {/form_field} + + +
+ {/form} + +
+ +
+ +
+
+ + + + diff --git a/templates/backOffice/default/script/dealer-geo-js.html b/templates/backOffice/default/script/dealer-geo-js.html index 604942e..25c59bd 100644 --- a/templates/backOffice/default/script/dealer-geo-js.html +++ b/templates/backOffice/default/script/dealer-geo-js.html @@ -1,4 +1,4 @@ - + \ No newline at end of file