Files
fotospiel-app/app/Models/PackageAddon.php
Codex Agent d2808ffa4f
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
feat(addons): finalize event addon catalog and ai styling upgrade flow
2026-02-07 12:35:07 +01:00

68 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PackageAddon extends Model
{
use HasFactory;
protected $fillable = [
'key',
'label',
'variant_id',
'extra_photos',
'extra_guests',
'extra_gallery_days',
'active',
'sort',
'metadata',
];
protected $casts = [
'active' => 'boolean',
'metadata' => 'array',
'extra_photos' => 'integer',
'extra_guests' => 'integer',
'extra_gallery_days' => 'integer',
'sort' => 'integer',
];
protected function increments(): Attribute
{
return Attribute::make(
get: fn () => [
'extra_photos' => (int) ($this->extra_photos ?? 0),
'extra_guests' => (int) ($this->extra_guests ?? 0),
'extra_gallery_days' => (int) ($this->extra_gallery_days ?? 0),
],
);
}
public function resolvePaypalPrice(): ?float
{
$metadata = is_array($this->metadata) ? $this->metadata : [];
$price = $metadata['price_eur'] ?? null;
return is_numeric($price) ? (float) $price : null;
}
public function isSellableForProvider(?string $provider = null): bool
{
$provider = strtolower((string) ($provider ?? config('package-addons.provider') ?? config('checkout.default_provider', 'paypal')));
if (! $this->active) {
return false;
}
if ($provider === 'lemonsqueezy') {
return filled($this->variant_id);
}
return $this->resolvePaypalPrice() !== null;
}
}