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 = [];
$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)) {