From 1d5ca5ed64bb6497d7c5562f663aa77337b1e0f0 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 19 Aug 2021 19:56:43 +0200 Subject: [PATCH] Fixed external barcode lookup (plugin) add product handling related to barcodes (fixes #1568) --- services/StockService.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/StockService.php b/services/StockService.php index a01bbe61..5968809e 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -510,10 +510,16 @@ class StockService extends BaseService if ($addFoundProduct === true) { // Add product to database and include new product id in output - $newRow = $this->getDatabase()->products()->createRow($pluginOutput); - $newRow->save(); + $productData = $pluginOutput; + unset($productData['barcode']); + $newProductRow = $this->getDatabase()->products()->createRow($productData); + $newProductRow->save(); + $this->getDatabase()->product_barcodes()->createRow([ + 'product_id' => $newProductRow->id, + 'barcode' => $pluginOutput['barcode'] + ])->save(); - $pluginOutput['id'] = $newRow->id; + $pluginOutput['id'] = $newProductRow->id; } }