mirror of
https://github.com/grocy/grocy.git
synced 2025-08-13 17:27:23 +00:00
fix: make stockentry grocycodes consume the actual stock entry not the product in general (#1584)
* fix: make stockentry grocycodes consume the actual stock entry not the product in general if the stock_entry_id is in the request body use this instead of the stockentry grocycode this may not be the correct way to interpret this but one of them has to win * Undo formatting changes * fix: add variable definition and reorder args used in ConsumeProduct * Simplify * Fix this also for transferring a product Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
@@ -323,6 +323,18 @@ class StockApiController extends BaseApiController
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||||
|
|
||||||
|
if (Grocycode::Validate($args['barcode']))
|
||||||
|
{
|
||||||
|
$gc = new Grocycode($args['barcode']);
|
||||||
|
if ($gc->GetExtraData())
|
||||||
|
{
|
||||||
|
$requestBody = $request->getParsedBody();
|
||||||
|
$requestBody['stock_entry_id'] = $gc->GetExtraData()[0];
|
||||||
|
$request = $request->withParsedBody($requestBody);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->ConsumeProduct($request, $response, $args);
|
return $this->ConsumeProduct($request, $response, $args);
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
@@ -805,6 +817,18 @@ class StockApiController extends BaseApiController
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||||
|
|
||||||
|
if (Grocycode::Validate($args['barcode']))
|
||||||
|
{
|
||||||
|
$gc = new Grocycode($args['barcode']);
|
||||||
|
if ($gc->GetExtraData())
|
||||||
|
{
|
||||||
|
$requestBody = $request->getParsedBody();
|
||||||
|
$requestBody['stock_entry_id'] = $gc->GetExtraData()[0];
|
||||||
|
$request = $request->withParsedBody($requestBody);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->TransferProduct($request, $response, $args);
|
return $this->TransferProduct($request, $response, $args);
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
|
Reference in New Issue
Block a user