remove area to area_delivery_module
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,7 @@
|
||||
<form name="thelia.admin.area.postage" class="Thelia\Form\Area\AreaPostageForm"/>
|
||||
|
||||
<form name="thelia.shopping_zone_area" class="Thelia\Form\ShippingZone\ShippingZoneAddArea"/>
|
||||
<form name="thelia.shopping_zone_remove_area" class="Thelia\Form\ShippingZone\ShippingZoneRemoveArea"/>
|
||||
</forms>
|
||||
|
||||
|
||||
|
||||
@@ -683,10 +683,14 @@
|
||||
<requirement key="shipping_zones_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.shipping-zones.area.add" path="/admin/configuration/shipping_zones/area/add">
|
||||
<route id="admin.configuration.shipping-zones.area.add" path="/admin/configuration/shipping_zones/area/add" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ShippingZoneController::addArea</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.shipping-zones.area.remove" path="/admin/configuration/shipping_zones/area/remove">
|
||||
<default key="_controller">Thelia\Controller\Admin\ShippingZoneController::removeArea</default>
|
||||
</route>
|
||||
|
||||
<!-- end shipping routes management -->
|
||||
|
||||
<!-- Shipping zones routes management -->
|
||||
|
||||
@@ -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()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\ShippingZone;
|
||||
|
||||
|
||||
/**
|
||||
* Class ShippingZoneRemoveAreaEvent
|
||||
* @package Thelia\Core\Event\ShippingZone
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingZoneRemoveAreaEvent extends ShippingZoneAddAreaEvent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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 ----------------------------------------
|
||||
|
||||
|
||||
42
core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php
Normal file
42
core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Form\ShippingZone;
|
||||
|
||||
|
||||
/**
|
||||
* Class ShippingZoneRemoveArea
|
||||
* @package Thelia\Form\ShippingZone
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingZoneRemoveArea extends ShippingZoneAddArea
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_shippingzone_remove_area';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user