diff --git a/core/lib/Thelia/Action/TaxRule.php b/core/lib/Thelia/Action/TaxRule.php
index b3656d993..4b24f8cb9 100644
--- a/core/lib/Thelia/Action/TaxRule.php
+++ b/core/lib/Thelia/Action/TaxRule.php
@@ -39,31 +39,18 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
*/
public function create(TaxRuleEvent $event)
{
- $product = new TaxRuleModel();
+ $taxRule = new TaxRuleModel();
- $product
+ $taxRule
->setDispatcher($this->getDispatcher())
-
- ->setRef($event->getRef())
- ->setTitle($event->getTitle())
->setLocale($event->getLocale())
- ->setVisible($event->getVisible())
-
- // Set the default tax rule to this product
- ->setTaxRule(TaxRuleQuery::create()->findOneByIsDefault(true))
-
- //public function create($defaultCategoryId, $basePrice, $priceCurrencyId, $taxRuleId, $baseWeight) {
-
- ->create(
- $event->getDefaultCategory(),
- $event->getBasePrice(),
- $event->getCurrencyId(),
- $event->getTaxRuleId(),
- $event->getBaseWeight()
- );
+ ->setTitle($event->getTitle())
+ ->setDescription($event->getDescription())
;
- $event->setTaxRule($product);
+ $taxRule->save();
+
+ $event->setTaxRule($taxRule);
}
/**
@@ -74,6 +61,7 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
if (null !== $taxRule = TaxRuleQuery::create()->findPk($event->getId())) {
$taxRule
+ ->setDispatcher($this->getDispatcher())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
->setDescription($event->getDescription())
diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml
index 39ba508fd..5e2227989 100755
--- a/core/lib/Thelia/Config/Resources/config.xml
+++ b/core/lib/Thelia/Config/Resources/config.xml
@@ -115,6 +115,7 @@
+
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 62049d285..9803bc866 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -798,6 +798,10 @@
\d+
+
+ Thelia\Controller\Admin\TaxRuleController::createAction
+
+
Thelia\Controller\Admin\TaxRuleController::processUpdateAction
diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php
index b50a39638..b0ceba67e 100644
--- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php
+++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php
@@ -65,7 +65,9 @@ class TaxRuleController extends AbstractCrudController
{
$event = new TaxRuleEvent();
- /* @todo fill event */
+ $event->setLocale($formData['locale']);
+ $event->setTitle($formData['title']);
+ $event->setDescription($formData['description']);
return $event;
}
@@ -154,18 +156,18 @@ class TaxRuleController extends AbstractCrudController
return $object->getId();
}
- protected function getViewArguments($country = null)
+ protected function getViewArguments($country = null, $tab = null)
{
return array(
- 'tab' => $this->getRequest()->get('tab', 'data'),
+ 'tab' => $tab === null ? $this->getRequest()->get('tab', 'data') : $tab,
'country' => $country === null ? $this->getRequest()->get('country', CountryQuery::create()->findOneByByDefault(1)->getId()) : $country,
);
}
- protected function getRouteArguments()
+ protected function getRouteArguments($tax_rule_id = null)
{
return array(
- 'tax_rule_id' => $this->getRequest()->get('tax_rule_id'),
+ 'tax_rule_id' => $tax_rule_id === null ? $this->getRequest()->get('tax_rule_id') : $tax_rule_id,
);
}
@@ -194,6 +196,21 @@ class TaxRuleController extends AbstractCrudController
);
}
+ /**
+ * Put in this method post object creation processing if required.
+ *
+ * @param TaxRuleEvent $createEvent the create event
+ * @return Response a response, or null to continue normal processing
+ */
+ protected function performAdditionalCreateAction($createEvent)
+ {
+ $this->redirectToRoute(
+ "admin.configuration.taxes-rules.update",
+ $this->getViewArguments(),
+ $this->getRouteArguments($createEvent->getTaxRule()->getId())
+ );
+ }
+
protected function redirectToListTemplate()
{
$this->redirectToRoute(
diff --git a/core/lib/Thelia/Form/TaxRuleCreationForm.php b/core/lib/Thelia/Form/TaxRuleCreationForm.php
index a069bd005..be3556321 100644
--- a/core/lib/Thelia/Form/TaxRuleCreationForm.php
+++ b/core/lib/Thelia/Form/TaxRuleCreationForm.php
@@ -29,6 +29,8 @@ use Thelia\Model\CountryQuery;
class TaxRuleCreationForm extends BaseForm
{
+ use StandardDescriptionFieldsTrait;
+
protected function buildForm($change_mode = false)
{
$this->formBuilder
@@ -36,6 +38,8 @@ class TaxRuleCreationForm extends BaseForm
"constraints" => array(new NotBlank())
))
;
+
+ $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
}
public function getName()
diff --git a/core/lib/Thelia/Form/TaxRuleModificationForm.php b/core/lib/Thelia/Form/TaxRuleModificationForm.php
index 5884e4b57..3ec8e1f87 100644
--- a/core/lib/Thelia/Form/TaxRuleModificationForm.php
+++ b/core/lib/Thelia/Form/TaxRuleModificationForm.php
@@ -28,8 +28,6 @@ use Thelia\Model\TaxRuleQuery;
class TaxRuleModificationForm extends TaxRuleCreationForm
{
- use StandardDescriptionFieldsTrait;
-
protected function buildForm()
{
parent::buildForm(true);
@@ -49,9 +47,6 @@ class TaxRuleModificationForm extends TaxRuleCreationForm
)
))
;
-
- // Add standard description fields
- $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
}
public function getName()
diff --git a/core/lib/Thelia/Model/TaxRule.php b/core/lib/Thelia/Model/TaxRule.php
index 72d8ae851..7758acdf2 100755
--- a/core/lib/Thelia/Model/TaxRule.php
+++ b/core/lib/Thelia/Model/TaxRule.php
@@ -3,11 +3,14 @@
namespace Thelia\Model;
use Thelia\Model\Base\TaxRule as BaseTaxRule;
+use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\TaxEngine\Calculator;
use Thelia\TaxEngine\OrderProductTaxCollection;
class TaxRule extends BaseTaxRule
{
+ use ModelEventDispatcherTrait;
+
/**
* @param Country $country
* @param $untaxedAmount
diff --git a/templates/admin/default/taxes-rules.html b/templates/admin/default/taxes-rules.html
index 387f70e08..67e8b414a 100644
--- a/templates/admin/default/taxes-rules.html
+++ b/templates/admin/default/taxes-rules.html
@@ -27,7 +27,7 @@
{intl l="Taxes rules"}
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.taxes-rules.create"}
-
+
{/loop}
@@ -73,7 +73,64 @@
-{* -- Delete category confirmation dialog ----------------------------------- *}
+{* -- Add tax rule confirmation dialog ----------------------------------- *}
+{form name="thelia.admin.taxrule.add"}
+
+{if $form_error_message}
+ {$taxCreateError = true}
+{else}
+ {$taxCreateError = false}
+{/if}
+
+{* Capture the dialog body, to pass it to the generic dialog *}
+{capture "tax_rule_create_dialog"}
+
+ {form_hidden_fields form=$form}
+
+ {form_field form=$form field='locale'}
+
+ {/form_field}
+
+ {if $form_error}{$form_error_message}
{/if}
+
+ {form_field form=$form field='title'}
+
+
+
+
+ {/form_field}
+
+ {form_field form=$form field='description'}
+
+
+
+
+
+ {/form_field}
+
+{/capture}
+
+ {include
+ file = "includes/generic-create-dialog.html"
+
+ dialog_id = "tax_rule_create_dialog"
+ dialog_title = {intl l="Create a new tax rule"}
+ dialog_body = {$smarty.capture.tax_rule_create_dialog nofilter}
+
+ dialog_ok_label = {intl l="Create"}
+ dialog_cancel_label = {intl l="Cancel"}
+
+ form_action = {url path="/admin/configuration/taxes_rules/add"}
+ form_enctype = {form_enctype form=$form}
+ form_error_message = $form_error_message
+ }
+
+{/form}
+
+{* -- Delete tax rule confirmation dialog ----------------------------------- *}
{capture "tax_rule_delete_dialog"}
@@ -97,10 +154,15 @@
{block name="javascript-initialization"}
-
+
{/block}
\ No newline at end of file