end tax edition
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'],
|
||||
));
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,11 @@ trait ModelEventDispatcherTrait {
|
||||
*/
|
||||
protected $dispatcher = null;
|
||||
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
{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}
|
||||
|
||||
@@ -65,7 +65,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}
|
||||
|
||||
@@ -78,27 +78,29 @@
|
||||
<div class="form-group">
|
||||
<select name="{$name}" class="js-change-tax-type" data-toggle="selectpicker">
|
||||
{foreach $choices as $choice}
|
||||
<option value="{$choice->value}" {if $choice->value == $TYPE}selected="selected" {/if}>{$choice->label}</option>
|
||||
<option value="{$choice->value}" {if !$form_error && $choice->value == $TYPE || $form_error && $choice->value == $value}selected="selected" {/if}>{$choice->label}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{$typeValue = $value}
|
||||
{/form_field}
|
||||
|
||||
{form_tagged_fields form=$form tag='requirements'}
|
||||
<div class="form-group {if $error}has-error{/if} js-tax-requirements" data-tax-type="{$data.tax_type}" {if $data.tax_type != $TYPE}style="display: none"{/if}>
|
||||
<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 != $TYPE || $form_error && $attr_list.tax_type != $typeValue}style="display: none"{/if}>
|
||||
<label for="{$label_attr.for}" class="control-label">
|
||||
{intl l=$label} : {$formType}
|
||||
{intl l=$label}
|
||||
</label>
|
||||
{if $formType == 'choice'}
|
||||
<select name="{$name}">
|
||||
<select name="{$name}" data-toggle="selectpicker" {if !$form_error && $attr_list.tax_type != $TYPE || $form_error && $attr_list.tax_type != $typeValue}disabled="disabled"{/if}>
|
||||
{foreach $choices as $choice}
|
||||
<option value="{$choice->value}" {if $REQUIREMENTS.$label == $choice->value}selected="selected" {/if}>{$choice->label}</option>
|
||||
<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" name="{$name}" value="{$REQUIREMENTS.$label}">
|
||||
<input type="text" {if !$form_error && $attr_list.tax_type != $TYPE || $form_error && $attr_list.tax_type != $typeValue}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}
|
||||
@@ -142,7 +144,10 @@
|
||||
<script>
|
||||
$(function() {
|
||||
$('.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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user