remove area to area_delivery_module
This commit is contained in:
@@ -24,8 +24,10 @@
|
|||||||
namespace Thelia\Action;
|
namespace Thelia\Action;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
||||||
|
use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Model\AreaDeliveryModule;
|
use Thelia\Model\AreaDeliveryModule;
|
||||||
|
use Thelia\Model\AreaDeliveryModuleQuery;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +48,20 @@ class ShippingZone extends BaseAction implements EventSubscriberInterface
|
|||||||
->save();
|
->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.
|
* 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()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array(
|
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.admin.area.postage" class="Thelia\Form\Area\AreaPostageForm"/>
|
||||||
|
|
||||||
<form name="thelia.shopping_zone_area" class="Thelia\Form\ShippingZone\ShippingZoneAddArea"/>
|
<form name="thelia.shopping_zone_area" class="Thelia\Form\ShippingZone\ShippingZoneAddArea"/>
|
||||||
|
<form name="thelia.shopping_zone_remove_area" class="Thelia\Form\ShippingZone\ShippingZoneRemoveArea"/>
|
||||||
</forms>
|
</forms>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -683,10 +683,14 @@
|
|||||||
<requirement key="shipping_zones_id">\d+</requirement>
|
<requirement key="shipping_zones_id">\d+</requirement>
|
||||||
</route>
|
</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>
|
<default key="_controller">Thelia\Controller\Admin\ShippingZoneController::addArea</default>
|
||||||
</route>
|
</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 -->
|
<!-- end shipping routes management -->
|
||||||
|
|
||||||
<!-- Shipping zones routes management -->
|
<!-- Shipping zones routes management -->
|
||||||
|
|||||||
@@ -23,8 +23,11 @@
|
|||||||
|
|
||||||
namespace Thelia\Controller\Admin;
|
namespace Thelia\Controller\Admin;
|
||||||
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
||||||
|
use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Form\Exception\FormValidationException;
|
use Thelia\Form\Exception\FormValidationException;
|
||||||
|
use Thelia\Form\ShippingZone\ShippingZoneAddArea;
|
||||||
|
use Thelia\Form\ShippingZone\ShippingZoneRemoveArea;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ShippingZoneController
|
* Class ShippingZoneController
|
||||||
@@ -56,7 +59,7 @@ class ShippingZoneController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
|
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;
|
$error_msg = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -87,13 +90,48 @@ class ShippingZoneController extends BaseAdminController
|
|||||||
return $this->renderEditionTemplate();
|
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
|
* Render the edition template
|
||||||
*/
|
*/
|
||||||
protected function renderEditionTemplate()
|
protected function renderEditionTemplate()
|
||||||
{
|
{
|
||||||
return $this->render('admin.configuration.shipping-zones.update.view',array(
|
return $this->render("shipping-zones-edit", array(
|
||||||
'shipping_zones_id' => $this->getShippingZoneId()
|
"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
|
// -- SHIPPING ZONE MANAGEMENT
|
||||||
|
|
||||||
const SHIPPING_ZONE_ADD_AREA = 'action.shippingZone.addArea';
|
const SHIPPING_ZONE_ADD_AREA = 'action.shippingZone.addArea';
|
||||||
|
const SHIPPING_ZONE_REMOVE_AREA = 'action.shippingZone.removeArea';
|
||||||
|
|
||||||
// -- Categories Associated Content ----------------------------------------
|
// -- 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';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{$NAME}</td>
|
<td>{$NAME}</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-default btn-xs" title="{intl l='Delete this zone'}" href="#delete_zone_dialog" data-id="{$ID}" data-toggle="modal">
|
<a class="btn btn-default btn-xs delete-zone-area" title="{intl l='Delete this zone'}" href="#delete_zone_dialog" data-id="{$ID}" data-toggle="modal">
|
||||||
<span class="glyphicon glyphicon-trash"></span>
|
<span class="glyphicon glyphicon-trash"></span>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -91,7 +91,22 @@
|
|||||||
{* Delete related content confirmation dialog *}
|
{* Delete related content confirmation dialog *}
|
||||||
|
|
||||||
{capture "delete_zone_dialog"}
|
{capture "delete_zone_dialog"}
|
||||||
|
{form name="thelia.shopping_zone_remove_area"}
|
||||||
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
|
{form_field form=$form field='success_url'}
|
||||||
|
<input type="hidden" name="{$name}" value="{url path="/admin/configuration/shipping_zones/update/{$shipping_zones_id}"}" /> {* the url the user is redirected to on login success *}
|
||||||
|
{/form_field}
|
||||||
|
|
||||||
|
{form_field form=$form field='shipping_zone_id'}
|
||||||
|
<input type="hidden" name="{$name}" value="{$shipping_zones_id}" />
|
||||||
|
{/form_field}
|
||||||
|
|
||||||
|
{form_field form=$form field='area_id'}
|
||||||
|
<input type="hidden" name="{$name}" value="" id="shipping-zone-id-delete" />
|
||||||
|
{/form_field}
|
||||||
|
|
||||||
|
{/form}
|
||||||
{/capture}
|
{/capture}
|
||||||
|
|
||||||
{include
|
{include
|
||||||
@@ -101,7 +116,7 @@
|
|||||||
dialog_title = {intl l="Remove zone"}
|
dialog_title = {intl l="Remove zone"}
|
||||||
dialog_message = {intl l="Do you really want to remove this 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}
|
form_content = {$smarty.capture.delete_zone_dialog nofilter}
|
||||||
}
|
}
|
||||||
{/block}
|
{/block}
|
||||||
@@ -113,4 +128,12 @@
|
|||||||
{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'}
|
{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'}
|
||||||
<script src="{$asset_url}"></script>
|
<script src="{$asset_url}"></script>
|
||||||
{/javascripts}
|
{/javascripts}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$(".delete-zone-area").click(function(e){
|
||||||
|
$("#shipping-zone-id-delete").val($(this).data('id'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user