mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Use OFF localized product names if available (closes #2666)
This commit is contained in:
parent
6a7436dbf0
commit
ebcc9a422e
@ -10,7 +10,7 @@
|
||||
|
||||
### Stock
|
||||
|
||||
- xxx
|
||||
- Optimized that the built-in Open Food Facts external barcode lookup plugin now uses the localized product name (if provided by the Open Food Facts API, based on the set Grocy language of the current user)
|
||||
|
||||
### Shopping list
|
||||
|
||||
|
@ -14,8 +14,10 @@ class OpenFoodFactsBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
|
||||
|
||||
protected function ExecuteLookup($barcode)
|
||||
{
|
||||
$productNameFieldLocalized = 'product_name_' . substr(GROCY_LOCALE, 0, 2);
|
||||
|
||||
$webClient = new Client(['http_errors' => false]);
|
||||
$response = $webClient->request('GET', 'https://world.openfoodfacts.org/api/v2/product/' . preg_replace('/[^0-9]/', '', $barcode) . '?fields=product_name,image_url', ['headers' => ['User-Agent' => 'GrocyOpenFoodFactsBarcodeLookupPlugin/1.0 (https://grocy.info)']]);
|
||||
$response = $webClient->request('GET', 'https://world.openfoodfacts.org/api/v2/product/' . preg_replace('/[^0-9]/', '', $barcode) . '?fields=product_name,image_url,' . $productNameFieldLocalized, ['headers' => ['User-Agent' => 'GrocyOpenFoodFactsBarcodeLookupPlugin/1.0 (https://grocy.info)']]);
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
// Guzzle throws exceptions for connection errors, so nothing to do on that here
|
||||
@ -48,8 +50,15 @@ class OpenFoodFactsBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
|
||||
$quId = $this->UserSettings['product_presets_qu_id'];
|
||||
}
|
||||
|
||||
// Use the localized product name, if provided
|
||||
$name = $data->product->product_name;
|
||||
if (isset($data->product->$productNameFieldLocalized))
|
||||
{
|
||||
$name = $data->product->$productNameFieldLocalized;
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => $data->product->product_name,
|
||||
'name' => $name,
|
||||
'location_id' => $locationId,
|
||||
'qu_id_purchase' => $quId,
|
||||
'qu_id_stock' => $quId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user