fix: export per-integration name/description to shopPRO with global fallback

mapProductPayload() now receives the per-integration translation row for
the target integration. For name, short_description, and description it
uses the integration-specific value when set (non-null), and falls back
to the global product_translations value otherwise.

loadIntegrationTranslation() helper fetches the row from
product_integration_translations for the given product+integration pair.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 19:20:24 +01:00
parent ff5a9cef97
commit a2a7934de6

View File

@@ -94,7 +94,8 @@ final class ShopProExportService
return ['ok' => false, 'message' => 'Produkt nie istnieje.'];
}
$payload = $this->mapProductPayload($product, $baseUrl, $apiKey, $timeout);
$integrationTranslation = $this->loadIntegrationTranslation($productId, $integrationId);
$payload = $this->mapProductPayload($product, $baseUrl, $apiKey, $timeout, $integrationTranslation);
$customFieldsPayload = $this->mapCustomFieldsPayload($product['custom_fields_json'] ?? null);
if (($customFieldsPayload['include'] ?? false) === true) {
$payload['custom_fields'] = $customFieldsPayload['fields'] ?? [];
@@ -337,11 +338,12 @@ final class ShopProExportService
/**
* @param array<string, mixed> $product
* @param array<string, mixed>|null $integrationTranslation Per-integration overrides (null fields = use global)
* @return array<string, mixed>
*/
private function mapProductPayload(array $product, string $baseUrl, string $apiKey, int $timeout): array
private function mapProductPayload(array $product, string $baseUrl, string $apiKey, int $timeout, ?array $integrationTranslation = null): array
{
$name = trim((string) ($product['name'] ?? ''));
$name = trim((string) ($integrationTranslation['name'] ?? $product['name'] ?? ''));
if ($name === '') {
$name = 'orderPRO #' . (int) ($product['id'] ?? 0);
}
@@ -366,8 +368,8 @@ final class ShopProExportService
'languages' => [
'pl' => [
'name' => $name,
'short_description' => $this->nullableText($product['short_description'] ?? null),
'description' => $this->nullableText($product['description'] ?? null),
'short_description' => $this->nullableText($integrationTranslation['short_description'] ?? $product['short_description'] ?? null),
'description' => $this->nullableText($integrationTranslation['description'] ?? $product['description'] ?? null),
'meta_title' => $this->nullableText($product['meta_title'] ?? null),
'meta_description' => $this->nullableText($product['meta_description'] ?? null),
'meta_keywords' => $this->nullableText($product['meta_keywords'] ?? null),
@@ -378,6 +380,24 @@ final class ShopProExportService
];
}
/**
* Returns the per-integration translation row for a product+integration pair, or null if none exists.
*/
private function loadIntegrationTranslation(int $productId, int $integrationId): ?array
{
if ($integrationId <= 0) {
return null;
}
foreach ($this->products->findIntegrationTranslations($productId) as $row) {
if ((int) ($row['integration_id'] ?? 0) === $integrationId) {
return $row;
}
}
return null;
}
/**
* Dopasowuje producenta po nazwie i zwraca ID producenta po stronie shopPRO.
*/