From 640f6b5420a179221914493afab2ad4d89cfb383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Wed, 27 Oct 2021 11:06:14 +0200 Subject: [PATCH] fix: normalize code for /products endpoint #6024 (#6026) --- lib/ProductOpener/Display.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/ProductOpener/Display.pm b/lib/ProductOpener/Display.pm index b6362dff2afc3..31af4927e19ce 100644 --- a/lib/ProductOpener/Display.pm +++ b/lib/ProductOpener/Display.pm @@ -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; + } } } }