diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index a6de7d3e7..d9173ae93 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -24,6 +24,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Area\AreaAddCountryEvent; +use Thelia\Core\Event\Area\AreaCreateEvent; use Thelia\Core\Event\Area\AreaDeleteEvent; use Thelia\Core\Event\Area\AreaRemoveCountryEvent; use Thelia\Core\Event\Area\AreaUpdatePostageEvent; @@ -31,6 +32,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\AreaQuery; use Thelia\Model\CountryQuery; use Thelia\Action\BaseAction; +use Thelia\Model\Area as AreaModel; /** @@ -83,6 +85,18 @@ class Area extends BaseAction implements EventSubscriberInterface } } + public function create(AreaCreateEvent $event) + { + $area = new AreaModel(); + + $area + ->setDispatcher($this->getDispatcher()) + ->setName($event->getAreaName()) + ->save(); + + $event->setArea($area); + } + /** * Returns an array of event names this subscriber wants to listen to. @@ -110,7 +124,8 @@ class Area extends BaseAction implements EventSubscriberInterface TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128), TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128), TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128), - TheliaEvents::AREA_DELETE => array('delete', 128) + TheliaEvents::AREA_DELETE => array('delete', 128), + TheliaEvents::AREA_CREATE => array('create', 128) ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index ca1b0821c..2cf8851e1 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -700,6 +700,10 @@ Thelia\Controller\Admin\AreaController::deleteAction + + Thelia\Controller\Admin\AreaController::createAction + + Thelia\Controller\Admin\AreaController::updatePostageAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 824678ae3..0b6fef7cc 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -126,7 +126,7 @@ class AreaController extends AbstractCrudController private function hydrateEvent($event, $formData) { - $event->setName($formData['name']); + $event->setAreaName($formData['name']); return $event; } diff --git a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php index a06ef2bc3..d63afa5b9 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php @@ -36,7 +36,7 @@ class AreaCreateEvent extends AreaEvent /** * @param mixed $name */ - public function setName($name) + public function setAreaName($name) { $this->name = $name; } @@ -44,7 +44,7 @@ class AreaCreateEvent extends AreaEvent /** * @return mixed */ - public function getName() + public function getAreaName() { return $this->name; } diff --git a/templates/admin/default/shipping-configuration.html b/templates/admin/default/shipping-configuration.html index 84287615d..d4c8147c2 100644 --- a/templates/admin/default/shipping-configuration.html +++ b/templates/admin/default/shipping-configuration.html @@ -75,16 +75,23 @@ {* Capture the dialog body, to pass it to the generic dialog *} {capture "creation_dialog"} + {form name="thelia.admin.area.create"} + {form_hidden_fields form=$form} - + {form_field form=$form field='success_url'} + {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} + + {/form_field} + {form_field form=$form field="name"}
- - + +
+ {/form_field} {module_include location='shipping_configuration_create_form'} - + {/form} {/capture} {include @@ -97,7 +104,7 @@ dialog_ok_label = {intl l="Create this shipping configuration"} dialog_cancel_label = {intl l="Cancel"} - form_action = {url path='/admin/configuration/configuration/shipping_configuration/create'} + form_action = {url path='/admin/configuration/shipping_configuration/create'} form_enctype = '' form_error_message = $form_error_message }