Added possibility to change the main product reference
This commit is contained in:
committed by
Julien Chanseaume
parent
f37625e5cf
commit
eaad1afdff
@@ -22,17 +22,15 @@ class ProductCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm($change_mode = false)
|
||||
{
|
||||
$ref_constraints = array(new NotBlank());
|
||||
|
||||
if (! $change_mode) {
|
||||
$ref_constraints[] = new Callback(array(
|
||||
"methods" => array(array($this, "checkDuplicateRef"))
|
||||
));
|
||||
}
|
||||
|
||||
$this->formBuilder
|
||||
->add("ref", "text", array(
|
||||
"constraints" => $ref_constraints,
|
||||
"constraints" => array(
|
||||
new NotBlank(),
|
||||
new Callback(array(
|
||||
"methods" => array(array($this, "checkDuplicateRef"))
|
||||
))
|
||||
),
|
||||
"label" => Translator::getInstance()->trans('Product reference *'),
|
||||
"label_attr" => array("for" => "ref")
|
||||
))
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\ProductQuery;
|
||||
|
||||
class ProductModificationForm extends ProductCreationForm
|
||||
{
|
||||
@@ -49,6 +52,23 @@ class ProductModificationForm extends ProductCreationForm
|
||||
$this->addStandardDescFields(array('title', 'locale'));
|
||||
}
|
||||
|
||||
public function checkDuplicateRef($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
|
||||
$count = ProductQuery::create()
|
||||
->filterById($data['id'], Criteria::NOT_EQUAL)
|
||||
->filterByRef($value)->count();
|
||||
|
||||
if ($count > 0) {
|
||||
$context->addViolation(
|
||||
Translator::getInstance()->trans(
|
||||
"A product with reference %ref already exists. Please choose another reference.",
|
||||
array('%ref' => $value)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_product_modification";
|
||||
|
||||
Reference in New Issue
Block a user