Skip to content

Commit

Permalink
feat: example product in API with code=example - #6250 (#6252)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet authored Jan 6, 2022
1 parent d71eee3 commit c0605a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1346,4 +1346,10 @@ $options{import_sources} = {
'database-usda' => "USDA Global Branded Food Products Database",
};

# Barcode of a sample product returned through the API when the requested code is "example"
$options{sample_product_code} = "80135463"; # Nutella
$options{sample_product_code_country_uk} = "5060042641000"; # Tyrrell's lighty salted chips
$options{sample_product_code_language_de} = "20884680"; # Waffeln Sondey
$options{sample_product_code_country_at_language_de} = "5411188119098"; # Natur miss kokosnuss Alpro

1;
10 changes: 10 additions & 0 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10144,6 +10144,16 @@ sub display_product_api($) {

my $request_ref = shift;

# Is a sample product requested?
if ((defined $request_ref->{code}) and ($request_ref->{code} eq "example")) {

$request_ref->{code} = $options{"sample_product_code_country_${cc}_language_${lc}"}
|| $options{"sample_product_code_country_${cc}"}
|| $options{"sample_product_code_language_${lc}"}
|| $options{"sample_product_code"}
|| "";
}

my $code = normalize_code($request_ref->{code});
my $product_id = product_id_for_owner($Owner_id, $code);

Expand Down

0 comments on commit c0605a4

Please sign in to comment.