From 89b8a9c1a98b11b2aa8c676599329868a293fc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1ndly=20Gerg=C5=91?= Date: Fri, 21 Mar 2025 17:34:33 +0200 Subject: [PATCH] Added option to include details in the webhook sent to label printers (#2704) * Added option to include details in the webhook sent to label printers * Removed LABEL_PRINTER_INCLUDE_DETAILS flag * Make this actually work * Care about all places where webhooks are used / don't forget recipes --------- Co-authored-by: Bernd Bestel --- controllers/BatteriesApiController.php | 5 +++-- controllers/ChoresApiController.php | 5 +++-- controllers/RecipesApiController.php | 1 + controllers/StockApiController.php | 13 ++++++++----- services/StockService.php | 8 ++++++++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/controllers/BatteriesApiController.php b/controllers/BatteriesApiController.php index b5cd7430..0701ccc2 100644 --- a/controllers/BatteriesApiController.php +++ b/controllers/BatteriesApiController.php @@ -69,11 +69,12 @@ class BatteriesApiController extends BaseApiController { try { - $battery = $this->getDatabase()->batteries()->where('id', $args['batteryId'])->fetch(); + $batteryDetails = (object)$this->getBatteriesService()->GetBatteryDetails($args['batteryId']); $webhookData = array_merge([ - 'battery' => $battery->name, + 'battery' => $batteryDetails->battery->name, 'grocycode' => (string)(new Grocycode(Grocycode::BATTERY, $args['batteryId'])), + 'details' => $batteryDetails, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_LABEL_PRINTER_RUN_SERVER) diff --git a/controllers/ChoresApiController.php b/controllers/ChoresApiController.php index e8a6d2f7..ba4c183e 100644 --- a/controllers/ChoresApiController.php +++ b/controllers/ChoresApiController.php @@ -120,11 +120,12 @@ class ChoresApiController extends BaseApiController { try { - $chore = $this->getDatabase()->chores()->where('id', $args['choreId'])->fetch(); + $choreDetails = (object)$this->getChoresService()->GetChoreDetails($args['choreId']); $webhookData = array_merge([ - 'chore' => $chore->name, + 'chore' => $choreDetails->chore->name, 'grocycode' => (string)(new Grocycode(Grocycode::CHORE, $args['choreId'])), + 'details' => $choreDetails, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_LABEL_PRINTER_RUN_SERVER) diff --git a/controllers/RecipesApiController.php b/controllers/RecipesApiController.php index 36e76020..719a5aae 100644 --- a/controllers/RecipesApiController.php +++ b/controllers/RecipesApiController.php @@ -90,6 +90,7 @@ class RecipesApiController extends BaseApiController $webhookData = array_merge([ 'recipe' => $recipe->name, 'grocycode' => (string)(new Grocycode(Grocycode::RECIPE, $args['recipeId'])), + 'details' => $recipe ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_LABEL_PRINTER_RUN_SERVER) diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php index 27fd5b26..bcbc4080 100644 --- a/controllers/StockApiController.php +++ b/controllers/StockApiController.php @@ -672,11 +672,12 @@ class StockApiController extends BaseApiController { try { - $product = $this->getDatabase()->products()->where('id', $args['productId'])->fetch(); + $productDetails = (object)$this->getStockService()->GetProductDetails($args['productId']); $webhookData = array_merge([ - 'product' => $product->name, - 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $product->id)), + 'product' => $productDetails->product->name, + 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productDetails->product->id)), + 'details' => $productDetails, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_LABEL_PRINTER_RUN_SERVER) @@ -697,11 +698,13 @@ class StockApiController extends BaseApiController try { $stockEntry = $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(); - $product = $this->getDatabase()->products()->where('id', $stockEntry->product_id)->fetch(); + $productDetails = (object)$this->getStockService()->GetProductDetails($stockEntry->product_id); $webhookData = array_merge([ - 'product' => $product->name, + 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id])), + 'details' => $productDetails, + 'stock_entry' => $stockEntry, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) diff --git a/services/StockService.php b/services/StockService.php index 70f2cf24..aba6ef2b 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -227,6 +227,8 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])), + 'details' => $productDetails, + 'stock_entry' => $stockRow, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) @@ -278,6 +280,8 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])), + 'details' => $productDetails, + 'stock_entry' => $stockRow, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) @@ -1009,6 +1013,8 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), + 'details' => $productDetails, + 'stock_entry' => $stockEntry, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) @@ -1321,6 +1327,8 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), + 'details' => $productDetails, + 'stock_entry' => $stockEntry, ], GROCY_LABEL_PRINTER_PARAMS); if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)