Added possibility to change the main product reference
This commit is contained in:
committed by
Julien Chanseaume
parent
f37625e5cf
commit
eaad1afdff
@@ -92,7 +92,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
$product
|
||||
->setDispatcher($event->getDispatcher())
|
||||
|
||||
->setRef($event->getRef())
|
||||
->setLocale($event->getLocale())
|
||||
->setTitle($event->getTitle())
|
||||
->setDescription($event->getDescription())
|
||||
|
||||
@@ -158,6 +158,7 @@ class ProductController extends AbstractSeoCrudController
|
||||
|
||||
$changeEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setRef($formData['ref'])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
|
||||
@@ -218,13 +218,13 @@ abstract class BaseController extends ContainerAware
|
||||
if ($form->get("error_message")->getData() != null) {
|
||||
$errorMessage = $form->get("error_message")->getData();
|
||||
} else {
|
||||
$errorMessage = sprintf("Missing or invalid data: %s", $this->getErrorMessages($form));
|
||||
$errorMessage = sprintf($this->getTranslator()->trans("Missing or invalid data: %s"), $this->getErrorMessages($form));
|
||||
}
|
||||
|
||||
throw new FormValidationException($errorMessage);
|
||||
}
|
||||
} else {
|
||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||
throw new FormValidationException(sprintf($this->getTranslator()->trans("Wrong form method, %s expected."), $expectedMethod));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
{$label} :
|
||||
</label>
|
||||
<div class="control-input">
|
||||
{* If ref's 'value is not empty the field is disable and the value is sent with an hidden field *}
|
||||
<input type="text" id="{$label_attr.for}" {if $value}name="{$name}_disabled" disabled{else}name="{$name}"{/if} class="form-control" value="{$value}"{if $required} aria-required="true" required{/if}>
|
||||
{if $value}<input type="hidden" name="{$name}" value="{$value}">{/if}
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}"{if $required} aria-required="true" required{/if}>
|
||||
</div>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
Reference in New Issue
Block a user