Enforce Shopify order identifier handoff

This commit is contained in:
2026-08-12 17:53:26 +02:00
parent a6454c733f
commit 727025da88
2 changed files with 14 additions and 4 deletions
@@ -171,13 +171,18 @@ function shopify_projection_stock_check(PDO $pdo, array $resolvedLines): void
} }
} }
function project_shopify_order(PDO $pdo, array $order, array $env, bool $dryRun = true): array function project_shopify_order(PDO $pdo, string $orderGid, callable $orderLoader, bool $dryRun = true): array
{ {
$orderGid = trim((string) ($order['id'] ?? '')); $orderGid = trim($orderGid);
if ($orderGid === '') { if ($orderGid === '') {
throw new RuntimeException('Shopify Order-GID fehlt'); throw new RuntimeException('Shopify Order-GID fehlt');
} }
$order = $orderLoader($orderGid);
if (!is_array($order) || (string) ($order['id'] ?? '') !== $orderGid) {
throw new RuntimeException("Shopify order {$orderGid} konnte nicht geladen werden");
}
$existingStmt = $pdo->prepare('SELECT id FROM sales_order WHERE shopify_order_gid = :shopify_order_gid LIMIT 1'); $existingStmt = $pdo->prepare('SELECT id FROM sales_order WHERE shopify_order_gid = :shopify_order_gid LIMIT 1');
$existingStmt->execute([':shopify_order_gid' => $orderGid]); $existingStmt->execute([':shopify_order_gid' => $orderGid]);
$existingId = $existingStmt->fetchColumn(); $existingId = $existingStmt->fetchColumn();
@@ -126,8 +126,13 @@ function run_shopify_delta(array $env, PDO $pdo, string $cutoff, bool $dryRun):
} }
try { try {
$order = shopify_delta_load_order($env, (string) $summaryOrder['id']); $orderGid = (string) $summaryOrder['id'];
$result = project_shopify_order($pdo, $order, $env, $dryRun); $result = project_shopify_order(
$pdo,
$orderGid,
static fn (string $gid): array => shopify_delta_load_order($env, $gid),
$dryRun
);
if (($result['status'] ?? '') === 'already_imported') { if (($result['status'] ?? '') === 'already_imported') {
$counters['already_imported']++; $counters['already_imported']++;
} else { } else {