add country to as area
This commit is contained in:
78
core/lib/Thelia/Action/Area.php
Normal file
78
core/lib/Thelia/Action/Area.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?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\Area\AreaAddCountryEvent;
|
||||||
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
use Thelia\Model\AreaQuery;
|
||||||
|
use Thelia\Model\CountryQuery;
|
||||||
|
use Thelia\Action\BaseAction;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Area
|
||||||
|
* @package Thelia\Action
|
||||||
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class Area extends BaseAction implements EventSubscriberInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function addCountry(AreaAddCountryEvent $event)
|
||||||
|
{
|
||||||
|
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
|
||||||
|
$country->setAreaId($event->getAreaId())
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$event->setArea($country->getArea());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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::AREA_ADD_COUNTRY => array('addCountry', 128)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -126,6 +126,11 @@
|
|||||||
<tag name="kernel.event_subscriber"/>
|
<tag name="kernel.event_subscriber"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="thelia.action.area" class="Thelia\Action\Area">
|
||||||
|
<argument type="service" id="service_container"/>
|
||||||
|
<tag name="kernel.event_subscriber"/>
|
||||||
|
</service>
|
||||||
|
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -696,6 +696,10 @@
|
|||||||
<requirement key="area_id">\d+</requirement>
|
<requirement key="area_id">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
<route id="admin.configuration.shipping-configuration.country.add" path="/admin/configuration/shipping_configuration/country/add" methods="post">
|
||||||
|
<default key="_controller">Thelia\Controller\Admin\AreaController::addCountry</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
<!-- end shipping routes management -->
|
<!-- end shipping routes management -->
|
||||||
|
|
||||||
<!-- Countries routes management -->
|
<!-- Countries routes management -->
|
||||||
|
|||||||
@@ -23,12 +23,15 @@
|
|||||||
|
|
||||||
namespace Thelia\Controller\Admin;
|
namespace Thelia\Controller\Admin;
|
||||||
|
|
||||||
|
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
||||||
use Thelia\Core\Event\Area\AreaCreateEvent;
|
use Thelia\Core\Event\Area\AreaCreateEvent;
|
||||||
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
||||||
use Thelia\Core\Event\Area\AreaUpdateEvent;
|
use Thelia\Core\Event\Area\AreaUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
use Thelia\Form\Area\AreaCountryForm;
|
||||||
use Thelia\Form\Area\AreaCreateForm;
|
use Thelia\Form\Area\AreaCreateForm;
|
||||||
use Thelia\Form\Area\AreaModificationForm;
|
use Thelia\Form\Area\AreaModificationForm;
|
||||||
|
use Thelia\Form\Exception\FormValidationException;
|
||||||
use Thelia\Model\AreaQuery;
|
use Thelia\Model\AreaQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,4 +222,53 @@ class AreaController extends AbstractCrudController
|
|||||||
{
|
{
|
||||||
$this->redirectToRoute('admin.configuration.shipping-configuration.default');
|
$this->redirectToRoute('admin.configuration.shipping-configuration.default');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a country to a define area
|
||||||
|
*/
|
||||||
|
public function addCountry()
|
||||||
|
{
|
||||||
|
// Check current user authorization
|
||||||
|
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||||
|
|
||||||
|
$areaCountryForm = new AreaCountryForm($this->getRequest());
|
||||||
|
$error_msg = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
$form = $this->validateForm($areaCountryForm);
|
||||||
|
|
||||||
|
$event = new AreaAddCountryEvent($form->get('area_id')->getData(), $form->get('country_id')->getData());
|
||||||
|
|
||||||
|
$this->dispatch(TheliaEvents::AREA_ADD_COUNTRY, $event);
|
||||||
|
|
||||||
|
if (! $this->eventContainsObject($event))
|
||||||
|
throw new \LogicException(
|
||||||
|
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||||
|
|
||||||
|
// Log object modification
|
||||||
|
if (null !== $changedObject = $this->getObjectFromEvent($event)) {
|
||||||
|
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||||
|
$this->redirectToEditionTemplate($this->getRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect to the success URL
|
||||||
|
$this->redirect($areaCountryForm->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, $areaCountryForm);
|
||||||
|
|
||||||
|
// At this point, the form has errors, and should be redisplayed.
|
||||||
|
return $this->renderEditionTemplate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
86
core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php
Normal file
86
core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?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\Area;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AreaAddCountryEvent
|
||||||
|
* @package Thelia\Core\Event\Area
|
||||||
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class AreaAddCountryEvent extends AreaEvent
|
||||||
|
{
|
||||||
|
protected $area_id;
|
||||||
|
protected $country_id;
|
||||||
|
|
||||||
|
function __construct($area_id, $country_id)
|
||||||
|
{
|
||||||
|
$this->area_id = $area_id;
|
||||||
|
$this->country_id = $country_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 $country_id
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCountryId($country_id)
|
||||||
|
{
|
||||||
|
$this->country_id = $country_id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getCountryId()
|
||||||
|
{
|
||||||
|
return $this->country_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -237,6 +237,7 @@ final class TheliaEvents
|
|||||||
const AREA_CREATE = 'action.createArea';
|
const AREA_CREATE = 'action.createArea';
|
||||||
const AREA_UPDATE = 'action.updateArea';
|
const AREA_UPDATE = 'action.updateArea';
|
||||||
const AREA_DELETE = 'action.deleteArea';
|
const AREA_DELETE = 'action.deleteArea';
|
||||||
|
const AREA_ADD_COUNTRY = 'action.area.addCountry';
|
||||||
|
|
||||||
// -- Categories Associated Content ----------------------------------------
|
// -- Categories Associated Content ----------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
<div class="shipping-configuration edit-shipping-configuration">
|
<div class="shipping-configuration edit-shipping-configuration">
|
||||||
|
|
||||||
<div id="wrapper" class="container">
|
<div id="wrapper" class="container">
|
||||||
|
{loop name="area-edit" type="area" id=$area_id}
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
|
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
|
||||||
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
|
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
|
||||||
<li><a href="{url path='/admin/configuration/shipping_configuration'}">{intl l="Shipping configuration"}</a></li>
|
<li><a href="{url path='/admin/configuration/shipping_configuration'}">{intl l="Shipping configuration"}</a></li>
|
||||||
<li>{intl l='Editing shipping configuration "%name"' name="{$TITLE}"}</li>
|
<li>{intl l='Editing shipping configuration "%name"' name="{$NAME}"}</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<div class="general-block-decorator">
|
<div class="general-block-decorator">
|
||||||
|
|
||||||
<div class="col-md-12 title title-without-tabs">
|
<div class="col-md-12 title title-without-tabs">
|
||||||
{intl l='Edit shipping configuration %title' title=$TITLE}
|
{intl l='Edit shipping configuration %title' title=$NAME}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-container clearfix">
|
<div class="form-container clearfix">
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
|
|
||||||
{form name="thelia.admin.area.country"}
|
{form name="thelia.admin.area.country"}
|
||||||
<form method="POST" action="">
|
<form method="POST" action="{url path="/admin/configuration/shipping_configuration/country/add"}">
|
||||||
{form_hidden_fields form=$form}
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
{form_field form=$form field='success_url'}
|
{form_field form=$form field='success_url'}
|
||||||
@@ -102,7 +102,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/loop}
|
||||||
|
|
||||||
|
{elseloop rel="area-edit"}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{intl l="No area defined with this id"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/elseloop}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user