add more validation constraints
This commit is contained in:
@@ -27,7 +27,8 @@ use Symfony\Component\Validator\Constraints;
|
|||||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
use Thelia\Action\Exception\StockNotFoundException;
|
use Thelia\Action\Exception\StockNotFoundException;
|
||||||
use Thelia\Action\Exception\ProductNotFoundException;
|
use Thelia\Action\Exception\ProductNotFoundException;
|
||||||
use Thelia\Model\Base\StockQuery;
|
use Thelia\Model\StockQuery;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Model\ProductQuery;
|
use Thelia\Model\ProductQuery;
|
||||||
|
|
||||||
class CartAdd extends BaseForm
|
class CartAdd extends BaseForm
|
||||||
@@ -78,7 +79,7 @@ class CartAdd extends BaseForm
|
|||||||
new Constraints\Callback(array(
|
new Constraints\Callback(array(
|
||||||
"methods" => array($this, "checkStock")
|
"methods" => array($this, "checkStock")
|
||||||
)),
|
)),
|
||||||
new
|
new Constraints\GreaterThanOrEqual(0)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
->add("append", "hidden")
|
->add("append", "hidden")
|
||||||
@@ -90,7 +91,7 @@ class CartAdd extends BaseForm
|
|||||||
{
|
{
|
||||||
$product = ProductQuery::create()->findPk($value);
|
$product = ProductQuery::create()->findPk($value);
|
||||||
|
|
||||||
if (is_null($product)) {
|
if (is_null($product) || $product->getVisible() == 0) {
|
||||||
throw new ProductNotFoundException(sprintf("this product id does not exists : %d", $value));
|
throw new ProductNotFoundException(sprintf("this product id does not exists : %d", $value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,10 +121,9 @@ class CartAdd extends BaseForm
|
|||||||
->filterByProductId($data["product"])
|
->filterByProductId($data["product"])
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
if ($stock->getQuantity() < $value) {
|
if ($stock->getQuantity() < $value && ConfigQuery::read("verifyStock", 1) == 1) {
|
||||||
$context->addViolation("quantity value is not valid");
|
$context->addViolation("quantity value is not valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user