Implemented a way to use the external barcode lookup plugin also from within the frontend as a product picker workflow

This commit is contained in:
Bernd Bestel
2023-11-03 20:47:43 +01:00
parent c9215a9a4e
commit 27f9d70b56
11 changed files with 62 additions and 14 deletions

View File

@@ -3,7 +3,7 @@
use Grocy\Helpers\BaseBarcodeLookupPlugin;
/*
This class must extend BaseBarcodeLookupPlugin (in namespace \Grocy\Helpers)
This class must extend BaseBarcodeLookupPlugin (in namespace Grocy\Helpers)
*/
class DemoBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
{
@@ -14,8 +14,11 @@ class DemoBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
/*
To try it:
Call the API function at /api/stock/barcodes/external-lookup/{barcode}
Or use the product picker workflow "External barcode lookup (via plugin)"
When you also add ?add=true as a query parameter to the API call,
on a successful lookup the product is added to the database and in the output
the new product id is included (automatically, nothing to do here in the plugin)
@@ -55,12 +58,14 @@ class DemoBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
*/
protected function ExecuteLookup($barcode)
{
if ($barcode === 'x')
{ // Demonstration when nothing is found
if ($barcode === 'nothing')
{
// Demonstration when nothing is found
return null;
}
elseif ($barcode === 'e')
{ // Demonstration when an error occurred
elseif ($barcode === 'error')
{
// Demonstration when an error occurred
throw new \Exception('This is the error message from the plugin...');
}
else