From 6bfca2c6b4a7f1119e87a563cfe5bf2766e28299 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 10 Oct 2013 14:20:53 +0200 Subject: [PATCH 01/20] allow country update --- core/lib/Thelia/Action/Country.php | 12 +++ .../Thelia/Config/Resources/routing/admin.xml | 7 +- .../Controller/Admin/BaseAdminController.php | 2 +- .../Controller/Admin/CountryController.php | 9 +- .../Core/Event/Country/CountryUpdateEvent.php | 85 +++++++++++++++++++ .../Form/Image/DocumentModification.php | 12 +-- .../Thelia/Form/Image/ImageModification.php | 12 +-- templates/admin/default/countries.html | 4 +- templates/admin/default/country-edit.html | 71 ++++++---------- 9 files changed, 140 insertions(+), 74 deletions(-) diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index 9bccfcea5..69bf3c568 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -59,7 +59,19 @@ class Country extends BaseAction implements EventSubscriberInterface public function update(CountryUpdateEvent $event) { + if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country + ->setIsocode($event->getIsocode()) + ->setIsoalpha2($event->getIsoAlpha2()) + ->setIsoalpha3($event->getIsoAlpha3()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setChapo($event->getChapo()) + ->setDescription($event->getDescription()) + ->save(); + $event->setCountry($country); + } } public function delete(CountryDeleteEvent $event) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 5df02e5bd..b2292b334 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -420,11 +420,16 @@ \d+ + + Thelia\Controller\Admin\CountryController::processUpdateAction + \d+ + + Thelia\Controller\Admin\CountryController::deleteAction - + Thelia\Controller\Admin\CountryController::toggleDefaultAction diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 5d99a877b..9adb7a19a 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -246,7 +246,7 @@ class BaseAdminController extends BaseController * @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml * @param unknown $urlParameters the URL parametrs, as a var/value pair array */ - public function redirectToRoute($routeId, $urlParameters = array(), $routeParameters = array()) + public function redirectToRoute($routeId, array $urlParameters = array(), array $routeParameters = array()) { $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, $routeParameters), $urlParameters)); } diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index a272f7364..c97a4c5ee 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -129,7 +129,7 @@ class CountryController extends AbstractCrudController */ protected function getUpdateEvent($formData) { - $event = new CountryUpdateEvent(); + $event = new CountryUpdateEvent($formData['id']); return $this->hydrateEvent($event, $formData); } @@ -139,6 +139,8 @@ class CountryController extends AbstractCrudController $event ->setLocale($formData['locale']) ->setTitle($formData['title']) + ->setChapo($formData['chapo']) + ->setDescription($formData['description']) ->setIsocode($formData['isocode']) ->setIsoAlpha2($formData['isoalpha2']) ->setIsoAlpha3($formData['isoalpha3']) @@ -236,7 +238,10 @@ class CountryController extends AbstractCrudController */ protected function redirectToEditionTemplate() { - $this->redirectToRoute('admin.configuration.countries.update', array(), $this->getRequest()->get('country_id', 0)); + $this->redirectToRoute('admin.configuration.countries.update', array(), array( + "country_id" => $this->getRequest()->get('country_id', 0) + ) + ); } /** diff --git a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php index 5c4ad1cf3..496904172 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php @@ -31,5 +31,90 @@ namespace Thelia\Core\Event\Country; */ class CountryUpdateEvent extends CountryCreateEvent { + protected $country_id; + + protected $chapo; + protected $description; + protected $postscriptum; + + function __construct($country_id) + { + $this->country_id = $country_id; + } + + /** + * @param mixed $chapo + */ + public function setChapo($chapo) + { + $this->chapo = $chapo; + + return $this; + } + + /** + * @return mixed + */ + public function getChapo() + { + return $this->chapo; + } + + /** + * @param mixed $description + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return mixed + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param mixed $postscriptum + */ + public function setPostscriptum($postscriptum) + { + $this->postscriptum = $postscriptum; + + return $this; + } + + /** + * @return mixed + */ + public function getPostscriptum() + { + return $this->postscriptum; + } + + /** + * @param mixed $country_id + */ + public function setCountryId($country_id) + { + $this->country_id = $country_id; + + return $this; + } + + /** + * @return mixed + */ + public function getCountryId() + { + return $this->country_id; + } + + + } \ No newline at end of file diff --git a/core/lib/Thelia/Form/Image/DocumentModification.php b/core/lib/Thelia/Form/Image/DocumentModification.php index 31de5af98..dbb85f5b3 100644 --- a/core/lib/Thelia/Form/Image/DocumentModification.php +++ b/core/lib/Thelia/Form/Image/DocumentModification.php @@ -122,16 +122,6 @@ abstract class DocumentModification extends BaseForm ) ) ) - ->add( - 'postscriptum', - 'text', - array( - 'constraints' => array(), - 'label' => Translator::getInstance()->trans('Post Scriptum'), - 'label_attr' => array( - 'for' => 'postscriptum' - ) - ) - ); + ; } } diff --git a/core/lib/Thelia/Form/Image/ImageModification.php b/core/lib/Thelia/Form/Image/ImageModification.php index e95a39c37..368f82410 100644 --- a/core/lib/Thelia/Form/Image/ImageModification.php +++ b/core/lib/Thelia/Form/Image/ImageModification.php @@ -130,16 +130,6 @@ abstract class ImageModification extends BaseForm ) ) ) - ->add( - 'postscriptum', - 'text', - array( - 'constraints' => array(), - 'label' => Translator::getInstance()->trans('Post Scriptum'), - 'label_attr' => array( - 'for' => 'postscriptum' - ) - ) - ); + ; } } diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index 6de45aa38..48dda2c4d 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -58,11 +58,11 @@ - +{*
- + *} {$ISOCODE} {$ISOALPHA3} diff --git a/templates/admin/default/country-edit.html b/templates/admin/default/country-edit.html index b5d68e46b..447a6b355 100644 --- a/templates/admin/default/country-edit.html +++ b/templates/admin/default/country-edit.html @@ -30,8 +30,8 @@
{form name="thelia.admin.country.modification"} -
- + + {include file = "includes/inner-form-toolbar.html"}
{* Be sure to get the country ID, even if the form could not be validated *} @@ -40,8 +40,12 @@ {form_hidden_fields form=$form} {form_field form=$form field='success_url'} - - {/form_field} + + {/form_field} + + {form_field form=$form field='locale'} + + {/form_field} {if $form_error}
{$form_error_message}
{/if} @@ -74,51 +78,26 @@
{/form_field} -
- -
- {intl l="Translations"} -
- {loop type="lang" name="lang"} -
-
-
-

- {intl l=$TITLE} {$TITLE} -

