feat(addons): finalize event addon catalog and ai styling upgrade flow
This commit is contained in:
@@ -17,18 +17,43 @@ class EventAddonCatalog
|
||||
->orderBy('sort')
|
||||
->get()
|
||||
->mapWithKeys(function (PackageAddon $addon) {
|
||||
$metadata = $this->normalizeMetadata($addon->metadata);
|
||||
|
||||
return [$addon->key => [
|
||||
'label' => $addon->label,
|
||||
'variant_id' => $addon->variant_id,
|
||||
'increments' => $addon->increments,
|
||||
'price' => $this->resolveMetadataPrice($addon->metadata ?? []),
|
||||
'price' => $addon->resolvePaypalPrice(),
|
||||
'currency' => 'EUR',
|
||||
'metadata' => $metadata,
|
||||
]];
|
||||
})
|
||||
->all();
|
||||
|
||||
// Fallback to config and merge (DB wins)
|
||||
$configAddons = config('package-addons', []);
|
||||
$configAddons = collect((array) config('package-addons', []))
|
||||
->filter(static fn (mixed $addon): bool => is_array($addon))
|
||||
->map(function (array $addon): array {
|
||||
$metadata = $this->normalizeMetadata($addon['metadata'] ?? []);
|
||||
|
||||
if (! isset($metadata['scope']) && is_string($addon['scope'] ?? null) && trim((string) $addon['scope']) !== '') {
|
||||
$metadata['scope'] = trim((string) $addon['scope']);
|
||||
}
|
||||
|
||||
if (! isset($metadata['entitlements']) && is_array($addon['entitlements'] ?? null)) {
|
||||
$metadata['entitlements'] = $addon['entitlements'];
|
||||
}
|
||||
|
||||
return [
|
||||
'label' => $addon['label'] ?? null,
|
||||
'variant_id' => $addon['variant_id'] ?? null,
|
||||
'increments' => Arr::get($addon, 'increments', []),
|
||||
'price' => $this->resolveConfiguredPrice($addon),
|
||||
'currency' => $addon['currency'] ?? 'EUR',
|
||||
'metadata' => $metadata,
|
||||
];
|
||||
})
|
||||
->all();
|
||||
|
||||
return array_merge($configAddons, $dbAddons);
|
||||
}
|
||||
@@ -61,13 +86,29 @@ class EventAddonCatalog
|
||||
return is_numeric($price) ? (float) $price : null;
|
||||
}
|
||||
|
||||
protected function resolveMetadataPrice(array $metadata): ?float
|
||||
protected function resolveConfiguredPrice(array $addon): ?float
|
||||
{
|
||||
$price = $metadata['price_eur'] ?? null;
|
||||
$price = $addon['price'] ?? $addon['price_eur'] ?? null;
|
||||
|
||||
return is_numeric($price) ? (float) $price : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function normalizeMetadata(mixed $metadata): array
|
||||
{
|
||||
if (is_string($metadata)) {
|
||||
$decoded = json_decode($metadata, true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$metadata = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
return is_array($metadata) ? $metadata : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user