Skip to content

Commit

Permalink
Merge pull request #1606 from sigwinhq/fix/range-filter-condition-pro…
Browse files Browse the repository at this point in the history
…cessor-v-2-2

[IndexBundle] Fix range filter to work if min/max value = 0
  • Loading branch information
dpfaffenbauer authored Apr 23, 2021
2 parents 5f3694c + f2d252d commit ffc58a8
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,23 @@ public function prepareValuesForRendering(FilterConditionInterface $condition, F
$minValue = count($rawValues) > 0 ? $rawValues[0]['value'] : 0;
$maxValue = count($rawValues) > 0 ? $rawValues[count($rawValues) - 1]['value'] : 0;

$currentValueMin = $minValue;
if (isset($currentFilter["$field-min"]) && ('' !== (string)$currentFilter["$field-min"]) ) {
$currentValueMin = $currentFilter["$field-min"];
}

$currentValueMax = $maxValue;
if (isset($currentFilter["$field-max"]) && ('' !== (string)$currentFilter["$field-max"]) ) {
$currentValueMax = $currentFilter["$field-max"];
}

return [
'type' => 'range',
'label' => $condition->getLabel(),
'minValue' => $minValue,
'maxValue' => $maxValue,
'currentValueMin' => $currentFilter[$field . '-min'] ? $currentFilter[$field . '-min'] : $minValue,
'currentValueMax' => $currentFilter[$field . '-max'] ? $currentFilter[$field . '-max'] : $maxValue,
'currentValueMin' => $currentValueMin,
'currentValueMax' => $currentValueMax,
'values' => array_values($rawValues),
'fieldName' => $field,
'stepCount' => $condition->getConfiguration()['stepCount'],
Expand All @@ -63,15 +73,15 @@ public function addCondition(FilterConditionInterface $condition, FilterInterfac
$valueMin = $parameterBag->get($field . '-min');
$valueMax = $parameterBag->get($field . '-max');

if (empty($valueMax)) {
if (null === $valueMax) {
$valueMax = $condition->getConfiguration()['preSelectMax'];
}

if ($valueMax === static::EMPTY_STRING) {
$valueMax = null;
}

if (empty($valueMin)) {
if (null === $valueMin) {
$valueMin = $condition->getConfiguration()['preSelectMin'];
}

Expand All @@ -82,7 +92,7 @@ public function addCondition(FilterConditionInterface $condition, FilterInterfac
$currentFilter[$field . '-min'] = $valueMin;
$currentFilter[$field . '-max'] = $valueMax;

if (!empty($valueMin) && !empty($valueMax)) {
if (null !== $valueMin && null !== $valueMax) {
$fieldName = $field;

if ($isPrecondition) {
Expand Down

0 comments on commit ffc58a8

Please sign in to comment.