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;
}
}

View File

@@ -6,6 +6,7 @@ INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`created_at`,
INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES
('session_config.default', '1', 1, 1, NOW(), NOW());
('sverifyStock', '1', 1, 0, NOW(), NOW());
INSERT INTO `module` (`code`, `type`, `activate`, `position`, `created_at`, `updated_at`) VALUES ('test', '1', '1', '1', NOW(), NOW());