Bereite Shopify Bestellprojektion vor

This commit is contained in:
2026-08-12 17:42:10 +02:00
parent 0e4c9219bf
commit 6e4925cdb6
3 changed files with 164 additions and 4 deletions
+44
View File
@@ -257,6 +257,50 @@ function resolve_sellable_item_id(PDO $pdo, string $articleNumber, string $title
return ensure_sellable_mapping_from_product_fallback($pdo, $articleNumber, $title);
}
function find_shopify_sellable_item_id(PDO $pdo, string $sku, string $variantGid): ?int
{
$stmt = $pdo->prepare(
"SELECT sellable_item_id
FROM external_item_alias
WHERE source_system = 'shopify'
AND is_active = TRUE
AND (shopify_variant_gid = :variant_gid OR external_article_number = :sku)
ORDER BY CASE WHEN shopify_variant_gid = :sort_variant_gid THEN 0 ELSE 1 END, id
LIMIT 1"
);
$stmt->execute([
':sku' => trim($sku),
':variant_gid' => trim($variantGid),
':sort_variant_gid' => trim($variantGid),
]);
$id = $stmt->fetchColumn();
return $id === false ? null : (int) $id;
}
function bind_shopify_item_identity(PDO $pdo, int $sellableItemId, string $sku, string $productGid, string $variantGid): void
{
$stmt = $pdo->prepare(
"UPDATE external_item_alias
SET shopify_product_gid = :product_gid,
shopify_variant_gid = :variant_gid,
updated_at = NOW()
WHERE source_system = 'shopify'
AND sellable_item_id = :sellable_item_id
AND external_article_number = :sku"
);
$stmt->execute([
':product_gid' => trim($productGid) !== '' ? trim($productGid) : null,
':variant_gid' => trim($variantGid) !== '' ? trim($variantGid) : null,
':sellable_item_id' => $sellableItemId,
':sku' => trim($sku),
]);
if ($stmt->rowCount() !== 1) {
throw new RuntimeException("Kein eindeutiger Shopify-Alias fuer SKU '{$sku}'");
}
}
function get_item_components(PDO $pdo, int $sellableItemId): array
{
$stmt = $pdo->prepare(