diff --git a/classes/CartRule.php b/classes/CartRule.php index bb6967a98..2b8d32f09 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -97,7 +97,7 @@ class CartRuleCore extends ObjectModel 'product_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'shop_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'free_shipping' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), - 'reduction_percent' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), + 'reduction_percent' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPercentage'), 'reduction_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), 'reduction_tax' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'reduction_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), diff --git a/classes/Referrer.php b/classes/Referrer.php index 3bdb67e6c..b1bcf4c09 100644 --- a/classes/Referrer.php +++ b/classes/Referrer.php @@ -64,7 +64,7 @@ class ReferrerCore extends ObjectModel 'http_referer_like_not' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml'), 'request_uri_like_not' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml'), 'base_fee' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), - 'percent_fee' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), + 'percent_fee' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPercentage'), 'click_fee' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), diff --git a/classes/Risk.php b/classes/Risk.php index f8cb58d94..d5d740692 100644 --- a/classes/Risk.php +++ b/classes/Risk.php @@ -42,7 +42,7 @@ class RiskCore extends ObjectModel 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString', 'required' => true, 'size' => 20), 'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor', 'size' => 32), - 'percent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt') + 'percent' => array('type' => self::TYPE_INT, 'validate' => 'isPercentage') ), ); diff --git a/classes/Validate.php b/classes/Validate.php index 049be4ef6..665e1afae 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -622,7 +622,7 @@ class ValidateCore /** * Check for an integer validity * - * @param integer $id Integer to validate + * @param integer $value Integer to validate * @return boolean Validity is ok or not */ public static function isInt($value) @@ -633,13 +633,24 @@ class ValidateCore /** * Check for an integer validity (unsigned) * - * @param integer $id Integer to validate + * @param integer $value Integer to validate * @return boolean Validity is ok or not */ public static function isUnsignedInt($value) { return (preg_match('#^[0-9]+$#', (string)$value) && $value < 4294967296 && $value >= 0); } + + /** + * Check for an percentage validity (between 0 and 100) + * + * @param float $value Float to validate + * @return boolean Validity is ok or not + */ + public static function isPercentage($value) + { + return (Validate::isFloat($value) && $value >= 0 && $value <= 100); + } /** * Check for an integer validity (unsigned)