Files
WitShop/app/Models/ProductVariant.php
T
marcoandClaude Sonnet 4.6 41078fdc08 Initial commit: WitShop Laravel Online-Shop
- 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>
2026-06-20 00:34:09 +02:00

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(', ');
}
}