add method checking if stock needed is valid or not

This commit is contained in:
Manuel Raynaud
2013-07-29 11:07:03 +02:00
parent 67d38c0619
commit dc73e34f0f
2 changed files with 32 additions and 0 deletions

View File

@@ -3,7 +3,38 @@
namespace Thelia\Model;
use Thelia\Model\Base\Product as BaseProduct;
use Thelia\Model\Base\StockQuery;
class Product extends BaseProduct {
public function stockIsValid($value, $combination = null)
{
$isValid = true;
if (ConfigQuery::read("verifyStock", 1) == 1) {
$stock = StockQuery::create()
->filterByProduct($this);
if ($combination) {
$stock->filterByCombinationId($combination);
}
$stock = $stock->findOne();
if ($stock) {
if($stock->getQuantity() < $value) {
$isValid = false;
}
} else {
$isValid = false;
}
}
return $isValid;
}
}