add method checking if stock needed is valid or not
This commit is contained in:
@@ -3,7 +3,38 @@
|
|||||||
namespace Thelia\Model;
|
namespace Thelia\Model;
|
||||||
|
|
||||||
use Thelia\Model\Base\Product as BaseProduct;
|
use Thelia\Model\Base\Product as BaseProduct;
|
||||||
|
use Thelia\Model\Base\StockQuery;
|
||||||
|
|
||||||
class Product extends BaseProduct {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES
|
||||||
('session_config.default', '1', 1, 1, NOW(), NOW());
|
('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());
|
INSERT INTO `module` (`code`, `type`, `activate`, `position`, `created_at`, `updated_at`) VALUES ('test', '1', '1', '1', NOW(), NOW());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user