tax rule creation

This commit is contained in:
Etienne Roudeix
2013-10-11 13:51:30 +02:00
parent 2c88471ef3
commit c84e451a12
8 changed files with 111 additions and 37 deletions

View File

@@ -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())

View File

@@ -115,6 +115,7 @@
<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.add" class="Thelia\Form\TaxRuleCreationForm"/>
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>

View File

@@ -798,6 +798,10 @@
<requirement key="tax_rule_id">\d+</requirement>
</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">
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::processUpdateAction</default>
</route>

View File

@@ -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(

View File

@@ -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()

View File

@@ -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()

View File

@@ -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