verify if coupon code is existing
This commit is contained in:
@@ -23,6 +23,9 @@
|
|||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints;
|
use Symfony\Component\Validator\Constraints;
|
||||||
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
use Thelia\Model\CouponQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CouponCode
|
* Class CouponCode
|
||||||
@@ -44,11 +47,25 @@ class CouponCode extends BaseForm
|
|||||||
"required" => true,
|
"required" => true,
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new Constraints\NotBlank(),
|
new Constraints\NotBlank(),
|
||||||
|
new Constraints\Callback(array(
|
||||||
|
"methods" => array(
|
||||||
|
array($this,
|
||||||
|
"verifyExistingCode")
|
||||||
|
)
|
||||||
|
))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function verifyExistingCode($value, ExecutionContextInterface $context)
|
||||||
|
{
|
||||||
|
$coupon = CouponQuery::create()->findOneByCode($value);
|
||||||
|
if (null === $coupon) {
|
||||||
|
$context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form name
|
* Form name
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user