diff --git a/core/lib/Thelia/Action/ShippingZone.php b/core/lib/Thelia/Action/ShippingZone.php
index 9dfb53123..517a5ca25 100644
--- a/core/lib/Thelia/Action/ShippingZone.php
+++ b/core/lib/Thelia/Action/ShippingZone.php
@@ -24,8 +24,10 @@
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
+use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\AreaDeliveryModule;
+use Thelia\Model\AreaDeliveryModuleQuery;
/**
@@ -46,6 +48,20 @@ class ShippingZone extends BaseAction implements EventSubscriberInterface
->save();
}
+ public function removeArea(ShippingZoneRemoveAreaEvent $event)
+ {
+ $areaDelivery = AreaDeliveryModuleQuery::create()
+ ->filterByAreaId($event->getAreaId())
+ ->filterByDeliveryModuleId($event->getShoppingZoneId())
+ ->findOne();
+
+ if($areaDelivery) {
+ $areaDelivery->delete();
+ } else {
+ throw new \RuntimeException(sprintf('areaDeliveryModule not found with area_id = %d and delivery_module_id = %d', $event->getAreaId(), $event->getShoppingZoneId()));
+ }
+ }
+
/**
* Returns an array of event names this subscriber wants to listen to.
*
@@ -69,7 +85,8 @@ class ShippingZone extends BaseAction implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
- TheliaEvents::SHIPPING_ZONE_ADD_AREA => array('addArea', 128)
+ TheliaEvents::SHIPPING_ZONE_ADD_AREA => array('addArea', 128),
+ TheliaEvents::SHIPPING_ZONE_REMOVE_AREA => array('removeArea', 128),
);
}
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml
index ae6849a34..f8122dcba 100755
--- a/core/lib/Thelia/Config/Resources/config.xml
+++ b/core/lib/Thelia/Config/Resources/config.xml
@@ -131,6 +131,7 @@
+
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 6daefead9..9bb2f08b9 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -683,10 +683,14 @@
\d+
-
+
Thelia\Controller\Admin\ShippingZoneController::addArea
+
+ Thelia\Controller\Admin\ShippingZoneController::removeArea
+
+
diff --git a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php
index 8f1117d70..d68de4808 100644
--- a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php
+++ b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php
@@ -23,8 +23,11 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
+use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\Exception\FormValidationException;
+use Thelia\Form\ShippingZone\ShippingZoneAddArea;
+use Thelia\Form\ShippingZone\ShippingZoneRemoveArea;
/**
* Class ShippingZoneController
@@ -56,7 +59,7 @@ class ShippingZoneController extends BaseAdminController
{
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
- $shippingAreaForm = new \Thelia\Form\ShippingZone\ShippingZoneAddArea($this->getRequest());
+ $shippingAreaForm = new ShippingZoneAddArea($this->getRequest());
$error_msg = null;
try {
@@ -87,13 +90,48 @@ class ShippingZoneController extends BaseAdminController
return $this->renderEditionTemplate();
}
+ public function removeArea()
+ {
+ if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
+
+ $shippingAreaForm = new ShippingZoneRemoveArea($this->getRequest());
+ $error_msg = null;
+
+ try {
+ $form = $this->validateForm($shippingAreaForm);
+
+ $event = new ShippingZoneRemoveAreaEvent(
+ $form->get('area_id')->getData(),
+ $form->get('shipping_zone_id')->getData()
+ );
+
+ $this->dispatch(TheliaEvents::SHIPPING_ZONE_REMOVE_AREA, $event);
+
+ // Redirect to the success URL
+ $this->redirect($shippingAreaForm->getSuccessUrl());
+
+ } catch (FormValidationException $ex) {
+ // Form cannot be validated
+ $error_msg = $this->createStandardFormValidationErrorMessage($ex);
+ } catch (\Exception $ex) {
+ // Any other error
+ $error_msg = $ex->getMessage();
+ }
+
+ $this->setupFormErrorContext(
+ $this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $shippingAreaForm);
+
+ // At this point, the form has errors, and should be redisplayed.
+ return $this->renderEditionTemplate();
+ }
+
/**
* Render the edition template
*/
protected function renderEditionTemplate()
{
- return $this->render('admin.configuration.shipping-zones.update.view',array(
- 'shipping_zones_id' => $this->getShippingZoneId()
+ return $this->render("shipping-zones-edit", array(
+ "shipping_zones_id" => $this->getShippingZoneId()
));
}
diff --git a/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php
new file mode 100644
index 000000000..6dc6094d6
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php
@@ -0,0 +1,35 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event\ShippingZone;
+
+
+/**
+ * Class ShippingZoneRemoveAreaEvent
+ * @package Thelia\Core\Event\ShippingZone
+ * @author Manuel Raynaud
+ */
+class ShippingZoneRemoveAreaEvent extends ShippingZoneAddAreaEvent
+{
+
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index aeade5ea8..aa365e54a 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -254,6 +254,7 @@ final class TheliaEvents
// -- SHIPPING ZONE MANAGEMENT
const SHIPPING_ZONE_ADD_AREA = 'action.shippingZone.addArea';
+ const SHIPPING_ZONE_REMOVE_AREA = 'action.shippingZone.removeArea';
// -- Categories Associated Content ----------------------------------------
diff --git a/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php b/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php
new file mode 100644
index 000000000..5c4e5597b
--- /dev/null
+++ b/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php
@@ -0,0 +1,42 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Form\ShippingZone;
+
+
+/**
+ * Class ShippingZoneRemoveArea
+ * @package Thelia\Form\ShippingZone
+ * @author Manuel Raynaud
+ */
+class ShippingZoneRemoveArea extends ShippingZoneAddArea
+{
+
+ /**
+ * @return string the name of you form. This name must be unique
+ */
+ public function getName()
+ {
+ return 'thelia_shippingzone_remove_area';
+ }
+}
\ No newline at end of file
diff --git a/templates/admin/default/shipping-zones-edit.html b/templates/admin/default/shipping-zones-edit.html
index 257b3de9c..139e3d164 100644
--- a/templates/admin/default/shipping-zones-edit.html
+++ b/templates/admin/default/shipping-zones-edit.html
@@ -69,7 +69,7 @@
| {$NAME} |
-
+
|
@@ -91,7 +91,22 @@
{* Delete related content confirmation dialog *}
{capture "delete_zone_dialog"}
-
+ {form name="thelia.shopping_zone_remove_area"}
+ {form_hidden_fields form=$form}
+
+ {form_field form=$form field='success_url'}
+ {* the url the user is redirected to on login success *}
+ {/form_field}
+
+ {form_field form=$form field='shipping_zone_id'}
+
+ {/form_field}
+
+ {form_field form=$form field='area_id'}
+
+ {/form_field}
+
+ {/form}
{/capture}
{include
@@ -101,7 +116,7 @@
dialog_title = {intl l="Remove zone"}
dialog_message = {intl l="Do you really want to remove this zone ?"}
- form_action = {url path=''}
+ form_action = {url path='/admin/configuration/shipping_zones/area/remove'}
form_content = {$smarty.capture.delete_zone_dialog nofilter}
}
{/block}
@@ -113,4 +128,12 @@
{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'}
{/javascripts}
+
+
{/block}
\ No newline at end of file