diff --git a/app/Services/EmailTemplateRenderer.php b/app/Services/EmailTemplateRenderer.php index 24b22fb..6c19829 100644 --- a/app/Services/EmailTemplateRenderer.php +++ b/app/Services/EmailTemplateRenderer.php @@ -35,7 +35,15 @@ public function render(array $template, array $ctx): array return $m[0]; } - return (string) data_get($map, $key, ''); + $value = data_get($map, $key, ''); + + // If the resolved value is an array (e.g. {{ contract.meta }} used directly), + // return empty string instead of triggering "Array to string conversion". + if (is_array($value)) { + return ''; + } + + return (string) $value; }, $input); }; @@ -176,8 +184,17 @@ protected function buildMap(array $ctx): array ], ]; $meta = data_get($co, 'meta'); + if (is_string($meta)) { + $meta = json_decode($meta, true) ?? []; + } if (is_array($meta)) { - $out['contract']['meta'] = $meta; + // Flatten meta entries. Supports two formats: + // - Structured: { "sklic": { "value": "...", "type": "string", ... } } → extract 'value' + // - Plain: { "sklic": "..." } → use as-is + $out['contract']['meta'] = array_map( + fn ($item) => (is_array($item) && array_key_exists('value', $item)) ? $item['value'] : $item, + $meta + ); } } if (isset($ctx['activity'])) {