Files
marcoandClaude Sonnet 4.6 9dbc6e7ea1
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s
Release erstellen / build-release (push) Successful in 47s
Add delivery_note field to products for planned delivery info
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 07:17:40 +02:00

51 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Product extends Model
{
protected $fillable = ['category_id','name','slug','description','base_price','sale_price','tax_rate','weight','active','featured','track_stock','sort_order','delivery_note'];
protected $casts = ['active' => 'boolean', 'featured' => 'boolean', 'track_stock' => 'boolean', 'base_price' => 'decimal:2', 'sale_price' => 'decimal:2', 'tax_rate' => 'decimal:2'];
public function isOnSale(): bool
{
return $this->sale_price !== null && (float)$this->sale_price < (float)$this->base_price;
}
public function getEffectivePriceAttribute(): float
{
return $this->isOnSale() ? (float)$this->sale_price : (float)$this->base_price;
}
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function images(): HasMany
{
return $this->hasMany(ProductImage::class)->orderBy('sort_order');
}
public function variants(): HasMany
{
return $this->hasMany(ProductVariant::class);
}
/** Effektiver Bruttopreis (Basispreis, wenn keine Variante gewählt) */
public function getDisplayPriceAttribute(): float
{
return (float) $this->base_price;
}
public function getNetPriceAttribute(): float
{
return round($this->base_price / (1 + $this->tax_rate / 100), 2);
}
}