tax rule creation
This commit is contained in:
@@ -39,31 +39,18 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public function create(TaxRuleEvent $event)
|
public function create(TaxRuleEvent $event)
|
||||||
{
|
{
|
||||||
$product = new TaxRuleModel();
|
$taxRule = new TaxRuleModel();
|
||||||
|
|
||||||
$product
|
$taxRule
|
||||||
->setDispatcher($this->getDispatcher())
|
->setDispatcher($this->getDispatcher())
|
||||||
|
|
||||||
->setRef($event->getRef())
|
|
||||||
->setTitle($event->getTitle())
|
|
||||||
->setLocale($event->getLocale())
|
->setLocale($event->getLocale())
|
||||||
->setVisible($event->getVisible())
|
->setTitle($event->getTitle())
|
||||||
|
->setDescription($event->getDescription())
|
||||||
// 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()
|
|
||||||
);
|
|
||||||
;
|
;
|
||||||
|
|
||||||
$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())) {
|
if (null !== $taxRule = TaxRuleQuery::create()->findPk($event->getId())) {
|
||||||
|
|
||||||
$taxRule
|
$taxRule
|
||||||
|
->setDispatcher($this->getDispatcher())
|
||||||
->setLocale($event->getLocale())
|
->setLocale($event->getLocale())
|
||||||
->setTitle($event->getTitle())
|
->setTitle($event->getTitle())
|
||||||
->setDescription($event->getDescription())
|
->setDescription($event->getDescription())
|
||||||
|
|||||||
@@ -115,6 +115,7 @@
|
|||||||
|
|
||||||
<form name="thelia.admin.taxrule.modification" class="Thelia\Form\TaxRuleModificationForm"/>
|
<form name="thelia.admin.taxrule.modification" class="Thelia\Form\TaxRuleModificationForm"/>
|
||||||
<form name="thelia.admin.taxrule.taxlistupdate" class="Thelia\Form\TaxRuleTaxListUpdateForm"/>
|
<form name="thelia.admin.taxrule.taxlistupdate" class="Thelia\Form\TaxRuleTaxListUpdateForm"/>
|
||||||
|
<form name="thelia.admin.taxrule.add" class="Thelia\Form\TaxRuleCreationForm"/>
|
||||||
|
|
||||||
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
|
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
|
||||||
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>
|
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>
|
||||||
|
|||||||
@@ -798,6 +798,10 @@
|
|||||||
<requirement key="tax_rule_id">\d+</requirement>
|
<requirement key="tax_rule_id">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
<route id="admin.configuration.taxes-rules.add" path="/admin/configuration/taxes_rules/add">
|
||||||
|
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::createAction</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
<route id="admin.configuration.taxes-rules.save" path="/admin/configuration/taxes_rules/save">
|
<route id="admin.configuration.taxes-rules.save" path="/admin/configuration/taxes_rules/save">
|
||||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::processUpdateAction</default>
|
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::processUpdateAction</default>
|
||||||
</route>
|
</route>
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ class TaxRuleController extends AbstractCrudController
|
|||||||
{
|
{
|
||||||
$event = new TaxRuleEvent();
|
$event = new TaxRuleEvent();
|
||||||
|
|
||||||
/* @todo fill event */
|
$event->setLocale($formData['locale']);
|
||||||
|
$event->setTitle($formData['title']);
|
||||||
|
$event->setDescription($formData['description']);
|
||||||
|
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
@@ -154,18 +156,18 @@ class TaxRuleController extends AbstractCrudController
|
|||||||
return $object->getId();
|
return $object->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getViewArguments($country = null)
|
protected function getViewArguments($country = null, $tab = null)
|
||||||
{
|
{
|
||||||
return array(
|
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,
|
'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(
|
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()
|
protected function redirectToListTemplate()
|
||||||
{
|
{
|
||||||
$this->redirectToRoute(
|
$this->redirectToRoute(
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ use Thelia\Model\CountryQuery;
|
|||||||
|
|
||||||
class TaxRuleCreationForm extends BaseForm
|
class TaxRuleCreationForm extends BaseForm
|
||||||
{
|
{
|
||||||
|
use StandardDescriptionFieldsTrait;
|
||||||
|
|
||||||
protected function buildForm($change_mode = false)
|
protected function buildForm($change_mode = false)
|
||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
@@ -36,6 +38,8 @@ class TaxRuleCreationForm extends BaseForm
|
|||||||
"constraints" => array(new NotBlank())
|
"constraints" => array(new NotBlank())
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ use Thelia\Model\TaxRuleQuery;
|
|||||||
|
|
||||||
class TaxRuleModificationForm extends TaxRuleCreationForm
|
class TaxRuleModificationForm extends TaxRuleCreationForm
|
||||||
{
|
{
|
||||||
use StandardDescriptionFieldsTrait;
|
|
||||||
|
|
||||||
protected function buildForm()
|
protected function buildForm()
|
||||||
{
|
{
|
||||||
parent::buildForm(true);
|
parent::buildForm(true);
|
||||||
@@ -49,9 +47,6 @@ class TaxRuleModificationForm extends TaxRuleCreationForm
|
|||||||
)
|
)
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
|
|
||||||
// Add standard description fields
|
|
||||||
$this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
namespace Thelia\Model;
|
namespace Thelia\Model;
|
||||||
|
|
||||||
use Thelia\Model\Base\TaxRule as BaseTaxRule;
|
use Thelia\Model\Base\TaxRule as BaseTaxRule;
|
||||||
|
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||||
use Thelia\TaxEngine\Calculator;
|
use Thelia\TaxEngine\Calculator;
|
||||||
use Thelia\TaxEngine\OrderProductTaxCollection;
|
use Thelia\TaxEngine\OrderProductTaxCollection;
|
||||||
|
|
||||||
class TaxRule extends BaseTaxRule
|
class TaxRule extends BaseTaxRule
|
||||||
{
|
{
|
||||||
|
use ModelEventDispatcherTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Country $country
|
* @param Country $country
|
||||||
* @param $untaxedAmount
|
* @param $untaxedAmount
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<caption class="clearfix">
|
<caption class="clearfix">
|
||||||
{intl l="Taxes rules"}
|
{intl l="Taxes rules"}
|
||||||
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.taxes-rules.create"}
|
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.taxes-rules.create"}
|
||||||
<a class="btn btn-default btn-primary pull-right" title="{intl l='Create a new tax rule'}" href="#creation_dialog" data-toggle="modal">
|
<a class="btn btn-default btn-primary pull-right" title="{intl l='Create a new tax rule'}" href="#tax_rule_create_dialog" data-toggle="modal">
|
||||||
<span class="glyphicon glyphicon-plus"></span>
|
<span class="glyphicon glyphicon-plus"></span>
|
||||||
</a>
|
</a>
|
||||||
{/loop}
|
{/loop}
|
||||||
@@ -73,7 +73,64 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{* -- 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'}
|
||||||
|
<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}">
|
||||||
|
</div>
|
||||||
|
{/form_field}
|
||||||
|
|
||||||
|
{form_field form=$form field='description'}
|
||||||
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
|
<label for="{$label_attr.for}" class="control-label">
|
||||||
|
{intl l=$label} :
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
{/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"}
|
{capture "tax_rule_delete_dialog"}
|
||||||
<input type="hidden" name="tax_rule_id" id="tax_rule_delete_id" value="" />
|
<input type="hidden" name="tax_rule_id" id="tax_rule_delete_id" value="" />
|
||||||
@@ -97,10 +154,15 @@
|
|||||||
|
|
||||||
{block name="javascript-initialization"}
|
{block name="javascript-initialization"}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(".js-delete-tax-rule").click(function(e){
|
|
||||||
$('#tax_rule_delete_id').val($(this).data('id'))
|
{if $taxCreateError == true}
|
||||||
});
|
$('#tax_rule_create_dialog').modal();
|
||||||
</script>
|
{/if}
|
||||||
|
|
||||||
|
$(".js-delete-tax-rule").click(function(e){
|
||||||
|
$('#tax_rule_delete_id').val($(this).data('id'))
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user