OTC auf Produkt-ID umstellen
This commit is contained in:
@@ -53,19 +53,19 @@ if ($totalPrice === null || $totalPrice <= 0) {
|
||||
$resolvedProducts = [];
|
||||
$totalQty = 0.0;
|
||||
foreach ($products as $product) {
|
||||
if (!is_array($product) || !isset($product['qty'], $product['title'])) {
|
||||
json_response(422, ['ok' => false, 'error' => 'Product missing title or qty']);
|
||||
if (!is_array($product) || !isset($product['qty'], $product['productId'])) {
|
||||
json_response(422, ['ok' => false, 'error' => 'Product missing productId or qty']);
|
||||
}
|
||||
|
||||
$qty = parse_number($product['qty']);
|
||||
$title = trim((string) $product['title']);
|
||||
if ($qty === null || $qty <= 0 || $title === '') {
|
||||
json_response(422, ['ok' => false, 'error' => 'Invalid product quantity or title']);
|
||||
$productId = (int) $product['productId'];
|
||||
if ($qty === null || $qty <= 0 || $productId <= 0) {
|
||||
json_response(422, ['ok' => false, 'error' => 'Invalid product quantity or productId']);
|
||||
}
|
||||
|
||||
$resolvedProducts[] = [
|
||||
'qty' => (float) $qty,
|
||||
'title' => $title,
|
||||
'productId' => $productId,
|
||||
];
|
||||
$totalQty += (float) $qty;
|
||||
}
|
||||
@@ -105,12 +105,24 @@ try {
|
||||
foreach ($resolvedProducts as $product) {
|
||||
$lineNo++;
|
||||
$qty = (float) $product['qty'];
|
||||
$title = $product['title'];
|
||||
$productId = (int) $product['productId'];
|
||||
|
||||
$resolvedProduct = resolve_otc_product($pdo, $title);
|
||||
$sellableItemId = resolve_sellable_item_id($pdo, '', $title);
|
||||
$productStmt = $pdo->prepare(
|
||||
"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) {
|
||||
throw new RuntimeException("Kein Artikel-Mapping fuer '{$title}' gefunden");
|
||||
throw new RuntimeException("Kein Artikel-Mapping fuer Produkt-ID {$productId} gefunden");
|
||||
}
|
||||
|
||||
if ($lineNo === count($resolvedProducts)) {
|
||||
|
||||
@@ -35,15 +35,7 @@ function get_otc_order_form_products(PDO $pdo): array
|
||||
WHERE p.status = 'active'
|
||||
GROUP BY p.id, p.name
|
||||
HAVING COALESCE(SUM(v.qty_net), 0) > 0
|
||||
ORDER BY
|
||||
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"
|
||||
ORDER BY p.id ASC"
|
||||
);
|
||||
|
||||
$products = [];
|
||||
|
||||
Reference in New Issue
Block a user