- Laravel 11, Blade, Alpine.js, Tailwind CSS - Produkt- & Kategorieverwaltung mit Varianten - Checkout (Vorkasse + Rechnung), Session-Warenkorb - Admin-Backend (Dashboard, Bestellungen, Kunden, CMS) - DSGVO-konform: Cookie-Consent, Impressum, Widerruf, AGB - PDF-Rechnung via dompdf, SMTP-Mailversand - Kundenverwaltung mit manueller Freischaltung Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
984 B
PHP
36 lines
984 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class ProductVariant extends Model
|
|
{
|
|
protected $fillable = ['product_id','sku','price_override','stock','stock_warning','active'];
|
|
|
|
protected $casts = ['active' => 'boolean', 'price_override' => 'decimal:2'];
|
|
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function attributeValues(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(AttributeValue::class, 'product_variant_attribute_values')
|
|
->with('attribute');
|
|
}
|
|
|
|
public function getEffectivePriceAttribute(): float
|
|
{
|
|
return (float) ($this->price_override ?? $this->product->base_price);
|
|
}
|
|
|
|
public function getLabelAttribute(): string
|
|
{
|
|
return $this->attributeValues->map(fn($v) => $v->value)->join(', ');
|
|
}
|
|
}
|