diff --git a/C4/Letters.pm b/C4/Letters.pm index dfb7b78694..c67a878c43 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1890,6 +1890,7 @@ sub _get_tt_params { }, }; + my $dbh = C4::Context->dbh; foreach my $table ( keys %$tables ) { next unless $config->{$table}; @@ -1910,12 +1911,19 @@ sub _get_tt_params { my $objects = $module->search( { $key => $values }, { - # We want to retrieve the data in the same order - # FIXME MySQLism - # field is a MySQLism, but they are no other way to do it - # To be generic we could do it in perl, but we will need to fetch - # all the data then order them - @$values ? ( order_by => \[ "field($key, " . join( ', ', @$values ) . ")" ] ) : () + # We want to retrieve the data in the same order + # FIXME MySQLism + # field is a MySQLism, but they are no other way to do it + # To be generic we could do it in perl, but we will need to fetch + # all the data then order them + @$values + ? ( + order_by => \[ + sprintf "field(%s, %s)", $key, + join(',', map { $dbh->quote($_) } @$values ) + ] + ) + : () } ); $params->{ $config->{$table}->{plural} } = $objects;