diff --git a/core/lib/Thelia/Action/Tax.php b/core/lib/Thelia/Action/Tax.php index d17433362..c35d87bbe 100644 --- a/core/lib/Thelia/Action/Tax.php +++ b/core/lib/Thelia/Action/Tax.php @@ -41,11 +41,12 @@ class Tax extends BaseAction implements EventSubscriberInterface $tax ->setDispatcher($this->getDispatcher()) + ->setRequirements($event->getRequirements()) ->setType($event->getType()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) ->setDescription($event->getDescription()) - ; + ; $tax->save(); @@ -66,9 +67,10 @@ class Tax extends BaseAction implements EventSubscriberInterface ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) ->setDescription($event->getDescription()) - ->save() ; + $tax->save(); + $event->setTax($tax); } } @@ -97,7 +99,6 @@ class Tax extends BaseAction implements EventSubscriberInterface TheliaEvents::TAX_CREATE => array("create", 128), TheliaEvents::TAX_UPDATE => array("update", 128), TheliaEvents::TAX_DELETE => array("delete", 128), - ); } } diff --git a/core/lib/Thelia/Action/TaxRule.php b/core/lib/Thelia/Action/TaxRule.php index 4b24f8cb9..b3f1d23ae 100644 --- a/core/lib/Thelia/Action/TaxRule.php +++ b/core/lib/Thelia/Action/TaxRule.php @@ -27,6 +27,7 @@ use Propel\Runtime\ActiveQuery\Criteria; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Tax\TaxRuleEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\Map\TaxRuleTableMap; use Thelia\Model\TaxRuleCountry; use Thelia\Model\TaxRuleCountryQuery; use Thelia\Model\TaxRule as TaxRuleModel; @@ -134,6 +135,23 @@ class TaxRule extends BaseAction implements EventSubscriberInterface } } + /** + * @param TaxRuleEvent $event + */ + public function setDefault(TaxRuleEvent $event) + { + if (null !== $taxRule = TaxRuleQuery::create()->findPk($event->getId())) { + + TaxRuleQuery::create()->update(array( + "IsDefault" => 0 + )); + + $taxRule->setIsDefault(1)->save(); + + $event->setTaxRule($taxRule); + } + } + /** * {@inheritDoc} */ @@ -144,7 +162,7 @@ class TaxRule extends BaseAction implements EventSubscriberInterface TheliaEvents::TAX_RULE_UPDATE => array("update", 128), TheliaEvents::TAX_RULE_TAXES_UPDATE => array("updateTaxes", 128), TheliaEvents::TAX_RULE_DELETE => array("delete", 128), - + TheliaEvents::TAX_RULE_SET_DEFAULT => array("setDefault", 128), ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 72fa1cd15..865c14484 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -870,6 +870,11 @@ Thelia\Controller\Admin\TaxRuleController::deleteAction + + Thelia\Controller\Admin\TaxRuleController::setDefaultAction + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/TaxController.php b/core/lib/Thelia/Controller/Admin/TaxController.php index e840f2b78..fd81e4d6c 100644 --- a/core/lib/Thelia/Controller/Admin/TaxController.php +++ b/core/lib/Thelia/Controller/Admin/TaxController.php @@ -68,6 +68,7 @@ class TaxController extends AbstractCrudController $event->setTitle($formData['title']); $event->setDescription($formData['description']); $event->setType($formData['type']); + $event->setRequirements($this->getRequirements($formData['type'], $formData)); return $event; } diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php index b0ceba67e..17381c7a1 100644 --- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php +++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php @@ -236,6 +236,23 @@ class TaxRuleController extends AbstractCrudController return parent::updateAction(); } + public function setDefaultAction() + { + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; + + $setDefaultEvent = new TaxRuleEvent(); + + $taxRuleId = $this->getRequest()->attributes->get('tax_rule_id'); + + $setDefaultEvent->setId( + $taxRuleId + ); + + $this->dispatch(TheliaEvents::TAX_RULE_SET_DEFAULT, $setDefaultEvent); + + $this->redirectToListTemplate(); + } + public function processUpdateTaxesAction() { // Check current user authorization diff --git a/templates/admin/default/taxes-rules.html b/templates/admin/default/taxes-rules.html index 73eb35b40..a7f19d6f5 100644 --- a/templates/admin/default/taxes-rules.html +++ b/templates/admin/default/taxes-rules.html @@ -55,9 +55,9 @@ - {intl l="Name"} - {intl l="Description"} - {intl l="Actions"} + {intl l="Name"} + {intl l="Description"} + {intl l="Actions"} @@ -100,9 +100,10 @@ - {intl l="Name"} - {intl l="Description"} - {intl l="Actions"} + {intl l="Name"} + {intl l="Description"} + {intl l="Default"} + {intl l="Actions"} @@ -112,13 +113,19 @@ {$TITLE} {$DESCRIPTION} + + {if $IS_DEFAULT == 1} + + {/if} +
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"} + {/loop} - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.dele"} {/loop}
@@ -157,12 +164,10 @@ {/form_field} - {if $form_error}
{$form_error_message}
{/if} - {form_field form=$form field='title'}
- +
{/form_field} @@ -173,7 +178,7 @@ {intl l="The detailed description."} - + {/form_field} @@ -184,15 +189,37 @@
- + {$typeValueWithError = $value} + {foreach from=$choices key=key item=choice} + {if $key == 0} + {$typeValue = $choice->value} + {/if} + {/foreach}
{/form_field} + {form_tagged_fields form=$form tag='requirements'} +
+ + {if $formType == 'choice'} + + {/if} + {if $formType == 'text'} + + {/if} +
+ {/form_tagged_fields} + {/capture} {include @@ -322,6 +349,7 @@ {/javascripts} {/block} \ No newline at end of file