mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user