Bereite Shopify Bestellprojektion vor
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -264,7 +264,8 @@ function allocate_components_for_line(
|
||||
int $lineNo,
|
||||
array $components,
|
||||
float $lineQty,
|
||||
array $locations
|
||||
array $locations,
|
||||
string $movementSource = 'otc-order'
|
||||
): array {
|
||||
if ($components === []) {
|
||||
throw new RuntimeException("Keine Komponenten fuer Verkaufsposition {$lineNo} gefunden");
|
||||
@@ -313,7 +314,7 @@ function allocate_components_for_line(
|
||||
$take,
|
||||
(int) $locations['storage'],
|
||||
(int) $locations['dispatch'],
|
||||
"otc-order:order={$orderId}:line={$lineNo}:product={$productId}"
|
||||
"{$movementSource}:order={$orderId}:line={$lineNo}:product={$productId}"
|
||||
);
|
||||
|
||||
$allocationInsert->execute([
|
||||
@@ -342,10 +343,11 @@ function allocate_line_inventory(
|
||||
int $lineNo,
|
||||
float $lineQty,
|
||||
int $sellableItemId,
|
||||
array $locations
|
||||
array $locations,
|
||||
string $movementSource = 'otc-order'
|
||||
): array {
|
||||
$components = get_item_components($pdo, $sellableItemId);
|
||||
return allocate_components_for_line($pdo, $orderId, $lineId, $lineNo, $components, $lineQty, $locations);
|
||||
return allocate_components_for_line($pdo, $orderId, $lineId, $lineNo, $components, $lineQty, $locations, $movementSource);
|
||||
}
|
||||
|
||||
function allocate_line_inventory_fallback_product(
|
||||
|
||||
Reference in New Issue
Block a user