From e0cd3a456a9507b6b6d856ed6fc1086ebcf8ca4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Gla=CC=88ser?= Date: Sun, 6 Sep 2026 14:48:59 +0200 Subject: [PATCH] OTC auf Einzelartikel je Produkt begrenzen --- modules/erp/artikel-mapping/service.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/erp/artikel-mapping/service.php b/modules/erp/artikel-mapping/service.php index f22aae8..e09c88f 100644 --- a/modules/erp/artikel-mapping/service.php +++ b/modules/erp/artikel-mapping/service.php @@ -129,10 +129,20 @@ function sellable_item_exists(PDO $pdo, int $sellableItemId): bool function find_sellable_item_for_product(PDO $pdo, int $productId): ?int { $stmt = $pdo->prepare( - 'SELECT sellable_item_id - FROM sellable_item_component - WHERE product_id = :product_id - ORDER BY id + 'SELECT sic.sellable_item_id + FROM sellable_item_component sic + INNER JOIN sellable_item si ON si.id = sic.sellable_item_id + INNER JOIN product p ON p.id = sic.product_id + WHERE sic.product_id = :product_id + AND sic.qty_per_item = 1 + AND si.item_code = p.sku || \'.01\' + AND NOT EXISTS ( + SELECT 1 + FROM sellable_item_component other_sic + WHERE other_sic.sellable_item_id = sic.sellable_item_id + AND other_sic.id <> sic.id + ) + ORDER BY sic.id LIMIT 1' ); $stmt->execute([':product_id' => $productId]);