From dc73e34f0fc3ecdd5923b6967692ecca33d04582 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 29 Jul 2013 11:07:03 +0200 Subject: [PATCH] add method checking if stock needed is valid or not --- core/lib/Thelia/Model/Product.php | 31 +++++++++++++++++++++++++++++++ install/insert.sql | 1 + 2 files changed, 32 insertions(+) diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 649f315dc..0ea98deea 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -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; + } + } diff --git a/install/insert.sql b/install/insert.sql index 6fe5db6d8..3f1211ba3 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -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());