Fixed minor bug in Currencies

This commit is contained in:
franck
2013-09-03 19:32:57 +02:00
parent 7128739da5
commit 26da884dae
6 changed files with 19 additions and 20 deletions

View File

@@ -60,6 +60,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
->save()
;
$event->setCurrency($currency);
}

View File

@@ -125,10 +125,6 @@ class CurrencyController extends BaseAdminController
catch (\Exception $ex) {
// Any other error
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
var_dump($ex);
exit;
}
if ($error_msg !== false) {

View File

@@ -31,20 +31,20 @@ class CurrencyCreationForm extends BaseForm
{
protected function buildForm($change_mode = false)
{
$name_constraints = array(new Constraints\NotBlank());
$code_constraints = array(new Constraints\NotBlank());
if (!$change_mode) {
$name_constraints[] = new Constraints\Callback(array(
"methods" => array(array($this, "checkDuplicateName"))
$code_constraints[] = new Constraints\Callback(array(
"methods" => array(array($this, "checkDuplicateCode"))
));
}
$this->formBuilder
->add("name" , "text" , array("constraints" => $name_constraints))
->add("name" , "text" , array("constraints" => array(new NotBlank())))
->add("locale" , "text" , array("constraints" => array(new NotBlank())))
->add("symbol" , "text" , array("constraints" => array(new NotBlank())))
->add("rate" , "text" , array("constraints" => array(new NotBlank())))
->add("code" , "text" , array("constraints" => array(new NotBlank())))
->add("code" , "text" , array("constraints" => $code_constraints))
;
}
@@ -53,12 +53,12 @@ class CurrencyCreationForm extends BaseForm
return "thelia_currency_creation";
}
public function checkDuplicateName($value, ExecutionContextInterface $context)
public function checkDuplicateCode($value, ExecutionContextInterface $context)
{
$currency = CurrencyQuery::create()->findOneByName($value);
$currency = CurrencyQuery::create()->findOneByCode($value);
if ($currency) {
$context->addViolation(sprintf("A currency with name \"%s\" already exists.", $value));
$context->addViolation(sprintf("A currency with code \"%s\" already exists.", $value));
}
}