end tax edition

This commit is contained in:
Etienne Roudeix
2013-10-17 11:53:26 +02:00
parent a2048bec24
commit dad2591a57
11 changed files with 58 additions and 93 deletions

View File

@@ -61,6 +61,7 @@ class Tax extends BaseAction implements EventSubscriberInterface
$tax
->setDispatcher($this->getDispatcher())
->setRequirements($event->getRequirements())
->setType($event->getType())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
@@ -68,8 +69,6 @@ class Tax extends BaseAction implements EventSubscriberInterface
->save()
;
$event->setTax($tax);
}
}

View File

@@ -392,8 +392,6 @@ abstract class AbstractCrudController extends BaseAdminController
// Get the form field values
$data = $form->getData();
$dataType = $form->all();
$changeEvent = $this->getUpdateEvent($data);
$this->dispatch($this->updateEventIdentifier, $changeEvent);

View File

@@ -76,16 +76,12 @@ class TaxController extends AbstractCrudController
{
$event = new TaxEvent();
/* check the requirements */
if(!$this->checkRequirements($formData)) {
}
$event->setLocale($formData['locale']);
$event->setId($formData['id']);
$event->setTitle($formData['title']);
$event->setDescription($formData['description']);
$event->setType($formData['type']);
$event->setRequirements($this->getRequirements($formData['type'], $formData));
return $event;
}
@@ -207,4 +203,24 @@ class TaxController extends AbstractCrudController
}
protected function getRequirements($type, $formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
continue;
}
$couple = explode(':', $data);
if(count($couple) != 2 || $couple[0] != $type) {
continue;
}
$requirements[$couple[1]] = $value;
}
return $requirements;
}
}

View File

@@ -34,6 +34,7 @@ class TaxEvent extends ActionEvent
protected $title;
protected $description;
protected $type;
protected $requirements;
public function __construct(Tax $tax = null)
{
@@ -106,4 +107,14 @@ class TaxEvent extends ActionEvent
{
return $this->type;
}
public function setRequirements($requirements)
{
$this->requirements = $requirements;
}
public function getRequirements()
{
return $this->requirements;
}
}

View File

@@ -11,13 +11,13 @@ class TheliaType extends AbstractType
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'instance' => false,
//'instance' => false,
'type' => false,
'options' => false,
));
$resolver->setAllowedTypes(array(
'instance' => array('Thelia\Type\TypeInterface'),
//'instance' => array('Thelia\Type\TypeInterface'),
));
$resolver->setAllowedValues(array(
@@ -31,7 +31,7 @@ class TheliaType extends AbstractType
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars = array_replace($view->vars, array(
'instance' => $options['instance'],
//'instance' => $options['instance'],
'type' => $options['type'],
'options' => $options['options'],
));

View File

@@ -151,12 +151,10 @@ class Tax extends BaseI18nLoop
$loopResultRow = new LoopResultRow($loopResult, $tax, $this->versionable, $this->timestampable, $this->countable);
$requirements = json_decode( base64_decode( $tax->getSerializedRequirements() ), true );
$loopResultRow
->set("ID" , $tax->getId())
->set("TYPE" , $tax->getType())
->set("REQUIREMENTS" , $requirements)
->set("REQUIREMENTS" , $tax->getRequirements())
->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale)
->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE'))

View File

@@ -64,8 +64,8 @@ class TaxCreationForm extends BaseForm
foreach($requirementList as $type => $requirements) {
foreach($requirements as $name => $requirementType) {
$this->formBuilder
->add($type . '_' . $name, new TheliaType(), array(
"instance" => $requirementType,
->add($type . ':' . $name, new TheliaType(), array(
//"instance" => $requirementType,
"constraints" => array(
new Constraints\Callback(
array(
@@ -77,8 +77,6 @@ class TaxCreationForm extends BaseForm
),
"attr" => array(
"tag" => "requirements",
),
"data" => array(
"tax_type" => $type,
),
"label" => Translator::getInstance()->trans($name),
@@ -96,11 +94,4 @@ class TaxCreationForm extends BaseForm
{
return "thelia_tax_creation";
}
public function verifyForm($value, ExecutionContextInterface $context)
{
$in = true;
//$this->getForm()->getChildren()
}
}

View File

@@ -36,7 +36,11 @@ trait ModelEventDispatcherTrait {
*/
protected $dispatcher = null;
/**
* @param EventDispatcherInterface $dispatcher
*
* @return $this
*/
public function setDispatcher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;

View File

@@ -1,57 +0,0 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\TaxEngine\TaxType;
use Thelia\Type\FloatToFloatArrayType;
use Thelia\Type\ModelValidIdType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class featureSlicePercentTaxType extends BaseTaxType
{
public function pricePercentRetriever()
{
}
public function fixAmountRetriever(\Thelia\Model\Product $product)
{
}
public function getRequirementsList()
{
return array(
'featureId' => new ModelValidIdType('Feature'),
'slices' => new FloatToFloatArrayType(),
);
}
public function getTitle()
{
return "% slice Tax depending on a feature";
}
}

View File

@@ -40,7 +40,7 @@ abstract class BaseType implements TypeInterface
public function verifyForm($value, ExecutionContextInterface $context)
{
if( ! $this->isValid($value) ) {
$context->addViolation("Thelia Type not matched");
$context->addViolation(sprintf("received value `%s` does not match `%s` type", $value, $this->getType()));
}
}
}