tax edition
This commit is contained in:
@@ -111,6 +111,8 @@
|
||||
|
||||
<form name="thelia.admin.featureav.creation" class="Thelia\Form\FeatureAvCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.taxrule.modification" class="Thelia\Form\TaxRuleModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
|
||||
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>
|
||||
|
||||
|
||||
@@ -779,11 +779,11 @@
|
||||
|
||||
<!-- taxe rules management -->
|
||||
|
||||
<route id="admin.configuration.taxes-rules.default" path="/admin/configuration/taxes_rules">
|
||||
<route id="admin.configuration.taxes-rules.list" path="/admin/configuration/taxes_rules">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.taxes-rules.update" path="/admin/configuration/taxes_rules/update/{tax_rule_id}" methods="get">
|
||||
<route id="admin.configuration.taxes-rules.update" path="/admin/configuration/taxes_rules/update/{tax_rule_id}/{country_isoalpha3}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::updateAction</default>
|
||||
<requirement key="tax_rule_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
@@ -23,23 +23,154 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Class TaxRuleController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class TaxRuleController extends BaseAdminController
|
||||
use Thelia\Core\Event\Tax\TaxRuleEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\TaxRuleCreationForm;
|
||||
use Thelia\Form\TaxRuleModificationForm;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
|
||||
class TaxRuleController extends AbstractCrudController
|
||||
{
|
||||
public function defaultAction()
|
||||
public function __construct()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.taxes-rules.view")) return $response;
|
||||
return $this->render("taxes-rules", array("display_taxes_rules" => 20));
|
||||
parent::__construct(
|
||||
'taxrule',
|
||||
'manual',
|
||||
'order',
|
||||
|
||||
'admin.configuration.taxrule.view',
|
||||
'admin.configuration.taxrule.create',
|
||||
'admin.configuration.taxrule.update',
|
||||
'admin.configuration.taxrule.delete',
|
||||
|
||||
TheliaEvents::TAX_RULE_CREATE,
|
||||
TheliaEvents::TAX_RULE_UPDATE,
|
||||
TheliaEvents::TAX_RULE_DELETE
|
||||
);
|
||||
}
|
||||
|
||||
public function updateAction($tax_rule_id){
|
||||
return $this->render("tax-rule-edit", array(
|
||||
"tax_rule_id" => $tax_rule_id
|
||||
));
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new TaxRuleCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new TaxRuleModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$event = new TaxRuleEvent();
|
||||
|
||||
/* @todo fill event */
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$event = new TaxRuleEvent();
|
||||
|
||||
/* @todo fill event */
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
$event = new TaxRuleEvent();
|
||||
|
||||
/* @todo fill event */
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasTaxRule();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'description' => $object->getDescription(),
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new TaxRuleModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasTaxRule() ? $event->getTaxRule() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return TaxRuleQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('tax_rule_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function getViewArguments()
|
||||
{
|
||||
return array(
|
||||
'tax_rule_id' => $this->getRequest()->get('tax_rule_id'),
|
||||
'country_isoalpha3' => $this->getRequest()->get('country_isoalpha3'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
return $this->render(
|
||||
'taxes-rules',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
/* check the country exists */
|
||||
$country = CountryQuery::create()->findOneByIsoalpha3($this->getRequest()->get('country_isoalpha3'));
|
||||
if(null === $country) {
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
// We always return to the feature edition form
|
||||
return $this->render('tax-rule-edit', $this->getViewArguments());
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.taxes-rules.update",
|
||||
$this->getViewArguments()
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.taxes-rules.list",
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
53
core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php
Normal file
53
core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Tax;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\TaxRule;
|
||||
|
||||
class TaxRuleEvent extends ActionEvent
|
||||
{
|
||||
protected $taxRule = null;
|
||||
|
||||
public function __construct(TaxRule $taxRule = null)
|
||||
{
|
||||
$this->taxRule = $taxRule;
|
||||
}
|
||||
|
||||
public function hasTaxRule()
|
||||
{
|
||||
return ! is_null($this->taxRule);
|
||||
}
|
||||
|
||||
public function getTaxRule()
|
||||
{
|
||||
return $this->taxRule;
|
||||
}
|
||||
|
||||
public function setTaxRule(TaxRule $taxRule)
|
||||
{
|
||||
$this->taxRule = $taxRule;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -503,6 +503,13 @@ final class TheliaEvents
|
||||
|
||||
const CHANGE_DEFAULT_CURRENCY = 'action.changeDefaultCurrency';
|
||||
|
||||
// -- Tax Rules management ---------------------------------------------
|
||||
|
||||
const TAX_RULE_CREATE = "action.createTaxRule";
|
||||
const TAX_RULE_UPDATE = "action.updateTaxRule";
|
||||
const TAX_RULE_DELETE = "action.deleteTaxRule";
|
||||
const TAX_RULE_SET_DEFAULT = "action.setDefaultTaxRule";
|
||||
|
||||
// -- Product templates management -----------------------------------------
|
||||
|
||||
const TEMPLATE_CREATE = "action.createTemplate";
|
||||
|
||||
@@ -113,6 +113,7 @@ class Country extends BaseI18nLoop
|
||||
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $country->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("IS_DEFAULT", $country->getByDefault() === 1 ? "1" : "0")
|
||||
->set("ISOCODE", $country->getIsocode())
|
||||
->set("ISOALPHA2", $country->getIsoalpha2())
|
||||
->set("ISOALPHA3", $country->getIsoalpha3());
|
||||
|
||||
@@ -163,16 +163,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
|
||||
public function countryDataAccess($params, $smarty)
|
||||
{
|
||||
if (array_key_exists('defaultCountry', self::$dataAccessCache)) {
|
||||
$defaultCountry = self::$dataAccessCache['defaultCountry'];
|
||||
} else {
|
||||
$defaultCountry = CountryQuery::create()->findOneByByDefault(1);
|
||||
self::$dataAccessCache['defaultCountry'] = $defaultCountry;
|
||||
}
|
||||
|
||||
switch ($params["attr"]) {
|
||||
switch ($params["ask"]) {
|
||||
case "default":
|
||||
return $defaultCountry->getId();
|
||||
/*if (array_key_exists('defaultCountry', self::$dataAccessCache)) {
|
||||
$defaultCountry = self::$dataAccessCache['defaultCountry'];
|
||||
} else {
|
||||
$defaultCountry = CountryQuery::create()->findOneByByDefault(1);
|
||||
self::$dataAccessCache['defaultCountry'] = $defaultCountry;
|
||||
}*/
|
||||
$defaultCountry = CountryQuery::create()->filterByByDefault(1)->limit(1);
|
||||
return $this->dataAccessWithI18n("defaultCountry", $params, $defaultCountry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
60
core/lib/Thelia/Form/TaxRuleCreationForm.php
Normal file
60
core/lib/Thelia/Form/TaxRuleCreationForm.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class TaxRuleCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("title" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Title *"),
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
))
|
||||
)
|
||||
->add("locale" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
))
|
||||
)
|
||||
->add("feature_id", "hidden", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_tax_rule_creation";
|
||||
}
|
||||
}
|
||||
52
core/lib/Thelia/Form/TaxRuleModificationForm.php
Normal file
52
core/lib/Thelia/Form/TaxRuleModificationForm.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
|
||||
class TaxRuleModificationForm extends FeatureCreationForm
|
||||
{
|
||||
use StandardDescriptionFieldsTrait;
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("id", "hidden", array(
|
||||
"constraints" => array(
|
||||
new GreaterThan(
|
||||
array('value' => 0)
|
||||
)
|
||||
)
|
||||
))
|
||||
;
|
||||
|
||||
// Add standard description fields
|
||||
$this->addStandardDescFields();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_tax_rule_modification";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user