tax rule update and delation
This commit is contained in:
@@ -25,31 +25,27 @@ namespace Thelia\Form;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\CountryQuery;
|
||||
|
||||
class TaxRuleCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
protected function buildForm($change_mode = false)
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("title" , "text" , array(
|
||||
->add("locale", "text", array(
|
||||
"constraints" => array(new NotBlank())
|
||||
))
|
||||
->add("country", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
new Constraints\Callback(
|
||||
array(
|
||||
"methods" => array(
|
||||
array($this, "verifyCountry"),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Title *"),
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
))
|
||||
)
|
||||
->add("locale" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
))
|
||||
)
|
||||
->add("feature_id", "hidden", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
))
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
@@ -57,4 +53,14 @@ class TaxRuleCreationForm extends BaseForm
|
||||
{
|
||||
return "thelia_tax_rule_creation";
|
||||
}
|
||||
|
||||
public function verifyCountry($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$country = CountryQuery::create()
|
||||
->findOneByIsoalpha3($value);
|
||||
|
||||
if (null === $country) {
|
||||
$context->addViolation("Country ISOALPHA3 not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,21 +23,50 @@
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
|
||||
class TaxRuleModificationForm extends FeatureCreationForm
|
||||
class TaxRuleModificationForm extends TaxRuleCreationForm
|
||||
{
|
||||
use StandardDescriptionFieldsTrait;
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
parent::buildForm(true);
|
||||
|
||||
$this->formBuilder
|
||||
->add("id", "hidden", array(
|
||||
"required" => true,
|
||||
"constraints" => array(
|
||||
new GreaterThan(
|
||||
array('value' => 0)
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(
|
||||
array(
|
||||
"methods" => array(
|
||||
array($this, "verifyTaxRuleId"),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
))
|
||||
->add("tab", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Choice(
|
||||
array(
|
||||
'choices' => array('data', 'taxes'),
|
||||
)
|
||||
)
|
||||
),
|
||||
))
|
||||
->add("country", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Callback(
|
||||
array(
|
||||
"methods" => array(
|
||||
array($this, "verifyCountry"),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
))
|
||||
;
|
||||
|
||||
@@ -49,4 +78,14 @@ class TaxRuleModificationForm extends FeatureCreationForm
|
||||
{
|
||||
return "thelia_tax_rule_modification";
|
||||
}
|
||||
|
||||
public function verifyTaxRuleId($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$taxRule = TaxRuleQuery::create()
|
||||
->findPk($value);
|
||||
|
||||
if (null === $taxRule) {
|
||||
$context->addViolation("Tax rule ID not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user