feat: add findIntegrationTranslations and upsertIntegrationTranslation to ProductRepository

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 18:13:44 +01:00
parent 86a74bec93
commit 5b64bb872b

View File

@@ -35,7 +35,7 @@ final class ProductRepository
$total = (int) $countStmt->fetchColumn();
$listStmt = $this->pdo->prepare(
'SELECT p.id, p.type, p.sku, p.ean, p.status, p.promoted, p.price_brutto, p.quantity, p.updated_at,
'SELECT p.id, p.type, p.sku, p.ean, p.status, p.promoted, p.price_brutto, p.quantity, p.updated_at, p.created_at,
COALESCE(pt.name, "") AS name,
(
SELECT pi.storage_path
@@ -575,6 +575,7 @@ final class ProductRepository
'quantity' => 'p.quantity',
'status' => 'p.status',
'updated_at' => 'p.updated_at',
'created_at' => 'p.created_at',
default => 'p.id',
};
}
@@ -597,6 +598,7 @@ final class ProductRepository
'price_brutto' => (float) ($row['price_brutto'] ?? 0),
'quantity' => (float) ($row['quantity'] ?? 0),
'updated_at' => (string) ($row['updated_at'] ?? ''),
'created_at' => (string) ($row['created_at'] ?? ''),
];
}
@@ -649,4 +651,66 @@ final class ProductRepository
'id' => $id,
]);
}
/**
* @return array<int, array<string, mixed>>
*/
public function findIntegrationTranslations(int $productId): array
{
$stmt = $this->pdo->prepare(
'SELECT pit.id, pit.product_id, pit.integration_id,
pit.name, pit.short_description, pit.description,
i.name AS integration_name
FROM product_integration_translations pit
INNER JOIN integrations i ON i.id = pit.integration_id
WHERE pit.product_id = :product_id
ORDER BY i.name ASC'
);
$stmt->execute(['product_id' => $productId]);
$rows = $stmt->fetchAll();
if (!is_array($rows)) {
return [];
}
return array_map(static fn (array $row): array => [
'id' => (int) ($row['id'] ?? 0),
'product_id' => (int) ($row['product_id'] ?? 0),
'integration_id' => (int) ($row['integration_id'] ?? 0),
'integration_name' => (string) ($row['integration_name'] ?? ''),
'name' => isset($row['name']) ? (string) $row['name'] : null,
'short_description' => isset($row['short_description']) ? (string) $row['short_description'] : null,
'description' => isset($row['description']) ? (string) $row['description'] : null,
], $rows);
}
public function upsertIntegrationTranslation(
int $productId,
int $integrationId,
?string $name,
?string $shortDescription,
?string $description
): void {
$now = date('Y-m-d H:i:s');
$stmt = $this->pdo->prepare(
'INSERT INTO product_integration_translations
(product_id, integration_id, name, short_description, description, created_at, updated_at)
VALUES
(:product_id, :integration_id, :name, :short_description, :description, :created_at, :updated_at)
ON DUPLICATE KEY UPDATE
name = VALUES(name),
short_description = VALUES(short_description),
description = VALUES(description),
updated_at = VALUES(updated_at)'
);
$stmt->execute([
'product_id' => $productId,
'integration_id' => $integrationId,
'name' => $name !== '' ? $name : null,
'short_description' => $shortDescription !== '' ? $shortDescription : null,
'description' => $description !== '' ? $description : null,
'created_at' => $now,
'updated_at' => $now,
]);
}
}