Fix 0 in range filters

This commit is contained in:
Abhishek Kumar
2024-02-28 11:51:19 +05:30
parent 44c0ea95fc
commit 1cd23cf847
4 changed files with 43 additions and 16 deletions

View File

@@ -905,18 +905,25 @@ class AdminControllerCore extends Controller
$sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')';
}
} elseif ($type == 'range') {
if (isset($value[0]) && !empty($value[0])) {
if (!Validate::isUnsignedInt($value[0])) {
// set validation type
if (isset($field['validation']) && $field['validation'] && method_exists('Validate', $field['validation'])) {
$validation = $field['validation'];
} else {
$validation = 'isUnsignedInt';
}
if (isset($value[0]) && ($value[0] !== '' || $value[0] === 0)) {
if (!Validate::$validation($value[0])) {
$this->errors[] = Tools::displayError('The \'From\' value is invalid');
} else {
$sql_filter .= ' AND '.pSQL($key).' >= '.pSQL($value[0]);
}
}
if (isset($value[1]) && !empty($value[1])) {
if (!Validate::isUnsignedInt($value[1])) {
$this->errors[] = Tools::displayError('The \'From\' value is invalid');
} elseif (isset($value[0]) && !empty($value[0]) && $value[0] > $value[1]) {
$this->errors[] = Tools::displayError('The \'To\' value cannot be less than from value');
if (isset($value[1]) && ($value[1] !== '' || $value[1] === 0)) {
if (!Validate::$validation($value[1])) {
$this->errors[] = Tools::displayError('The \'To\' value is invalid');
} elseif ((isset($value[0]) && ($value[0] !== '' || $value[0] === 0)) && $value[0] > $value[1]) {
$this->errors[] = Tools::displayError('The \'To\' value cannot be less than \'From\' value');
} else {
$sql_filter .= ' AND '.pSQL($key).' <= '.pSQL($value[1]);
}