add an area to a delivery module
This commit is contained in:
75
core/lib/Thelia/Action/ShippingZone.php
Normal file
75
core/lib/Thelia/Action/ShippingZone.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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\Action;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\AreaDeliveryModule;
|
||||
|
||||
|
||||
/**
|
||||
* Class ShippingZone
|
||||
* @package Thelia\Action
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingZone extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
public function addArea(ShippingZoneAddAreaEvent $event)
|
||||
{
|
||||
$areaDelivery = new AreaDeliveryModule();
|
||||
|
||||
$areaDelivery
|
||||
->setAreaId($event->getAreaId())
|
||||
->setDeliveryModuleId($event->getShoppingZoneId())
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::SHIPPING_ZONE_ADD_AREA => array('addArea', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,11 @@
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.shippingZone" class="Thelia\Action\ShippingZone">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
</services>
|
||||
|
||||
</config>
|
||||
|
||||
@@ -683,6 +683,10 @@
|
||||
<requirement key="shipping_zones_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.shipping-zones.area.add" path="/admin/configuration/shipping_zones/area/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\ShippingZoneController::addArea</default>
|
||||
</route>
|
||||
|
||||
<!-- end shipping routes management -->
|
||||
|
||||
<!-- Shipping zones routes management -->
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
|
||||
/**
|
||||
* Class ShippingZoneController
|
||||
@@ -30,6 +33,8 @@ namespace Thelia\Controller\Admin;
|
||||
*/
|
||||
class ShippingZoneController extends BaseAdminController
|
||||
{
|
||||
public $objectName = 'areaDeliveryModule';
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
|
||||
@@ -38,10 +43,64 @@ class ShippingZoneController extends BaseAdminController
|
||||
|
||||
public function updateAction($shipping_zones_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
|
||||
return $this->render("shipping-zones-edit", array(
|
||||
"shipping_zones_id" => $shipping_zones_id
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function addArea()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
|
||||
|
||||
$shippingAreaForm = new \Thelia\Form\ShippingZone\ShippingZoneAddArea($this->getRequest());
|
||||
$error_msg = null;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($shippingAreaForm);
|
||||
|
||||
$event = new ShippingZoneAddAreaEvent(
|
||||
$form->get('area_id')->getData(),
|
||||
$form->get('shipping_zone_id')->getData()
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::SHIPPING_ZONE_ADD_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()
|
||||
));
|
||||
}
|
||||
|
||||
protected function getShippingZoneId()
|
||||
{
|
||||
return $this->getRequest()->get('shipping_zone_id', 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?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;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Class ShippingZoneAddAreaEvent
|
||||
* @package Thelia\Core\Event\ShippingZone
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingZoneAddAreaEvent extends ActionEvent
|
||||
{
|
||||
protected $area_id;
|
||||
protected $shopping_zone_id;
|
||||
|
||||
function __construct($area_id, $shopping_zone_id)
|
||||
{
|
||||
$this->area_id = $area_id;
|
||||
$this->shopping_zone_id = $shopping_zone_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $area_id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAreaId($area_id)
|
||||
{
|
||||
$this->area_id = $area_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAreaId()
|
||||
{
|
||||
return $this->area_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $shopping_zone_id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setShoppingZoneId($shopping_zone_id)
|
||||
{
|
||||
$this->shopping_zone_id = $shopping_zone_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getShoppingZoneId()
|
||||
{
|
||||
return $this->shopping_zone_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -232,7 +232,7 @@ final class TheliaEvents
|
||||
const BEFORE_UPDATECOUNTRY = "action.before_updateCountry";
|
||||
const AFTER_UPDATECOUNTRY = "action.after_updateCountry";
|
||||
|
||||
// -- SHIPPING CONFIGURATION MANAGEMENT
|
||||
// -- AREA CONFIGURATION MANAGEMENT
|
||||
|
||||
const AREA_CREATE = 'action.createArea';
|
||||
const AREA_UPDATE = 'action.updateArea';
|
||||
@@ -251,6 +251,10 @@ final class TheliaEvents
|
||||
const BEFORE_DELETEAREA = 'action.before_deleteArea';
|
||||
const AFTER_DELETEAREA = 'action.after_deleteArea';
|
||||
|
||||
// -- SHIPPING ZONE MANAGEMENT
|
||||
|
||||
const SHIPPING_ZONE_ADD_AREA = 'action.shippingZone.addArea';
|
||||
|
||||
// -- Categories Associated Content ----------------------------------------
|
||||
|
||||
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
<div class="form-container clearfix">
|
||||
<div class="col-md-4">
|
||||
{form name="thelia.shopping_zone_area"}
|
||||
<form method="POST" action="">
|
||||
<form method="POST" action="{url path="/admin/configuration/shipping_zones/area/add"}">
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{form_field form=$form field='success_url'}
|
||||
<input type="hidden" name="{$name}" value="{navigate to="return_to"}" /> {* the url the user is redirected to on login success *}
|
||||
<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'}
|
||||
|
||||
Reference in New Issue
Block a user