From d8bceda9086f1261d36a3d7ac5e4115e8e4ed101 Mon Sep 17 00:00:00 2001 From: aKorczak Date: Tue, 21 Feb 2012 15:55:38 +0000 Subject: [PATCH] [-] WS : Fixed PSFV-383 git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13510 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Combination.php | 2 +- classes/Validate.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/classes/Combination.php b/classes/Combination.php index e1c85df96..8ee450451 100644 --- a/classes/Combination.php +++ b/classes/Combination.php @@ -65,7 +65,7 @@ class CombinationCore extends ObjectModel 'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13), 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12), 'wholesale_price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'size' => 27), - 'price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'size' => 20), + 'price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isNegativePrice', 'size' => 20), 'ecotax' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'size' => 20), 'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'size' => 10), 'weight' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'), diff --git a/classes/Validate.php b/classes/Validate.php index 33d71d77d..a433a2518 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -233,6 +233,17 @@ class ValidateCore return preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', $price); } + /** + * Check for price validity (including negative price) + * + * @param string $price Price to validate + * @return boolean Validity is ok or not + */ + public static function isNegativePrice($price) + { + return preg_match('/^[-]?[0-9]{1,10}(\.[0-9]{1,9})?$/', $price); + } + /** * Check for language code (ISO) validity *