Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s
- PayPal: Checkout-Integration via srmklive/paypal, Weiterleitung zu PayPal, Bestellung wird nach Capture automatisch auf payment_received gesetzt - Stripe: Payment Elements im Checkout, Intent-API, Zahlung direkt bestätigt - CSV-Export: Admin → Bestellungen → CSV exportieren (UTF-8 BOM für Excel) - PayPal/Stripe nur sichtbar wenn Keys in .env gesetzt - .env.example um PAYPAL_* und STRIPE_* Keys erweitert Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Order extends Model
|
|
{
|
|
protected $fillable = [
|
|
'order_number','user_id','guest_email','status','payment_method','payment_id',
|
|
'coupon_code','discount_amount',
|
|
'subtotal','tax_total','shipping_cost','total','tracking_code','notes','paid_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'paid_at' => 'datetime',
|
|
'subtotal' => 'decimal:2',
|
|
'discount_amount' => 'decimal:2',
|
|
'tax_total' => 'decimal:2',
|
|
'shipping_cost' => 'decimal:2',
|
|
'total' => 'decimal:2',
|
|
];
|
|
|
|
public static array $statusLabels = [
|
|
'new' => 'Neu',
|
|
'payment_received' => 'Zahlung eingegangen',
|
|
'processing' => 'In Bearbeitung',
|
|
'shipped' => 'Versendet',
|
|
'completed' => 'Abgeschlossen',
|
|
'cancelled' => 'Storniert',
|
|
];
|
|
|
|
public static array $paymentLabels = [
|
|
'prepayment' => 'Vorkasse',
|
|
'invoice' => 'Rechnung',
|
|
'paypal' => 'PayPal',
|
|
'stripe' => 'Kreditkarte (Stripe)',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(OrderItem::class);
|
|
}
|
|
|
|
public function addresses(): HasMany
|
|
{
|
|
return $this->hasMany(OrderAddress::class);
|
|
}
|
|
|
|
public function billingAddress()
|
|
{
|
|
return $this->addresses()->where('type', 'billing')->first();
|
|
}
|
|
|
|
public function shippingAddress()
|
|
{
|
|
return $this->addresses()->where('type', 'shipping')->first();
|
|
}
|
|
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return self::$statusLabels[$this->status] ?? $this->status;
|
|
}
|
|
|
|
public function getPaymentLabelAttribute(): string
|
|
{
|
|
return self::$paymentLabels[$this->payment_method] ?? $this->payment_method;
|
|
}
|
|
|
|
public static function generateOrderNumber(): string
|
|
{
|
|
return 'ORD-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -5));
|
|
}
|
|
}
|