tax rule set default in back office
This commit is contained in:
@@ -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),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -870,6 +870,11 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.taxes-rules.set-default" path="/admin/configuration/taxes_rules/update/set_default/{tax_rule_id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::setDefaultAction</default>
|
||||
<requirement key="tax_rule_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- end tax rules management -->
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -55,9 +55,9 @@
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l="Name"}</th>
|
||||
<th>{intl l="Description"}</th>
|
||||
<th>{intl l="Actions"}</th>
|
||||
<th class="col-md-3">{intl l="Name"}</th>
|
||||
<th class="col-md-5">{intl l="Description"}</th>
|
||||
<th class="col-md-1">{intl l="Actions"}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -100,9 +100,10 @@
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l="Name"}</th>
|
||||
<th>{intl l="Description"}</th>
|
||||
<th>{intl l="Actions"}</th>
|
||||
<th class="col-md-3">{intl l="Name"}</th>
|
||||
<th class="col-md-4">{intl l="Description"}</th>
|
||||
<th class="col-md-1">{intl l="Default"}</th>
|
||||
<th class="col-md-1">{intl l="Actions"}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -112,13 +113,19 @@
|
||||
<tr>
|
||||
<td>{$TITLE}</td>
|
||||
<td>{$DESCRIPTION}</td>
|
||||
<td>
|
||||
{if $IS_DEFAULT == 1}
|
||||
<span class="glyphicon glyphicon-ok"></span>
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"}
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Change this tax rule'}" href="{url path="/admin/configuration/taxes_rules/update/$ID"}"><span class="glyphicon glyphicon-edit"></span></a>
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Set as default tax rule'}" href="{url path="/admin/configuration/taxes_rules/update/set_default/$ID"}" {if $IS_DEFAULT == 1}disabled{/if}><span class="glyphicon glyphicon-star"></span></a>
|
||||
{/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"}
|
||||
<a class="btn btn-default btn-xs js-delete-tax-rule" title="{intl l='Delete this tax rule'}" href="#tax_rule_delete_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
{/loop}
|
||||
</div>
|
||||
@@ -157,12 +164,10 @@
|
||||
<input type="hidden" name="{$name}" value="{$edit_language_locale}" />
|
||||
{/form_field}
|
||||
|
||||
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
|
||||
|
||||
{form_field form=$form field='title'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Title'}" placeholder="{intl l='Title'}" class="form-control" value="{if $error}{$value}{else}{if $IS_TRANSLATED == 1}{$TITLE}{/if}{/if}">
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Title'}" placeholder="{intl l='Title'}" class="form-control" value="{if $form_error}{$value}{else}{if $IS_TRANSLATED == 1}{$TITLE}{/if}{/if}">
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
@@ -173,7 +178,7 @@
|
||||
<span class="label-help-block">{intl l="The detailed description."}</span>
|
||||
</label>
|
||||
|
||||
<textarea name="{$name}" id="{$label_attr.for}" rows="10" class="form-control wysiwyg">{if $error}{$value}{else}{if $IS_TRANSLATED == 1}{$DESCRIPTION}{/if}{/if}</textarea>
|
||||
<textarea name="{$name}" id="{$label_attr.for}" rows="10" class="form-control wysiwyg">{if $form_error}{$value}{else}{if $IS_TRANSLATED == 1}{$DESCRIPTION}{/if}{/if}</textarea>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
@@ -184,15 +189,37 @@
|
||||
</label>
|
||||
|
||||
<div class="form-group">
|
||||
<select name="{$name}" data-toggle="selectpicker">
|
||||
{foreach $choices as $choice}
|
||||
<option value="{$choice->value}" {if $choice->value == $TYPE}selected="selected" {/if}>{$choice->label}</option>
|
||||
<select name="{$name}" class="js-change-tax-type" data-toggle="selectpicker">
|
||||
{$typeValueWithError = $value}
|
||||
{foreach from=$choices key=key item=choice}
|
||||
{if $key == 0}
|
||||
{$typeValue = $choice->value}
|
||||
{/if}
|
||||
<option value="{$choice->value}" {if $form_error && $choice->value == $value || !$form_error && $key == 0}selected="selected" {/if}>{$choice->label}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{form_tagged_fields form=$form tag='requirements'}
|
||||
<div class="form-group {if $error}has-error{/if} js-tax-requirements" data-tax-type="{$attr_list.tax_type}" {if !$form_error && $attr_list.tax_type != $typeValue || $form_error && $attr_list.tax_type != $typeValueWithError}style="display: none"{/if}>
|
||||
<label for="{$label_attr.for}" class="control-label">
|
||||
{intl l=$label}
|
||||
</label>
|
||||
{if $formType == 'choice'}
|
||||
<select name="{$name}" data-toggle="selectpicker" {if !$form_error && $attr_list.tax_type != $typeValue || $form_error && $attr_list.tax_type != $typeValueWithError}disabled="disabled"{/if}>
|
||||
{foreach $choices as $choice}
|
||||
<option value="{$choice->value}" {if !$form_error && $REQUIREMENTS.$label == $choice->value || $form_error && $value == $choice->value}selected="selected" {/if}>{$choice->label}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{/if}
|
||||
{if $formType == 'text'}
|
||||
<input type="text" {if !$form_error && $attr_list.tax_type != $typeValue || $form_error && $attr_list.tax_type != $typeValueWithError}disabled="disabled"{/if} id="{$label_attr.for}" name="{$name}" required="required" class="form-control" value="{if $form_error}{$value}{else}{$REQUIREMENTS.$label}{/if}">
|
||||
{/if}
|
||||
</div>
|
||||
{/form_tagged_fields}
|
||||
|
||||
{/capture}
|
||||
|
||||
{include
|
||||
@@ -322,6 +349,7 @@
|
||||
{/javascripts}
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery(function($) {
|
||||
|
||||
{if $taxRuleCreateError == true}
|
||||
$('#tax_rule_create_dialog').modal();
|
||||
@@ -338,6 +366,15 @@
|
||||
$(".js-delete-tax").click(function(e){
|
||||
$('#tax_delete_id').val($(this).data('id'))
|
||||
});
|
||||
|
||||
$('.js-change-tax-type').change(function(e){
|
||||
$('.js-tax-requirements').children('select, input').attr('disabled', true);
|
||||
$('.js-tax-requirements').hide();
|
||||
$('.js-tax-requirements[data-tax-type="' + $(this).val() + '"]').children('select, input').attr('disabled', false);
|
||||
$('.js-tax-requirements[data-tax-type="' + $(this).val() + '"]').children('select').selectpicker("refresh");
|
||||
$('.js-tax-requirements[data-tax-type="' + $(this).val() + '"]').show();
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
||||
{/block}
|
||||
Reference in New Issue
Block a user