OTC auf Produkt-ID umstellen

This commit is contained in:
2026-06-15 14:05:29 +02:00
parent 82387690dc
commit fb812e147e
3 changed files with 24 additions and 20 deletions
+22 -10
View File
@@ -53,19 +53,19 @@ if ($totalPrice === null || $totalPrice <= 0) {
$resolvedProducts = []; $resolvedProducts = [];
$totalQty = 0.0; $totalQty = 0.0;
foreach ($products as $product) { foreach ($products as $product) {
if (!is_array($product) || !isset($product['qty'], $product['title'])) { if (!is_array($product) || !isset($product['qty'], $product['productId'])) {
json_response(422, ['ok' => false, 'error' => 'Product missing title or qty']); json_response(422, ['ok' => false, 'error' => 'Product missing productId or qty']);
} }
$qty = parse_number($product['qty']); $qty = parse_number($product['qty']);
$title = trim((string) $product['title']); $productId = (int) $product['productId'];
if ($qty === null || $qty <= 0 || $title === '') { if ($qty === null || $qty <= 0 || $productId <= 0) {
json_response(422, ['ok' => false, 'error' => 'Invalid product quantity or title']); json_response(422, ['ok' => false, 'error' => 'Invalid product quantity or productId']);
} }
$resolvedProducts[] = [ $resolvedProducts[] = [
'qty' => (float) $qty, 'qty' => (float) $qty,
'title' => $title, 'productId' => $productId,
]; ];
$totalQty += (float) $qty; $totalQty += (float) $qty;
} }
@@ -105,12 +105,24 @@ try {
foreach ($resolvedProducts as $product) { foreach ($resolvedProducts as $product) {
$lineNo++; $lineNo++;
$qty = (float) $product['qty']; $qty = (float) $product['qty'];
$title = $product['title']; $productId = (int) $product['productId'];
$resolvedProduct = resolve_otc_product($pdo, $title); $productStmt = $pdo->prepare(
$sellableItemId = resolve_sellable_item_id($pdo, '', $title); "SELECT id, sku, name
FROM product
WHERE id = :id
AND status = 'active'
LIMIT 1"
);
$productStmt->execute([':id' => $productId]);
$resolvedProduct = $productStmt->fetch();
if (!is_array($resolvedProduct)) {
throw new RuntimeException("Kein aktives ERP-Produkt fuer Produkt-ID {$productId} gefunden");
}
$sellableItemId = find_sellable_item_for_product($pdo, $productId);
if ($sellableItemId === null) { if ($sellableItemId === null) {
throw new RuntimeException("Kein Artikel-Mapping fuer '{$title}' gefunden"); throw new RuntimeException("Kein Artikel-Mapping fuer Produkt-ID {$productId} gefunden");
} }
if ($lineNo === count($resolvedProducts)) { if ($lineNo === count($resolvedProducts)) {
+1 -9
View File
@@ -35,15 +35,7 @@ function get_otc_order_form_products(PDO $pdo): array
WHERE p.status = 'active' WHERE p.status = 'active'
GROUP BY p.id, p.name GROUP BY p.id, p.name
HAVING COALESCE(SUM(v.qty_net), 0) > 0 HAVING COALESCE(SUM(v.qty_net), 0) > 0
ORDER BY ORDER BY p.id ASC"
CASE
WHEN p.name ILIKE '%shiitake%' THEN 1
WHEN p.name ILIKE '%reishi%' THEN 2
WHEN p.name ILIKE '%lion''s mane%' THEN 3
WHEN p.name ILIKE '%chaga%' THEN 4
ELSE 99
END,
p.id ASC"
); );
$products = []; $products = [];
+1 -1
View File
@@ -438,7 +438,7 @@ function render_auth_home_page(array $user, array $otcProducts = []): void
echo " if (!updateFormState()) { return; }"; echo " if (!updateFormState()) { return; }";
echo " const products = productInputs"; echo " const products = productInputs";
echo " .filter((input) => getInputValue(input) > 0)"; echo " .filter((input) => getInputValue(input) > 0)";
echo " .map((input) => ({ title: input.dataset.title, qty: getInputValue(input) }));"; echo " .map((input) => ({ productId: parseInt(input.dataset.productId || '0', 10), qty: getInputValue(input) }));";
echo " const orderData = {"; echo " const orderData = {";
echo " products: products,"; echo " products: products,";
echo " totalPrice: parseFloat(totalPriceInput.value || '0') || 0,"; echo " totalPrice: parseFloat(totalPriceInput.value || '0') || 0,";