Externalisation de la clé API Google dans la config du module PlanificationLivraison
This commit is contained in:
@@ -25,4 +25,7 @@
|
|||||||
<stability>alpha</stability>
|
<stability>alpha</stability>
|
||||||
<mandatory>0</mandatory>
|
<mandatory>0</mandatory>
|
||||||
<hidden>0</hidden>
|
<hidden>0</hidden>
|
||||||
|
<required>
|
||||||
|
<module version="~1.0">PlanificationLivraison</module>
|
||||||
|
</required>
|
||||||
</module>
|
</module>
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
<input type="hidden" id="map-center-lat" value="50.749980292425974" />
|
<input type="hidden" id="map-center-lat" value="50.749980292425974" />
|
||||||
|
|
||||||
<div id="map" class="locationMap"></div>
|
<div id="map" class="locationMap"></div>
|
||||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBb07YA_unrh5w821I1xHxbeYb5KCF_WaM&libraries=&v=weekly" async></script>
|
<script src="https://maps.googleapis.com/maps/api/js?key={module_config module='PlanificationLivraison' key='planiflivraison_googlemap_api_key' locale='en_US'}&libraries=&v=weekly" async></script>
|
||||||
|
|
||||||
<caption class="clearfix">
|
<caption class="clearfix">
|
||||||
<div class="legende">NB : Les communes sans coordonnées GPS n'apparaitront pas sur la carte ci-dessus.</div>
|
<div class="legende">NB : Les communes sans coordonnées GPS n'apparaitront pas sur la carte ci-dessus.</div>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
{if {cart attr='total_taxed_price_without_discount'} < $minimum}
|
{if {cart attr='total_taxed_price_without_discount'} < $minimum}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="alert alert-info" style="margin-bottom:30px">{intl l="Message info minimum de commande" d="livraisonparsecteurs" minimum=$minimum delta=$minimum-{cart attr='total_taxed_price_without_discount'}}</div>
|
<div class="alert alert-info" style="margin:10px 0">{intl l="Message info minimum de commande" d="livraisonparsecteurs" minimum=$minimum delta=$minimum-{cart attr='total_taxed_price_without_discount'}}</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,19 @@
|
|||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
|
<forms>
|
||||||
|
<form name="planiflivraison.configuration" class="PlanificationLivraison\Form\Configuration" />
|
||||||
|
</forms>
|
||||||
|
|
||||||
|
|
||||||
<loops>
|
<loops>
|
||||||
<loop name="scheduled_deliveries" class="PlanificationLivraison\Loop\ScheduledDeliveriesLoop"/>
|
<loop name="scheduled_deliveries" class="PlanificationLivraison\Loop\ScheduledDeliveriesLoop"/>
|
||||||
</loops>
|
</loops>
|
||||||
|
|
||||||
|
<hooks>
|
||||||
|
<hook id="planiflivraison.hook" class="PlanificationLivraison\Hook\HookManager">
|
||||||
|
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfiguration" />
|
||||||
|
</hook>
|
||||||
|
</hooks>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
10
local/modules/PlanificationLivraison/Config/routing.xml
Normal file
10
local/modules/PlanificationLivraison/Config/routing.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<routes xmlns="http://symfony.com/schema/routing"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
|
<route id="planiflivraison.configuration" path="/admin/module/PlanificationLivraison/configuration/update" methods="post">
|
||||||
|
<default key="_controller">PlanificationLivraison\Controller\Configuration::editConfig</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
|
</routes>
|
||||||
66
local/modules/PlanificationLivraison/Controller/Configuration.php
Executable file
66
local/modules/PlanificationLivraison/Controller/Configuration.php
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PlanificationLivraison\Controller;
|
||||||
|
|
||||||
|
use PlanificationLivraison\PlanificationLivraison;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Thelia\Controller\Admin\BaseAdminController;
|
||||||
|
use Thelia\Core\Security\AccessManager;
|
||||||
|
use Thelia\Core\Security\Resource\AdminResources;
|
||||||
|
use Thelia\Form\Exception\FormValidationException;
|
||||||
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Configuration
|
||||||
|
* @package PlanificationLivraison\Controller
|
||||||
|
*/
|
||||||
|
class Configuration extends BaseAdminController
|
||||||
|
{
|
||||||
|
public function editConfig()
|
||||||
|
{
|
||||||
|
if (null !== $response = $this->checkAuth(
|
||||||
|
AdminResources::MODULE,
|
||||||
|
[PlanificationLivraison::DOMAIN_NAME],
|
||||||
|
AccessManager::UPDATE
|
||||||
|
)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = $this->createForm('planiflivraison.configuration');
|
||||||
|
$error_message = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$validateForm = $this->validateForm($form);
|
||||||
|
$data = $validateForm->getData();
|
||||||
|
|
||||||
|
PlanificationLivraison::setConfigValue(
|
||||||
|
PlanificationLivraison::CONFIG_VALUE_NAME,
|
||||||
|
$data["google_api_key"]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirectToConfigurationPage();
|
||||||
|
|
||||||
|
} catch (FormValidationException $e) {
|
||||||
|
$error_message = $this->createStandardFormValidationErrorMessage($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $error_message) {
|
||||||
|
$this->setupFormErrorContext(
|
||||||
|
'configuration',
|
||||||
|
$error_message,
|
||||||
|
$form
|
||||||
|
);
|
||||||
|
$response = $this->render("module-configure", ['module_code' => 'PlanificationLivraison']);
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirect to the configuration page
|
||||||
|
*/
|
||||||
|
protected function redirectToConfigurationPage()
|
||||||
|
{
|
||||||
|
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/PlanificationLivraison'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
local/modules/PlanificationLivraison/Form/Configuration.php
Normal file
38
local/modules/PlanificationLivraison/Form/Configuration.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PlanificationLivraison\Form;
|
||||||
|
|
||||||
|
use PlanificationLivraison\PlanificationLivraison;
|
||||||
|
use Thelia\Form\BaseForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Configuration
|
||||||
|
* @package PlanificationLivraison\Form
|
||||||
|
*/
|
||||||
|
class Configuration extends BaseForm
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function buildForm()
|
||||||
|
{
|
||||||
|
$this->formBuilder
|
||||||
|
->add(
|
||||||
|
"google_api_key",
|
||||||
|
"text",
|
||||||
|
array(
|
||||||
|
"label" => "GoogleMap API key",
|
||||||
|
"label_attr" => [
|
||||||
|
"for" => "google_api_key"
|
||||||
|
],
|
||||||
|
"required" => true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string the name of you form. This name must be unique
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return "planiflivraison_configuration";
|
||||||
|
}
|
||||||
|
}
|
||||||
20
local/modules/PlanificationLivraison/Hook/HookManager.php
Normal file
20
local/modules/PlanificationLivraison/Hook/HookManager.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PlanificationLivraison\Hook;
|
||||||
|
|
||||||
|
use Thelia\Core\Event\Hook\HookRenderEvent;
|
||||||
|
use Thelia\Core\Hook\BaseHook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class HookManager
|
||||||
|
* @package PlanificationLivraison\Hook
|
||||||
|
*/
|
||||||
|
class HookManager extends BaseHook
|
||||||
|
{
|
||||||
|
public function onModuleConfiguration(HookRenderEvent $event)
|
||||||
|
{
|
||||||
|
$module_id = self::getModule()->getModuleId();
|
||||||
|
|
||||||
|
$event->add($this->render("module_configuration.html", ['module_id' => $module_id]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
return array(
|
return array(
|
||||||
// 'an english string' => 'La traduction française de la chaine',
|
'GoogleMap API key' => 'Clé API GoogleMap',
|
||||||
|
'Save' => 'Enregistrer',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class PlanificationLivraison extends BaseModule
|
|||||||
{
|
{
|
||||||
/** @var string */
|
/** @var string */
|
||||||
const DOMAIN_NAME = 'planiflivraison';
|
const DOMAIN_NAME = 'planiflivraison';
|
||||||
|
const CONFIG_VALUE_NAME = 'planiflivraison_googlemap_api_key';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{if isset($smarty.get.errmes) && !empty($smarty.get.errmes)}
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
{$smarty.get.errmes}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="general-block-decorator">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{form name="planiflivraison.configuration"}
|
||||||
|
<form method="POST" action="{url path='/admin/module/PlanificationLivraison/configuration/update'}">
|
||||||
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
|
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
|
||||||
|
|
||||||
|
{render_form_field field="google_api_key" value={module_config module="PlanificationLivraison" key='planiflivraison_googlemap_api_key' locale="en_US"}}
|
||||||
|
|
||||||
|
<button type="submit" name="planiflivraison_save_configuration" value="save" class="form-submit-button btn btn-sm btn-default" title="{intl d='planificationlivraison' l='Save'}">
|
||||||
|
{intl d='planificationlivraison' l='Save'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{/form}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -25,4 +25,7 @@
|
|||||||
<stability>beta</stability>
|
<stability>beta</stability>
|
||||||
<mandatory>0</mandatory>
|
<mandatory>0</mandatory>
|
||||||
<hidden>0</hidden>
|
<hidden>0</hidden>
|
||||||
|
<required>
|
||||||
|
<module version="~1.0">PlanificationLivraison</module>
|
||||||
|
</required>
|
||||||
</module>
|
</module>
|
||||||
|
|||||||
@@ -184,7 +184,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBb07YA_unrh5w821I1xHxbeYb5KCF_WaM&callback=initMap&libraries=&v=weekly" async></script>
|
<script src="https://maps.googleapis.com/maps/api/js?key={module_config module='PlanificationLivraison' key='planiflivraison_googlemap_api_key' locale='en_US'}&callback=initMap&libraries=&v=weekly" async></script>
|
||||||
<div id="map" class="locationMap"></div>
|
<div id="map" class="locationMap"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,12 +20,6 @@
|
|||||||
<div class="col-sm-4"> </div>
|
<div class="col-sm-4"> </div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{if {cart attr='total_taxed_price_without_discount'} < $minimum}
|
|
||||||
<!-- <div class="row">-->
|
|
||||||
<!-- <div class="alert alert-info" style="margin-bottom:30px">{intl l="Message info minimum de commande" d="livraisonparsecteurs" minimum=$minimum delta=$minimum-{cart attr='total_taxed_price_without_discount'}}</div>-->
|
|
||||||
<!-- </div>-->
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-5">
|
<div class="col-md-5">
|
||||||
<div id="select-pdr">
|
<div id="select-pdr">
|
||||||
@@ -75,6 +69,10 @@
|
|||||||
$('input[type=radio][delivery-mode]').click(function() {
|
$('input[type=radio][delivery-mode]').click(function() {
|
||||||
$('div[id^="select"]').not($('#select-' + $(this).attr('delivery-mode'))).slideUp();
|
$('div[id^="select"]').not($('#select-' + $(this).attr('delivery-mode'))).slideUp();
|
||||||
$('#select-' + $(this).attr('delivery-mode')).slideDown('fast');
|
$('#select-' + $(this).attr('delivery-mode')).slideDown('fast');
|
||||||
|
|
||||||
|
if ($('[delivery-mode=pdr]').is(':checked')) {
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#form-cart-delivery").off('submit').submit(function(ev) {
|
$("#form-cart-delivery").off('submit').submit(function(ev) {
|
||||||
@@ -86,4 +84,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function loadScript() {
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.type = 'text/javascript';
|
||||||
|
script.src = "https://maps.googleapis.com/maps/api/js?callback=mondialRelaySetup&key={config key='planiflivraison_googlemap_api_key'}";
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user