-
-
- {form_field form=$form field='title'} -
- - -
- {/form_field} - {form_field form=$form field='chapo'} -
- - -
- {/form_field} - {form_field form=$form field='description'} -
- - -
- {/form_field} -
+ {form_field form=$form field='title'} +
+ +
-
- {/loop} - -
- + {/form_field} + {form_field form=$form field='chapo'} +
+ + +
+ {/form_field} + {form_field form=$form field='description'} +
+ + +
+ {/form_field}
-
{/form} From 8856cec55c7e9ca9840d97584e855db651b32797 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 10 Oct 2013 16:18:51 +0200 Subject: [PATCH 02/20] create area loop and shipping conf events name --- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Thelia/Config/Resources/routing/admin.xml | 59 +++---- .../Admin/ShippingConfigurationController.php | 159 +++++++++++++++++- core/lib/Thelia/Core/Event/TheliaEvents.php | 6 + core/lib/Thelia/Core/Template/Loop/Area.php | 124 ++++++++++++++ templates/admin/default/countries.html | 2 +- .../admin/default/shipping-configuration.html | 64 ++----- 7 files changed, 330 insertions(+), 85 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Loop/Area.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index d4d63ac77..ba530611c 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -7,6 +7,7 @@ + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index b2292b334..cfdce8aeb 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -405,34 +405,6 @@ Thelia\Controller\Admin\FolderController::updatePositionAction - - - - Thelia\Controller\Admin\CountryController::defaultAction - - - - Thelia\Controller\Admin\CountryController::createAction - - - - Thelia\Controller\Admin\CountryController::updateAction - \d+ - - - - Thelia\Controller\Admin\CountryController::processUpdateAction - \d+ - - - - Thelia\Controller\Admin\CountryController::deleteAction - - - - Thelia\Controller\Admin\CountryController::toggleDefaultAction - - Thelia\Controller\Admin\ContentController::createAction @@ -716,7 +688,7 @@ - Thelia\Controller\Admin\ShippingConfigurationController::indexAction + Thelia\Controller\Admin\ShippingConfigurationController::defaultAction @@ -726,6 +698,35 @@ + + + + Thelia\Controller\Admin\CountryController::defaultAction + + + + Thelia\Controller\Admin\CountryController::createAction + + + + Thelia\Controller\Admin\CountryController::updateAction + \d+ + + + + Thelia\Controller\Admin\CountryController::processUpdateAction + \d+ + + + + Thelia\Controller\Admin\CountryController::deleteAction + + + + Thelia\Controller\Admin\CountryController::toggleDefaultAction + + + diff --git a/core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php b/core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php index 92b73a83e..3ca6fec35 100644 --- a/core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php +++ b/core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php @@ -22,15 +22,16 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\TheliaEvents; /** * Class ShippingConfigurationController * @package Thelia\Controller\Admin * @author Manuel Raynaud */ -class ShippingConfigurationController extends BaseAdminController +class ShippingConfigurationController extends AbstractCrudController { - public function indexAction() +/* public function indexAction() { if (null !== $response = $this->checkAuth("admin.shipping-configuration.view")) return $response; return $this->render("shipping-configuration", array("display_shipping_configuration" => 20)); @@ -41,5 +42,159 @@ class ShippingConfigurationController extends BaseAdminController return $this->render("shipping-configuration-edit", array( "shipping_configuration_id" => $shipping_configuration_id )); + }*/ + + public function __construct() + { + parent::__construct( + 'area', + null, + null, + + 'admin.shipping.default', + 'admin.shipping.create', + 'admin.shipping.update', + 'admin.shipping.delete', + + TheliaEvents::SHIPPING_CREATE, + TheliaEvents::SHIPPING_UPDATE, + TheliaEvents::SHIPPING_DELETE + ); + } + + /** + * Return the creation form for this object + */ + protected function getCreationForm() + { + // TODO: Implement getCreationForm() method. + } + + /** + * Return the update form for this object + */ + protected function getUpdateForm() + { + // TODO: Implement getUpdateForm() method. + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param unknown $object + */ + protected function hydrateObjectForm($object) + { + // TODO: Implement hydrateObjectForm() method. + } + + /** + * Creates the creation event with the provided form data + * + * @param unknown $formData + */ + protected function getCreationEvent($formData) + { + // TODO: Implement getCreationEvent() method. + } + + /** + * Creates the update event with the provided form data + * + * @param unknown $formData + */ + protected function getUpdateEvent($formData) + { + // TODO: Implement getUpdateEvent() method. + } + + /** + * Creates the delete event with the provided form data + */ + protected function getDeleteEvent() + { + // TODO: Implement getDeleteEvent() method. + } + + /** + * Return true if the event contains the object, e.g. the action has updated the object in the event. + * + * @param unknown $event + */ + protected function eventContainsObject($event) + { + // TODO: Implement eventContainsObject() method. + } + + /** + * Get the created object from an event. + * + * @param unknown $createEvent + */ + protected function getObjectFromEvent($event) + { + // TODO: Implement getObjectFromEvent() method. + } + + /** + * Load an existing object from the database + */ + protected function getExistingObject() + { + // TODO: Implement getExistingObject() method. + } + + /** + * Returns the object label form the object event (name, title, etc.) + * + * @param unknown $object + */ + protected function getObjectLabel($object) + { + // TODO: Implement getObjectLabel() method. + } + + /** + * Returns the object ID from the object + * + * @param unknown $object + */ + protected function getObjectId($object) + { + // TODO: Implement getObjectId() method. + } + + /** + * Render the main list template + * + * @param unknown $currentOrder, if any, null otherwise. + */ + protected function renderListTemplate($currentOrder) + { + return $this->render("shipping-configuration"); + } + + /** + * Render the edition template + */ + protected function renderEditionTemplate() + { + // TODO: Implement renderEditionTemplate() method. + } + + /** + * Redirect to the edition template + */ + protected function redirectToEditionTemplate() + { + // TODO: Implement redirectToEditionTemplate() method. + } + + /** + * Redirect to the list template + */ + protected function redirectToListTemplate() + { + return $this->render("shipping-configuration"); } } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 4e4f55ba8..515ed8a25 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -232,6 +232,12 @@ final class TheliaEvents const BEFORE_UPDATECOUNTRY = "action.before_updateCountry"; const AFTER_UPDATECOUNTRY = "action.after_updateCountry"; + // -- SHIPPING CONFIGURATION MANAGEMENT + + const SHIPPING_CREATE = 'action.createShipping'; + const SHIPPING_UPDATE = 'action.updateShipping'; + const SHIPPING_DELETE = 'action.deleteShipping'; + // -- Categories Associated Content ---------------------------------------- const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent"; diff --git a/core/lib/Thelia/Core/Template/Loop/Area.php b/core/lib/Thelia/Core/Template/Loop/Area.php new file mode 100644 index 000000000..48baf2fbb --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Area.php @@ -0,0 +1,124 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Core\Template\Element\BaseLoop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\AreaQuery; + + +/** + * Class Area + * @package Thelia\Core\Template\Loop + * @author Manuel Raynaud + */ +class Area extends BaseLoop +{ + public $timestampable = true; + + /** + * + * define all args used in your loop + * + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * Argument::createBooleanTypeArgument('promo'), + * Argument::createFloatTypeArgument('min_price'), + * Argument::createFloatTypeArgument('max_price'), + * Argument::createIntTypeArgument('min_stock'), + * Argument::createFloatTypeArgument('min_weight'), + * Argument::createFloatTypeArgument('max_weight'), + * Argument::createBooleanTypeArgument('current'), + * + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id') + ); + } + + /** + * + * this function have to be implement in your own loop class. + * + * All loops parameters can be accessible via getter. + * + * for example, ref parameter is accessible through getRef method + * + * @param $pagination + * + * @return mixed + */ + public function exec(&$pagination) + { + $id = $this->getId(); + + $search = AreaQuery::create(); + + if ($id) { + $search->filterById($id, Criteria::IN); + } + + $areas = $this->search($search, $pagination); + + $loopResult = new LoopResult($areas); + + foreach ($areas as $area) { + $loopResultRow = new LoopResultRow($loopResult, $area, $this->versionable, $this->timestampable, $this->countable); + + $loopResultRow + ->set('ID', $area->getId()) + ->set('NAME', $area->getName()) + ->set('POSTAGE', $area->getPostage()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } + + +} \ No newline at end of file diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index 48dda2c4d..6791131df 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -52,7 +52,7 @@ {loop name="countries" type="country" backend_context="1" lang=$lang_id order=$order} {$ID} - {$TITLE} + {$TITLE}
diff --git a/templates/admin/default/shipping-configuration.html b/templates/admin/default/shipping-configuration.html index 067256d5f..7cd88bb1d 100644 --- a/templates/admin/default/shipping-configuration.html +++ b/templates/admin/default/shipping-configuration.html @@ -41,66 +41,24 @@ + {loop name="area-list" type="area" backend_context="1"} - France + {$NAME} {module_include location='shipping_configuration_table_row'} - {if ! $SECURED} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-configuration.change"} - - {/loop} - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.shipping-configuration.delete"} - - {/loop} -
- {else} - - {/if} - - - - Outre-Mer DOM - - {module_include location='shipping_configuration_table_row'} - - - {if ! $SECURED} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-configuration.change"} - - {/loop} - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.shipping-configuration.delete"} - - {/loop} -
- {else} - - {/if} - - - - Outre-Mer TOM - - {module_include location='shipping_configuration_table_row'} - - - {if ! $SECURED} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-configuration.change"} - - {/loop} - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.shipping-configuration.delete"} - - {/loop} -
- {else} - - {/if} +
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-configuration.change"} + + {/loop} + {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.shipping-configuration.delete"} + + {/loop} +
+ {/loop}
From 23f9301279044ed15ad0d76811ca111800828d66 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 10 Oct 2013 16:26:26 +0200 Subject: [PATCH 03/20] create shipping create and modify forms --- .../Form/Shipping/ShippingCreateForm.php | 79 +++++++++++++++++++ .../Shipping/ShippingModificationForm.php | 48 +++++++++++ 2 files changed, 127 insertions(+) create mode 100644 core/lib/Thelia/Form/Shipping/ShippingCreateForm.php create mode 100644 core/lib/Thelia/Form/Shipping/ShippingModificationForm.php diff --git a/core/lib/Thelia/Form/Shipping/ShippingCreateForm.php b/core/lib/Thelia/Form/Shipping/ShippingCreateForm.php new file mode 100644 index 000000000..674777112 --- /dev/null +++ b/core/lib/Thelia/Form/Shipping/ShippingCreateForm.php @@ -0,0 +1,79 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\Shipping; +use Thelia\Core\Translation\Translator; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Form\BaseForm; + + +/** + * Class ShippingCreateForm + * @package Thelia\Form\Shipping + * @author Manuel Raynaud + */ +class ShippingCreateForm extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add('name', 'text', array( + 'constraints' => array( + new NotBlank() + ), + 'label_attr' => array('for' => 'shipping_name'), + 'label' => Translator::getInstance()->trans('shipping area name') + )) + + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia_shipping_creation'; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/Shipping/ShippingModificationForm.php b/core/lib/Thelia/Form/Shipping/ShippingModificationForm.php new file mode 100644 index 000000000..018e44907 --- /dev/null +++ b/core/lib/Thelia/Form/Shipping/ShippingModificationForm.php @@ -0,0 +1,48 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\Shipping; +use Symfony\Component\Validator\Constraints\GreaterThan; + + +/** + * Class ShippingModificationForm + * @package Thelia\Form\Shipping + * @author Manuel Raynaud + */ +class ShippingModificationForm extends ShippingCreateForm +{ + public function buildForm() + { + parent::buildForm(); + + $this->formBuilder + ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) + ; + } + + public function getName() + { + return 'thelia_shipping_modification'; + } +} \ No newline at end of file From 9d6df61296509b6ef700337f184ffd27253bb80b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 10 Oct 2013 16:36:59 +0200 Subject: [PATCH 04/20] create form tag for shipping forms --- core/lib/Thelia/Config/Resources/config.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index ba530611c..54fd85794 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -120,6 +120,9 @@
+ + + From 560b80c18285dcd6b293bb02730a0d2a988794fe Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 10 Oct 2013 17:18:38 +0200 Subject: [PATCH 05/20] refactor shipping object into area --- core/lib/Thelia/Config/Resources/config.xml | 4 +- .../Thelia/Config/Resources/routing/admin.xml | 4 +- ...ationController.php => AreaController.php} | 18 ++--- core/lib/Thelia/Core/Event/Area/AreaEvent.php | 66 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 6 +- .../AreaCreateForm.php} | 8 +-- .../AreaModificationForm.php} | 9 +-- 7 files changed, 91 insertions(+), 24 deletions(-) rename core/lib/Thelia/Controller/Admin/{ShippingConfigurationController.php => AreaController.php} (93%) create mode 100644 core/lib/Thelia/Core/Event/Area/AreaEvent.php rename core/lib/Thelia/Form/{Shipping/ShippingCreateForm.php => Area/AreaCreateForm.php} (95%) rename core/lib/Thelia/Form/{Shipping/ShippingModificationForm.php => Area/AreaModificationForm.php} (92%) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 54fd85794..a154db798 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -120,8 +120,8 @@ - - + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index cfdce8aeb..04c106684 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -688,11 +688,11 @@ - Thelia\Controller\Admin\ShippingConfigurationController::defaultAction + Thelia\Controller\Admin\AreaController::defaultAction - Thelia\Controller\Admin\ShippingConfigurationController::updateAction + Thelia\Controller\Admin\AreaController::updateAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php b/core/lib/Thelia/Controller/Admin/AreaController.php similarity index 93% rename from core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php rename to core/lib/Thelia/Controller/Admin/AreaController.php index 3ca6fec35..12958b4ff 100644 --- a/core/lib/Thelia/Controller/Admin/ShippingConfigurationController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -25,11 +25,11 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\TheliaEvents; /** - * Class ShippingConfigurationController + * Class AreaController * @package Thelia\Controller\Admin * @author Manuel Raynaud */ -class ShippingConfigurationController extends AbstractCrudController +class AreaController extends AbstractCrudController { /* public function indexAction() { @@ -51,14 +51,14 @@ class ShippingConfigurationController extends AbstractCrudController null, null, - 'admin.shipping.default', - 'admin.shipping.create', - 'admin.shipping.update', - 'admin.shipping.delete', + 'admin.area.default', + 'admin.area.create', + 'admin.area.update', + 'admin.area.delete', - TheliaEvents::SHIPPING_CREATE, - TheliaEvents::SHIPPING_UPDATE, - TheliaEvents::SHIPPING_DELETE + TheliaEvents::AREA_CREATE, + TheliaEvents::AREA_UPDATE, + TheliaEvents::AREA_DELETE ); } diff --git a/core/lib/Thelia/Core/Event/Area/AreaEvent.php b/core/lib/Thelia/Core/Event/Area/AreaEvent.php new file mode 100644 index 000000000..892d00843 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaEvent.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; +use Thelia\Core\Event\ActionEvent; + + +/** + * Class AreaEvent + * @package Thelia\Core\Event\Shipping + * @author Manuel Raynaud + */ +class AreaEvent extends ActionEvent +{ + protected $area; + + public function __construct($area = null) + { + $this->area = $area; + } + + /** + * @param mixed $area + * + * @return $this + */ + public function setArea($area) + { + $this->area = $area; + + return $this; + } + + /** + * @return mixed + */ + public function getArea() + { + return $this->area; + } + + public function hasArea() + { + return null !== $this->area; + } +} \ 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 515ed8a25..9cc3beba9 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -234,9 +234,9 @@ final class TheliaEvents // -- SHIPPING CONFIGURATION MANAGEMENT - const SHIPPING_CREATE = 'action.createShipping'; - const SHIPPING_UPDATE = 'action.updateShipping'; - const SHIPPING_DELETE = 'action.deleteShipping'; + const AREA_CREATE = 'action.createArea'; + const AREA_UPDATE = 'action.updateArea'; + const AREA_DELETE = 'action.deleteArea'; // -- Categories Associated Content ---------------------------------------- diff --git a/core/lib/Thelia/Form/Shipping/ShippingCreateForm.php b/core/lib/Thelia/Form/Area/AreaCreateForm.php similarity index 95% rename from core/lib/Thelia/Form/Shipping/ShippingCreateForm.php rename to core/lib/Thelia/Form/Area/AreaCreateForm.php index 674777112..590001867 100644 --- a/core/lib/Thelia/Form/Shipping/ShippingCreateForm.php +++ b/core/lib/Thelia/Form/Area/AreaCreateForm.php @@ -21,18 +21,18 @@ /* */ /*************************************************************************************/ -namespace Thelia\Form\Shipping; +namespace Thelia\Form\Area; use Thelia\Core\Translation\Translator; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; /** - * Class ShippingCreateForm + * Class AreaCreateForm * @package Thelia\Form\Shipping * @author Manuel Raynaud */ -class ShippingCreateForm extends BaseForm +class AreaCreateForm extends BaseForm { /** @@ -74,6 +74,6 @@ class ShippingCreateForm extends BaseForm */ public function getName() { - return 'thelia_shipping_creation'; + return 'thelia_area_creation'; } } \ No newline at end of file diff --git a/core/lib/Thelia/Form/Shipping/ShippingModificationForm.php b/core/lib/Thelia/Form/Area/AreaModificationForm.php similarity index 92% rename from core/lib/Thelia/Form/Shipping/ShippingModificationForm.php rename to core/lib/Thelia/Form/Area/AreaModificationForm.php index 018e44907..eefcb825a 100644 --- a/core/lib/Thelia/Form/Shipping/ShippingModificationForm.php +++ b/core/lib/Thelia/Form/Area/AreaModificationForm.php @@ -21,16 +21,17 @@ /* */ /*************************************************************************************/ -namespace Thelia\Form\Shipping; +namespace Thelia\Form\Area; use Symfony\Component\Validator\Constraints\GreaterThan; +use Thelia\Form\Area\AreaCreateForm; /** - * Class ShippingModificationForm + * Class AreaModificationForm * @package Thelia\Form\Shipping * @author Manuel Raynaud */ -class ShippingModificationForm extends ShippingCreateForm +class AreaModificationForm extends AreaCreateForm { public function buildForm() { @@ -43,6 +44,6 @@ class ShippingModificationForm extends ShippingCreateForm public function getName() { - return 'thelia_shipping_modification'; + return 'thelia_area_modification'; } } \ No newline at end of file From 319bb2f0b84c6a1485cf5b0aad6f5166abf0af0d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 11 Oct 2013 12:06:17 +0200 Subject: [PATCH 06/20] create all area events --- .../Controller/Admin/AreaController.php | 24 +++++++-- .../Core/Event/Area/AreaCreateEvent.php | 53 +++++++++++++++++++ .../Core/Event/Area/AreaDeleteEvent.php | 40 ++++++++++++++ .../Core/Event/Area/AreaUpdateEvent.php | 35 ++++++++++++ 4 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php create mode 100644 core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php create mode 100644 core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 12958b4ff..ec8f2d2de 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -22,7 +22,10 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\Area\AreaCreateEvent; +use Thelia\Core\Event\Area\AreaUpdateEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\Area\AreaCreateForm; /** * Class AreaController @@ -67,7 +70,7 @@ class AreaController extends AbstractCrudController */ protected function getCreationForm() { - // TODO: Implement getCreationForm() method. + return new AreaCreateForm($this->getRequest()); } /** @@ -75,7 +78,7 @@ class AreaController extends AbstractCrudController */ protected function getUpdateForm() { - // TODO: Implement getUpdateForm() method. + return new AreaCreateForm($this->getRequest()); } /** @@ -92,10 +95,14 @@ class AreaController extends AbstractCrudController * Creates the creation event with the provided form data * * @param unknown $formData + * + * @return \Thelia\Core\Event\Area\AreaCreateEvent */ protected function getCreationEvent($formData) { - // TODO: Implement getCreationEvent() method. + $event = new AreaCreateEvent(); + + return $this->hydrateEvent($event, $formData); } /** @@ -105,7 +112,16 @@ class AreaController extends AbstractCrudController */ protected function getUpdateEvent($formData) { - // TODO: Implement getUpdateEvent() method. + $event = new AreaUpdateEvent(); + + return $this->hydrateEvent($event, $formData); + } + + private function hydrateEvent($event, $formData) + { + $event->setName($formData['name']); + + return $event; } /** diff --git a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php new file mode 100644 index 000000000..a06ef2bc3 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php @@ -0,0 +1,53 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; + + +/** + * Class AreaCreateEvent + * @package Thelia\Core\Event\Area + * @author Manuel Raynaud + */ +class AreaCreateEvent extends AreaEvent +{ + protected $name; + + /** + * @param mixed $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php b/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php new file mode 100644 index 000000000..fa996fa5e --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php @@ -0,0 +1,40 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; + + +/** + * Class AreaDeleteEvent + * @package Thelia\Core\Event\Area + * @author Manuel Raynaud + */ +class AreaDeleteEvent extends AreaEvent +{ + protected $area_id; + + public function __construct($area_id) + { + $this->area_id = $area_id; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php new file mode 100644 index 000000000..f5f7c8704 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; + + +/** + * Class AreaUpdateEvent + * @package Thelia\Core\Event\Area + * @author Manuel Raynaud + */ +class AreaUpdateEvent extends AreaCreateEvent +{ + +} \ No newline at end of file From 97ce036cbe1d862a23fb6907ba1f6ff5788821cf Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 11 Oct 2013 17:23:40 +0200 Subject: [PATCH 07/20] start area configuration tempalte --- core/lib/Thelia/Config/Resources/config.xml | 5 +- core/lib/Thelia/Form/Area/AreaCountryForm.php | 89 +++++++++++++++++++ templates/admin/default/category-edit.html | 2 +- .../default/shipping-configuration-edit.html | 50 +++++------ 4 files changed, 116 insertions(+), 30 deletions(-) create mode 100644 core/lib/Thelia/Form/Area/AreaCountryForm.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 34803ce31..aa8236000 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -125,8 +125,9 @@ - - + + + diff --git a/core/lib/Thelia/Form/Area/AreaCountryForm.php b/core/lib/Thelia/Form/Area/AreaCountryForm.php new file mode 100644 index 000000000..c511e0b3c --- /dev/null +++ b/core/lib/Thelia/Form/Area/AreaCountryForm.php @@ -0,0 +1,89 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\Area; + +use Thelia\Core\Translation\Translator; +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Form\BaseForm; + + +/** + * Class AreaCountryForm + * @package Thelia\Form\Area + * @author Manuel Raynaud + */ +class AreaCountryForm extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add('area_id', 'integer', array( + 'constraints' => array( + new GreaterThan(array('value' => 0)), + new NotBlank() + ) + + )) + ->add('country_id', 'integer', array( + 'constraints' => array( + new GreaterThan(array('value' => 0)), + new NotBlank() + ), + 'label_attr' => array( + 'for' => 'area_country' + ), + 'label' => Translator::getInstance()->trans('Country') + )); + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia_area_country'; + } +} \ No newline at end of file diff --git a/templates/admin/default/category-edit.html b/templates/admin/default/category-edit.html index f8b564822..78cb7b681 100755 --- a/templates/admin/default/category-edit.html +++ b/templates/admin/default/category-edit.html @@ -66,7 +66,7 @@ {form_hidden_fields form=$form} {form_field form=$form field='success_url'} - + {/form_field} {form_field form=$form field='locale'} diff --git a/templates/admin/default/shipping-configuration-edit.html b/templates/admin/default/shipping-configuration-edit.html index b17dc6de4..7bf8164f9 100644 --- a/templates/admin/default/shipping-configuration-edit.html +++ b/templates/admin/default/shipping-configuration-edit.html @@ -28,23 +28,33 @@
- + {form name="thelia.admin.area.country"} - + {form_hidden_fields form=$form} + + {form_field form=$form field='success_url'} + + {/form_field} + + {form_field form=$form field='area_id'} + + {/form_field} + {form_field form=$form field='country_id'} +
- + {loop name="country-without-area" type="country" with_area="0" backend_context="1" lang=$lang_id} + + {/loop}
- + {/form_field} - + {/form}
@@ -57,38 +67,24 @@ + {loop name="country-area" type="country" area=$area_id backend_context="1"} - Wallis-et-Futuna + {$TITLE} - - Polynésie française - - - - - - - - USA - Alabama - - - - - - + {/loop}
- +
- + From dfee7e87a6c5301d76666d0574163ef0e52e6d59 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 10:04:08 +0200 Subject: [PATCH 08/20] add country to as area --- core/lib/Thelia/Action/Area.php | 78 +++++++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 ++ .../Thelia/Config/Resources/routing/admin.xml | 4 + .../Controller/Admin/AreaController.php | 52 +++++++++++ .../Core/Event/Area/AreaAddCountryEvent.php | 86 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 1 + .../default/shipping-configuration-edit.html | 16 +++- 7 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 core/lib/Thelia/Action/Area.php create mode 100644 core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php new file mode 100644 index 000000000..14fcfa87b --- /dev/null +++ b/core/lib/Thelia/Action/Area.php @@ -0,0 +1,78 @@ +. */ +/* */ +/*************************************************************************************/ + +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 + */ +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) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 939cc9d88..4770ec377 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -126,6 +126,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 79165d2ac..1cb3486d8 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -696,6 +696,10 @@ \d+ + + Thelia\Controller\Admin\AreaController::addCountry + + diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 9ab31ac2f..46f90d40b 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -23,12 +23,15 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\Area\AreaAddCountryEvent; use Thelia\Core\Event\Area\AreaCreateEvent; use Thelia\Core\Event\Area\AreaDeleteEvent; use Thelia\Core\Event\Area\AreaUpdateEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\Area\AreaCountryForm; use Thelia\Form\Area\AreaCreateForm; use Thelia\Form\Area\AreaModificationForm; +use Thelia\Form\Exception\FormValidationException; use Thelia\Model\AreaQuery; /** @@ -219,4 +222,53 @@ class AreaController extends AbstractCrudController { $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(); + } } diff --git a/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php b/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php new file mode 100644 index 000000000..b6af3c5b3 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php @@ -0,0 +1,86 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; + + +/** + * Class AreaAddCountryEvent + * @package Thelia\Core\Event\Area + * @author Manuel Raynaud + */ +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; + } + + + + +} \ 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 36db1f699..8145a247f 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -237,6 +237,7 @@ final class TheliaEvents const AREA_CREATE = 'action.createArea'; const AREA_UPDATE = 'action.updateArea'; const AREA_DELETE = 'action.deleteArea'; + const AREA_ADD_COUNTRY = 'action.area.addCountry'; // -- Categories Associated Content ---------------------------------------- diff --git a/templates/admin/default/shipping-configuration-edit.html b/templates/admin/default/shipping-configuration-edit.html index 7bf8164f9..78dfe4e7c 100644 --- a/templates/admin/default/shipping-configuration-edit.html +++ b/templates/admin/default/shipping-configuration-edit.html @@ -8,12 +8,12 @@
- + {loop name="area-edit" type="area" id=$area_id}
@@ -21,7 +21,7 @@
- {intl l='Edit shipping configuration %title' title=$TITLE} + {intl l='Edit shipping configuration %title' title=$NAME}
@@ -29,7 +29,7 @@ {form name="thelia.admin.area.country"} - + {form_hidden_fields form=$form} {form_field form=$form field='success_url'} @@ -102,7 +102,15 @@
+ {/loop} + {elseloop rel="area-edit"} +
+
+ {intl l="No area defined with this id"} +
+
+ {/elseloop}
From b371f5c54c57dab7fa40929526892c828238301b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 11:03:13 +0200 Subject: [PATCH 09/20] remove country from area and start creating postage management --- core/lib/Thelia/Action/Area.php | 12 ++++++- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Thelia/Config/Resources/routing/admin.xml | 9 +++++ .../Controller/Admin/AreaController.php | 13 +++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 2 ++ .../default/shipping-configuration-edit.html | 34 +++++++++++++++---- 6 files changed, 64 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index 14fcfa87b..d3aa5bbc5 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -24,6 +24,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Area\AreaAddCountryEvent; +use Thelia\Core\Event\Area\AreaRemoveCountryEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\AreaQuery; use Thelia\Model\CountryQuery; @@ -48,6 +49,14 @@ class Area extends BaseAction implements EventSubscriberInterface } } + public function removeCountry(AreaRemoveCountryEvent $event) + { + if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country->setAreaId(null) + ->save(); + } + } + /** * Returns an array of event names this subscriber wants to listen to. @@ -72,7 +81,8 @@ class Area extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128) + TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128), + TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 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 aa8236000..aafaa85b7 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -128,6 +128,7 @@ + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 1cb3486d8..e69853d99 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -696,10 +696,19 @@ \d+ + + Thelia\Controller\Admin\AreaController::updatePostageAction + \d+ + + Thelia\Controller\Admin\AreaController::addCountry + + Thelia\Controller\Admin\AreaController::removeCountry + + diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 46f90d40b..62333fb7b 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -26,6 +26,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\Area\AreaAddCountryEvent; use Thelia\Core\Event\Area\AreaCreateEvent; use Thelia\Core\Event\Area\AreaDeleteEvent; +use Thelia\Core\Event\Area\AreaRemoveCountryEvent; use Thelia\Core\Event\Area\AreaUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\Area\AreaCountryForm; @@ -271,4 +272,16 @@ class AreaController extends AbstractCrudController // At this point, the form has errors, and should be redisplayed. return $this->renderEditionTemplate(); } + + public function removeCountry() + { + // Check current user authorization + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; + $request = $this->getRequest(); + $removeCountryEvent = new AreaRemoveCountryEvent($request->request->get('areai_id', 0), $request->request->get('country_id', 0)); + + $this->dispatch(TheliaEvents::AREA_REMOVE_COUNTRY, $removeCountryEvent); + + $this->redirectToEditionTemplate(); + } } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 8145a247f..6b8cfddc0 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -237,7 +237,9 @@ final class TheliaEvents const AREA_CREATE = 'action.createArea'; const AREA_UPDATE = 'action.updateArea'; const AREA_DELETE = 'action.deleteArea'; + const AREA_ADD_COUNTRY = 'action.area.addCountry'; + const AREA_REMOVE_COUNTRY = 'action.area.removeCountry'; // -- Categories Associated Content ---------------------------------------- diff --git a/templates/admin/default/shipping-configuration-edit.html b/templates/admin/default/shipping-configuration-edit.html index 78dfe4e7c..e8275dc15 100644 --- a/templates/admin/default/shipping-configuration-edit.html +++ b/templates/admin/default/shipping-configuration-edit.html @@ -71,7 +71,7 @@ {$TITLE} - + @@ -81,16 +81,29 @@ - - + {form name="thelia.admin.area.postage"} + + {form_hidden_fields form=$form} + + {form_field form=$form field='success_url'} + + {/form_field} + + {form_field form=$form field='area_id'} + + {/form_field} + {form_field form=$form field='postage'} +
- +
+ {/form_field} + {/form} @@ -117,7 +130,8 @@ {* Delete related content confirmation dialog *} {capture "delete_country_dialog"} - + + {/capture} {include @@ -127,7 +141,7 @@ dialog_title = {intl l="Remove country"} dialog_message = {intl l="Do you really want to remove this country ?"} - form_action = {url path=''} + form_action = {url path='/admin/configuration/shipping_configuration/country/remove'} form_content = {$smarty.capture.delete_country_dialog nofilter} } {/block} @@ -139,4 +153,12 @@ {javascripts file='assets/js/bootstrap-select/bootstrap-select.js'} {/javascripts} + + {/block} \ No newline at end of file From 8d4fa3b29bb0d370a38f223f8bed91d4520d1e31 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 11:03:44 +0200 Subject: [PATCH 10/20] add missinf files --- .../Event/Area/AreaRemoveCountryEvent.php | 35 ++++++++ .../Event/Area/AreaUpdatePostageEvent.php | 85 ++++++++++++++++++ core/lib/Thelia/Form/Area/AreaPostageForm.php | 88 +++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php create mode 100644 core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php create mode 100644 core/lib/Thelia/Form/Area/AreaPostageForm.php diff --git a/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php b/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php new file mode 100644 index 000000000..84c8f10d2 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; + + +/** + * Class AreaRemoveCountryEvent + * @package Thelia\Core\Event\Area + * @author Manuel Raynaud + */ +class AreaRemoveCountryEvent extends AreaAddCountryEvent +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php b/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php new file mode 100644 index 000000000..5f799b93c --- /dev/null +++ b/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php @@ -0,0 +1,85 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Area; + + +/** + * Class AreaUpdatePostageEvent + * @package Thelia\Core\Event\Area + * @author Manuel Raynaud + */ +class AreaUpdatePostageEvent extends AreaEvent +{ + protected $area_id; + protected $postage; + + function __construct($area_id) + { + $this->area_id = $area_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 $postage + * + * @return $this + */ + public function setPostage($postage) + { + $this->postage = $postage; + + return $this; + } + + /** + * @return mixed + */ + public function getPostage() + { + return $this->postage; + } + + + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/Area/AreaPostageForm.php b/core/lib/Thelia/Form/Area/AreaPostageForm.php new file mode 100644 index 000000000..ba24499e8 --- /dev/null +++ b/core/lib/Thelia/Form/Area/AreaPostageForm.php @@ -0,0 +1,88 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\Area; + +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Form\BaseForm; +use Thelia\Core\Translation\Translator; + + +/** + * Class AreaPostageForm + * @package Thelia\Form\Area + * @author Manuel Raynaud + */ +class AreaPostageForm extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add('area_id', 'integer', array( + 'constraints' => array( + new GreaterThan(array('value' => 0)), + new NotBlank() + ) + )) + ->add('postage', 'number', array( + 'constraints' => array( + new GreaterThanOrEqual(array('value' => 0)), + new NotBlank() + ), + 'label_attr' => array('for' => 'area_postage'), + 'label' => Translator::getInstance()->trans('Postage') + )) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia_area_postage'; + } +} \ No newline at end of file From 52b68df4bc118b6944e90d61d1f83f9482b5cf03 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 11:12:17 +0200 Subject: [PATCH 11/20] update area postage --- core/lib/Thelia/Action/Area.php | 15 +++++- .../Controller/Admin/AreaController.php | 47 +++++++++++++++++-- core/lib/Thelia/Core/Event/TheliaEvents.php | 1 + .../default/shipping-configuration-edit.html | 2 +- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index d3aa5bbc5..ddb1fcdf5 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -25,6 +25,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Area\AreaAddCountryEvent; use Thelia\Core\Event\Area\AreaRemoveCountryEvent; +use Thelia\Core\Event\Area\AreaUpdatePostageEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\AreaQuery; use Thelia\Model\CountryQuery; @@ -57,6 +58,17 @@ class Area extends BaseAction implements EventSubscriberInterface } } + public function updatePostage(AreaUpdatePostageEvent $event) + { + if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) { + $area + ->setPostage($event->getPostage()) + ->save(); + + $event->setArea($area); + } + } + /** * Returns an array of event names this subscriber wants to listen to. @@ -82,7 +94,8 @@ class Area extends BaseAction implements EventSubscriberInterface { return array( TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128), - TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128) + TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128), + TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128) ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 62333fb7b..824678ae3 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -28,10 +28,12 @@ use Thelia\Core\Event\Area\AreaCreateEvent; use Thelia\Core\Event\Area\AreaDeleteEvent; use Thelia\Core\Event\Area\AreaRemoveCountryEvent; use Thelia\Core\Event\Area\AreaUpdateEvent; +use Thelia\Core\Event\Area\AreaUpdatePostageEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\Area\AreaCountryForm; use Thelia\Form\Area\AreaCreateForm; use Thelia\Form\Area\AreaModificationForm; +use Thelia\Form\Area\AreaPostageForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Model\AreaQuery; @@ -251,10 +253,6 @@ class AreaController extends AbstractCrudController $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()); @@ -284,4 +282,45 @@ class AreaController extends AbstractCrudController $this->redirectToEditionTemplate(); } + + public function updatePostageAction() + { + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; + + $areaUpdateForm = new AreaPostageForm($this->getRequest()); + $error_msg = null; + + try { + $form = $this->validateForm($areaUpdateForm); + + $event = new AreaUpdatePostageEvent($form->get('area_id')->getData()); + $event->setPostage($form->get('postage')->getData()); + + $this->dispatch(TheliaEvents::AREA_POSTAGE_UPDATE, $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))); + } + + // Redirect to the success URL + $this->redirect($areaUpdateForm->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, $areaUpdateForm); + + // At this point, the form has errors, and should be redisplayed. + return $this->renderEditionTemplate(); + } } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 6b8cfddc0..9d9e484ef 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -240,6 +240,7 @@ final class TheliaEvents const AREA_ADD_COUNTRY = 'action.area.addCountry'; const AREA_REMOVE_COUNTRY = 'action.area.removeCountry'; + const AREA_POSTAGE_UPDATE = 'action.area.postageUpdate'; // -- Categories Associated Content ---------------------------------------- diff --git a/templates/admin/default/shipping-configuration-edit.html b/templates/admin/default/shipping-configuration-edit.html index e8275dc15..768561313 100644 --- a/templates/admin/default/shipping-configuration-edit.html +++ b/templates/admin/default/shipping-configuration-edit.html @@ -95,7 +95,7 @@ {form_field form=$form field='postage'}
- + From 998e1369a57e6be3eccf8c05d9c346d10d0d9ff9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 11:15:08 +0200 Subject: [PATCH 12/20] display error message --- templates/admin/default/shipping-configuration-edit.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/admin/default/shipping-configuration-edit.html b/templates/admin/default/shipping-configuration-edit.html index 768561313..9e0268d0f 100644 --- a/templates/admin/default/shipping-configuration-edit.html +++ b/templates/admin/default/shipping-configuration-edit.html @@ -94,12 +94,15 @@ {/form_field} {form_field form=$form field='postage'} -
+
+ {if $error } + {$message} + {/if}
{/form_field} From 820a92c9c15b2ea062ffdc79b81b84fb8dee9627 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 11:26:13 +0200 Subject: [PATCH 13/20] add pre/post methods in Area model --- core/lib/Thelia/Action/Area.php | 17 +++++++- .../Thelia/Config/Resources/routing/admin.xml | 4 ++ core/lib/Thelia/Core/Event/TheliaEvents.php | 9 ++++ core/lib/Thelia/Model/Area.php | 41 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index ddb1fcdf5..a6de7d3e7 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -24,6 +24,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Area\AreaAddCountryEvent; +use Thelia\Core\Event\Area\AreaDeleteEvent; use Thelia\Core\Event\Area\AreaRemoveCountryEvent; use Thelia\Core\Event\Area\AreaUpdatePostageEvent; use Thelia\Core\Event\TheliaEvents; @@ -43,6 +44,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function addCountry(AreaAddCountryEvent $event) { if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country->setDispatcher($this->getDispatcher()); $country->setAreaId($event->getAreaId()) ->save(); @@ -53,6 +55,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function removeCountry(AreaRemoveCountryEvent $event) { if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country->setDispatcher($this->getDispatcher()); $country->setAreaId(null) ->save(); } @@ -61,6 +64,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function updatePostage(AreaUpdatePostageEvent $event) { if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) { + $area->setDispatcher($this->getDispatcher()); $area ->setPostage($event->getPostage()) ->save(); @@ -69,6 +73,16 @@ class Area extends BaseAction implements EventSubscriberInterface } } + public function delete(AreaDeleteEvent $event) + { + if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) { + $area->setDispatcher($this->getDispatcher()); + $area->delete(); + + $event->setArea($area); + } + } + /** * Returns an array of event names this subscriber wants to listen to. @@ -95,7 +109,8 @@ class Area extends BaseAction implements EventSubscriberInterface return array( TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128), TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128), - TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128) + TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128), + TheliaEvents::AREA_DELETE => array('delete', 128) ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index e69853d99..9ff5516d7 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -696,6 +696,10 @@ \d+ + + Thelia\Controller\Admin\AreaController::deleteAction + + Thelia\Controller\Admin\AreaController::updatePostageAction \d+ diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 9d9e484ef..a21431bbc 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -242,6 +242,15 @@ final class TheliaEvents const AREA_REMOVE_COUNTRY = 'action.area.removeCountry'; const AREA_POSTAGE_UPDATE = 'action.area.postageUpdate'; + const BEFORE_CREATEAREA = 'action.before_createArea'; + const AFTER_CREATEAREA = 'action.after_createArea'; + + const BEFORE_UPDATEAREA = 'action.before_updateArea'; + const AFTER_UPDATEAREA = 'action.after_updateArea'; + + const BEFORE_DELETEAREA = 'action.before_deleteArea'; + const AFTER_DELETEAREA = 'action.after_deleteArea'; + // -- Categories Associated Content ---------------------------------------- const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent"; diff --git a/core/lib/Thelia/Model/Area.php b/core/lib/Thelia/Model/Area.php index 2a91e7cd3..f826c0fcd 100755 --- a/core/lib/Thelia/Model/Area.php +++ b/core/lib/Thelia/Model/Area.php @@ -2,8 +2,49 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; +use Thelia\Core\Event\Area\AreaEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Area as BaseArea; class Area extends BaseArea { + use \Thelia\Model\Tools\ModelEventDispatcherTrait; + + public function preInsert(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_CREATEAREA, new AreaEvent($this)); + + return true; + } + + public function postInsert(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_CREATEAREA, new AreaEvent($this)); + } + + public function preUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATEAREA, new AreaEvent($this)); + + return true; + } + + public function postUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_UPDATEAREA, new AreaEvent($this)); + } + + public function preDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_DELETEAREA, new AreaEvent($this)); + + return true; + } + + public function postDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_DELETEAREA, new AreaEvent($this)); + } + } From 467113296405411d29cc2486ab1d16a45ab2d599 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 11:40:37 +0200 Subject: [PATCH 14/20] delete area --- .../Thelia/Config/Resources/routing/admin.xml | 2 +- .../admin/default/shipping-configuration.html | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 9ff5516d7..ca1b0821c 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -696,7 +696,7 @@ \d+ - + Thelia\Controller\Admin\AreaController::deleteAction diff --git a/templates/admin/default/shipping-configuration.html b/templates/admin/default/shipping-configuration.html index 7cd88bb1d..84287615d 100644 --- a/templates/admin/default/shipping-configuration.html +++ b/templates/admin/default/shipping-configuration.html @@ -50,10 +50,10 @@
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-configuration.change"} - + {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.shipping-configuration.delete"} - + {/loop}
@@ -105,7 +105,7 @@ {* Delete confirmation dialog *} {capture "delete_dialog"} - + {module_include location='shipping_configuration_delete_form'} @@ -121,4 +121,14 @@ form_action = {url path='/admin/configuration/shipping_configuration/delete'} form_content = {$smarty.capture.delete_dialog nofilter} } +{/block} + +{block name="javascript-initialization"} + {/block} \ No newline at end of file From 97887f1d54c1caba12867f888a221d1b5da65924 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 12:28:30 +0200 Subject: [PATCH 15/20] allow to create a new area --- core/lib/Thelia/Action/Area.php | 17 ++++++++++++++++- .../Thelia/Config/Resources/routing/admin.xml | 4 ++++ .../Thelia/Controller/Admin/AreaController.php | 2 +- .../Thelia/Core/Event/Area/AreaCreateEvent.php | 4 ++-- .../admin/default/shipping-configuration.html | 17 ++++++++++++----- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index a6de7d3e7..d9173ae93 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -24,6 +24,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Area\AreaAddCountryEvent; +use Thelia\Core\Event\Area\AreaCreateEvent; use Thelia\Core\Event\Area\AreaDeleteEvent; use Thelia\Core\Event\Area\AreaRemoveCountryEvent; use Thelia\Core\Event\Area\AreaUpdatePostageEvent; @@ -31,6 +32,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\AreaQuery; use Thelia\Model\CountryQuery; use Thelia\Action\BaseAction; +use Thelia\Model\Area as AreaModel; /** @@ -83,6 +85,18 @@ class Area extends BaseAction implements EventSubscriberInterface } } + public function create(AreaCreateEvent $event) + { + $area = new AreaModel(); + + $area + ->setDispatcher($this->getDispatcher()) + ->setName($event->getAreaName()) + ->save(); + + $event->setArea($area); + } + /** * Returns an array of event names this subscriber wants to listen to. @@ -110,7 +124,8 @@ class Area extends BaseAction implements EventSubscriberInterface TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128), TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128), TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128), - TheliaEvents::AREA_DELETE => array('delete', 128) + TheliaEvents::AREA_DELETE => array('delete', 128), + TheliaEvents::AREA_CREATE => array('create', 128) ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index ca1b0821c..2cf8851e1 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -700,6 +700,10 @@ Thelia\Controller\Admin\AreaController::deleteAction
+ + Thelia\Controller\Admin\AreaController::createAction + + Thelia\Controller\Admin\AreaController::updatePostageAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 824678ae3..0b6fef7cc 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -126,7 +126,7 @@ class AreaController extends AbstractCrudController private function hydrateEvent($event, $formData) { - $event->setName($formData['name']); + $event->setAreaName($formData['name']); return $event; } diff --git a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php index a06ef2bc3..d63afa5b9 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php @@ -36,7 +36,7 @@ class AreaCreateEvent extends AreaEvent /** * @param mixed $name */ - public function setName($name) + public function setAreaName($name) { $this->name = $name; } @@ -44,7 +44,7 @@ class AreaCreateEvent extends AreaEvent /** * @return mixed */ - public function getName() + public function getAreaName() { return $this->name; } diff --git a/templates/admin/default/shipping-configuration.html b/templates/admin/default/shipping-configuration.html index 84287615d..d4c8147c2 100644 --- a/templates/admin/default/shipping-configuration.html +++ b/templates/admin/default/shipping-configuration.html @@ -75,16 +75,23 @@ {* Capture the dialog body, to pass it to the generic dialog *} {capture "creation_dialog"} + {form name="thelia.admin.area.create"} + {form_hidden_fields form=$form} - + {form_field form=$form field='success_url'} + {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} + + {/form_field} + {form_field form=$form field="name"}
- - + +
+ {/form_field} {module_include location='shipping_configuration_create_form'} - + {/form} {/capture} {include @@ -97,7 +104,7 @@ dialog_ok_label = {intl l="Create this shipping configuration"} dialog_cancel_label = {intl l="Cancel"} - form_action = {url path='/admin/configuration/configuration/shipping_configuration/create'} + form_action = {url path='/admin/configuration/shipping_configuration/create'} form_enctype = '' form_error_message = $form_error_message } From 75bc86d43e8d708efb9e64450affabff260003f6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 12:40:09 +0200 Subject: [PATCH 16/20] complete admin log message --- core/lib/Thelia/Controller/Admin/AreaController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 0b6fef7cc..d6ac7918a 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -250,7 +250,7 @@ class AreaController extends AbstractCrudController // 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))); + $this->adminLogAppend(sprintf("%s %s (ID %s) modified, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } // Redirect to the success URL @@ -304,7 +304,7 @@ class AreaController extends AbstractCrudController // 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))); + $this->adminLogAppend(sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } // Redirect to the success URL From 9c4c63a564fd2db561ca129122e5b3ac52bd584a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 14:08:50 +0200 Subject: [PATCH 17/20] start shipping zone management --- .../Admin/ShippingZoneController.php | 2 + core/lib/Thelia/Core/Template/Loop/Area.php | 22 +++++- .../admin/default/shipping-zones-edit.html | 28 ++----- templates/admin/default/shipping-zones.html | 74 +++---------------- 4 files changed, 38 insertions(+), 88 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php index 0084c861b..d66967d44 100644 --- a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php +++ b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php @@ -42,4 +42,6 @@ class ShippingZoneController extends BaseAdminController "shipping_zones_id" => $shipping_zones_id )); } + + } diff --git a/core/lib/Thelia/Core/Template/Loop/Area.php b/core/lib/Thelia/Core/Template/Loop/Area.php index 48baf2fbb..4d43f524b 100644 --- a/core/lib/Thelia/Core/Template/Loop/Area.php +++ b/core/lib/Thelia/Core/Template/Loop/Area.php @@ -75,7 +75,9 @@ class Area extends BaseLoop protected function getArgDefinitions() { return new ArgumentCollection( - Argument::createIntListTypeArgument('id') + Argument::createIntListTypeArgument('id'), + Argument::createIntTypeArgument('with_zone'), + Argument::createIntTypeArgument('without_zone') ); } @@ -101,6 +103,24 @@ class Area extends BaseLoop $search->filterById($id, Criteria::IN); } + $withZone = $this->getWith_zone(); + + if ($withZone) { + $search->joinAreaDeliveryModule('with_zone') + ->where('`with_zone`.delivery_module_id '.Criteria::EQUAL.' ?', $withZone, \PDO::PARAM_INT); + } + + $withoutZone = $this->getWithout_zone(); + + if($withoutZone) + { + $search->joinAreaDeliveryModule('without_zone', Criteria::LEFT_JOIN) + ->addJoinCondition('without_zone', 'delivery_module_id '.Criteria::EQUAL.' ?', $withoutZone, null, \PDO::PARAM_INT) + ->where('`without_zone`.delivery_module_id '.Criteria::ISNULL); + } + + //echo $search->toString(); exit; + $areas = $this->search($search, $pagination); $loopResult = new LoopResult($areas); diff --git a/templates/admin/default/shipping-zones-edit.html b/templates/admin/default/shipping-zones-edit.html index c330f9064..a36cbccd9 100644 --- a/templates/admin/default/shipping-zones-edit.html +++ b/templates/admin/default/shipping-zones-edit.html @@ -32,11 +32,9 @@
@@ -57,30 +55,16 @@ + {loop type="area" name="area.module.associated" with_zone=$shipping_zones_id} - France - - - - - - - - Zone 1 - - - - - - - - Zone 2 + {$NAME} + {/loop}
diff --git a/templates/admin/default/shipping-zones.html b/templates/admin/default/shipping-zones.html index 20ffef799..5eeed61c4 100644 --- a/templates/admin/default/shipping-zones.html +++ b/templates/admin/default/shipping-zones.html @@ -36,57 +36,21 @@ + {loop type="delivery" name="delivery.list" backend_context="1"} - So Colissimo + {$TITLE} {module_include location='shipping_zones_table_row'} - {if ! $SECURED} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-zones.change"} - - {/loop} -
- {else} - - {/if} +
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-zones.change"} + + {/loop} +
- - - Chronopost - - {module_include location='shipping_zones_table_row'} - - - {if ! $SECURED} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-zones.change"} - - {/loop} -
- {else} - - {/if} - - - - Kiala - - {module_include location='shipping_zones_table_row'} - - - {if ! $SECURED} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.shipping-zones.change"} - - {/loop} -
- {else} - - {/if} - - + + {/loop}
@@ -98,24 +62,4 @@
- - {* Delete confirmation dialog *} - - {capture "delete_dialog"} - - - {module_include location='shipping_zones_delete_form'} - - {/capture} - - {include - file = "includes/generic-confirm-dialog.html" - - dialog_id = "delete_dialog" - dialog_title = {intl l="Delete shipping zone"} - dialog_message = {intl l="Do you really want to delete this shipping zone ?"} - - form_action = {url path='/admin/configuration/shipping_zones/delete'} - form_content = {$smarty.capture.delete_dialog nofilter} - } {/block} \ No newline at end of file From 9ea86be123ceac8225b39d7863e6ddc0bef63bf5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 16:20:16 +0200 Subject: [PATCH 18/20] create shipping zone area form --- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Form/ShippingZone/ShippingZoneAddArea.php | 87 +++++++++++++++++++ .../admin/default/shipping-zones-edit.html | 20 +++-- 3 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index aafaa85b7..ae6849a34 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -130,6 +130,7 @@
+ diff --git a/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php b/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php new file mode 100644 index 000000000..81dd422b6 --- /dev/null +++ b/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php @@ -0,0 +1,87 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\ShippingZone; + +use Thelia\Core\Translation\Translator; +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Form\BaseForm; + + +/** + * Class ShippingZoneAddArea + * @package Thelia\Form\ShippingZone + * @author Manuel Raynaud + */ +class ShippingZoneAddArea extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add('area_id', 'integer', array( + 'constraints' => array( + new NotBlank(), + new GreaterThan(array('value' => 0)) + ), + 'label_attr' => array('for' => 'shipping_area'), + 'label' => Translator::getInstance()->trans('Area') + )) + ->add('shipping_zone_id', 'integer', array( + 'constraints' => array( + new NotBlank(), + new GreaterThan(array('value' => 0)) + ) + )) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia_shippingzone_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 a36cbccd9..524c14d12 100644 --- a/templates/admin/default/shipping-zones-edit.html +++ b/templates/admin/default/shipping-zones-edit.html @@ -26,12 +26,22 @@
- + {form name="thelia.shopping_zone_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'} +
- {loop name="area.module.not_associated" type="area" without_zone=$shipping_zones_id} {/loop} @@ -40,9 +50,9 @@
- + {/form_field} - + {/form}
From 3c94c9c513ea9110a92ed472b201c7425a3f323f Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 17:23:20 +0200 Subject: [PATCH 19/20] add an area to a delivery module --- core/lib/Thelia/Action/ShippingZone.php | 75 ++++++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 ++ .../Thelia/Config/Resources/routing/admin.xml | 4 + .../Admin/ShippingZoneController.php | 59 +++++++++++++ .../ShippingZone/ShippingZoneAddAreaEvent.php | 87 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 6 +- .../admin/default/shipping-zones-edit.html | 4 +- 7 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 core/lib/Thelia/Action/ShippingZone.php create mode 100644 core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php diff --git a/core/lib/Thelia/Action/ShippingZone.php b/core/lib/Thelia/Action/ShippingZone.php new file mode 100644 index 000000000..9dfb53123 --- /dev/null +++ b/core/lib/Thelia/Action/ShippingZone.php @@ -0,0 +1,75 @@ +. */ +/* */ +/*************************************************************************************/ + +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 + */ +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) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 4770ec377..b3bc085bf 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -131,6 +131,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 2cf8851e1..6daefead9 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -683,6 +683,10 @@ \d+ + + Thelia\Controller\Admin\ShippingZoneController::addArea + + diff --git a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php index d66967d44..8f1117d70 100644 --- a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php +++ b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php @@ -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); + } + } diff --git a/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php new file mode 100644 index 000000000..d1e406646 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php @@ -0,0 +1,87 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\ShippingZone; +use Thelia\Core\Event\ActionEvent; + + +/** + * Class ShippingZoneAddAreaEvent + * @package Thelia\Core\Event\ShippingZone + * @author Manuel Raynaud + */ +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; + } + + + + +} \ 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 a21431bbc..aeade5ea8 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -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"; diff --git a/templates/admin/default/shipping-zones-edit.html b/templates/admin/default/shipping-zones-edit.html index 524c14d12..257b3de9c 100644 --- a/templates/admin/default/shipping-zones-edit.html +++ b/templates/admin/default/shipping-zones-edit.html @@ -27,11 +27,11 @@
{form name="thelia.shopping_zone_area"} -
+ {form_hidden_fields form=$form} {form_field form=$form field='success_url'} - {* the url the user is redirected to on login success *} + {* the url the user is redirected to on login success *} {/form_field} {form_field form=$form field='shipping_zone_id'} From 1aea868785ca25c05f3d9ae3c1fbd66bb179d280 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Oct 2013 17:45:23 +0200 Subject: [PATCH 20/20] remove area to area_delivery_module --- core/lib/Thelia/Action/ShippingZone.php | 19 +++++++- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Thelia/Config/Resources/routing/admin.xml | 6 ++- .../Admin/ShippingZoneController.php | 44 +++++++++++++++++-- .../ShippingZoneRemoveAreaEvent.php | 35 +++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 1 + .../ShippingZone/ShippingZoneRemoveArea.php | 42 ++++++++++++++++++ .../admin/default/shipping-zones-edit.html | 29 ++++++++++-- 8 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php create mode 100644 core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php 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