Skip to content

Commit

Permalink
fix: normalize code for /products endpoint #6024 (#6026)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Oct 27, 2021
1 parent b14375d commit 640f6b5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4609,11 +4609,24 @@ sub add_params_to_query($$) {
# xyz=a|b xyz=a,b xyz=a+b products with either xyz a or xyz b

if ($values =~ /\||\+|,/) {
# Multiple values: construct a MongoDB $in query
my @values = split(/\||\+|,/, $values);
$query_ref->{$field} = { '$in' => \@values };
if ($field eq "code") {
# normalize barcodes: add missing leading 0s
$query_ref->{$field} = { '$in' => [ map { normalize_code($_) } @values ] };
}
else {
$query_ref->{$field} = { '$in' => \@values };
}
}
else {
$query_ref->{$field} = $values;
# Single value
if ($field eq "code") {
$query_ref->{$field} = normalize_code($values);
}
else {
$query_ref->{$field} = $values;
}
}
}
}
Expand Down

0 comments on commit 640f6b5

Please sign in to comment.