diff --git a/core/lib/Thelia/Action/Tax.php b/core/lib/Thelia/Action/Tax.php index 91e51b59f..d17433362 100644 --- a/core/lib/Thelia/Action/Tax.php +++ b/core/lib/Thelia/Action/Tax.php @@ -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); } } diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index a1be6a15d..170c35c4f 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -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); diff --git a/core/lib/Thelia/Controller/Admin/TaxController.php b/core/lib/Thelia/Controller/Admin/TaxController.php index bbaf075cb..e840f2b78 100644 --- a/core/lib/Thelia/Controller/Admin/TaxController.php +++ b/core/lib/Thelia/Controller/Admin/TaxController.php @@ -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; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Tax/TaxEvent.php b/core/lib/Thelia/Core/Event/Tax/TaxEvent.php index 6136630ad..2c6636c06 100644 --- a/core/lib/Thelia/Core/Event/Tax/TaxEvent.php +++ b/core/lib/Thelia/Core/Event/Tax/TaxEvent.php @@ -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; + } } diff --git a/core/lib/Thelia/Core/Form/Type/TheliaType.php b/core/lib/Thelia/Core/Form/Type/TheliaType.php index 7aeeab3e0..550760098 100644 --- a/core/lib/Thelia/Core/Form/Type/TheliaType.php +++ b/core/lib/Thelia/Core/Form/Type/TheliaType.php @@ -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'], )); diff --git a/core/lib/Thelia/Core/Template/Loop/Tax.php b/core/lib/Thelia/Core/Template/Loop/Tax.php index a927a0dbd..724e57342 100644 --- a/core/lib/Thelia/Core/Template/Loop/Tax.php +++ b/core/lib/Thelia/Core/Template/Loop/Tax.php @@ -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')) diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index ee9ef532d..37cc80a92 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -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() - } } diff --git a/core/lib/Thelia/Model/Tools/ModelEventDispatcherTrait.php b/core/lib/Thelia/Model/Tools/ModelEventDispatcherTrait.php index 17af1e44d..e96e2f84c 100644 --- a/core/lib/Thelia/Model/Tools/ModelEventDispatcherTrait.php +++ b/core/lib/Thelia/Model/Tools/ModelEventDispatcherTrait.php @@ -36,7 +36,11 @@ trait ModelEventDispatcherTrait { */ protected $dispatcher = null; - + /** + * @param EventDispatcherInterface $dispatcher + * + * @return $this + */ public function setDispatcher(EventDispatcherInterface $dispatcher) { $this->dispatcher = $dispatcher; diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php deleted file mode 100755 index 8ec254843..000000000 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php +++ /dev/null @@ -1,57 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ -namespace Thelia\TaxEngine\TaxType; - -use Thelia\Type\FloatToFloatArrayType; -use Thelia\Type\ModelValidIdType; - -/** - * - * @author Etienne Roudeix - * - */ -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"; - } -} diff --git a/core/lib/Thelia/Type/BaseType.php b/core/lib/Thelia/Type/BaseType.php index 7ab1a86ec..9beb180e7 100644 --- a/core/lib/Thelia/Type/BaseType.php +++ b/core/lib/Thelia/Type/BaseType.php @@ -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())); } } } diff --git a/templates/admin/default/tax-edit.html b/templates/admin/default/tax-edit.html index 2bb0b260e..1237d6344 100644 --- a/templates/admin/default/tax-edit.html +++ b/templates/admin/default/tax-edit.html @@ -54,7 +54,7 @@ {form_field form=$form field='title'}
- +
{/form_field} @@ -65,7 +65,7 @@ {intl l="The detailed description."} - + {/form_field} @@ -78,27 +78,29 @@
+ + {$typeValue = $value} {/form_field} {form_tagged_fields form=$form tag='requirements'} -
+
{if $formType == 'choice'} - {foreach $choices as $choice} - + {/foreach} {/if} {if $formType == 'text'} - + {/if}
{/form_tagged_fields} @@ -142,7 +144,10 @@