Add coupons, newsletter, country-based shipping, sale prices, USP bar
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 8s
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 8s
- Gutscheincodes: DB-Verwaltung (%, €-Rabatt, Mindestbestellwert, Ablauf), Eingabefeld im Checkout, Admin unter Marketing → Gutscheine - Newsletter: Double-Opt-In per E-Mail, Formular im Footer, Admin-Liste mit CSV-Export - Länderzonen-Versand: DE / DACH / EU / WORLD, Versandkosten nach Lieferland dynamisch berechnet, Coupon-Rabatt in Bestellung gespeichert - Sale-Preise: sale_price auf Produkten, durchgestrichener UVP auf Produktkarte, Sonderangebote-Sektion auf Startseite - USP-Leiste auf Startseite: Versand, Zahlung, Rückgabe, Service Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Coupon extends Model
|
||||
{
|
||||
protected $fillable = ['code','type','value','min_order_value','expires_at','max_uses','used_count','active'];
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
'expires_at' => 'datetime',
|
||||
'value' => 'decimal:2',
|
||||
'min_order_value' => 'decimal:2',
|
||||
];
|
||||
|
||||
public static function findValid(string $code): ?self
|
||||
{
|
||||
return self::where('code', strtoupper(trim($code)))
|
||||
->where('active', true)
|
||||
->where(fn($q) => $q->whereNull('expires_at')->orWhere('expires_at', '>=', now()))
|
||||
->where(fn($q) => $q->whereNull('max_uses')->orWhereColumn('used_count', '<', 'max_uses'))
|
||||
->first();
|
||||
}
|
||||
|
||||
public function calcDiscount(float $subtotal): float
|
||||
{
|
||||
if ($this->min_order_value && $subtotal < $this->min_order_value) {
|
||||
return 0.0;
|
||||
}
|
||||
if ($this->type === 'percent') {
|
||||
return round($subtotal * $this->value / 100, 2);
|
||||
}
|
||||
return min((float) $this->value, $subtotal);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NewsletterSubscriber extends Model
|
||||
{
|
||||
protected $fillable = ['email','token','confirmed_at'];
|
||||
protected $casts = ['confirmed_at' => 'datetime'];
|
||||
|
||||
public function isConfirmed(): bool
|
||||
{
|
||||
return $this->confirmed_at !== null;
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,14 @@ class Order extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'order_number','user_id','guest_email','status','payment_method',
|
||||
'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',
|
||||
|
||||
+12
-2
@@ -8,9 +8,19 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
protected $fillable = ['category_id','name','slug','description','base_price','tax_rate','weight','active','featured','track_stock','sort_order'];
|
||||
protected $fillable = ['category_id','name','slug','description','base_price','sale_price','tax_rate','weight','active','featured','track_stock','sort_order'];
|
||||
|
||||
protected $casts = ['active' => 'boolean', 'featured' => 'boolean', 'track_stock' => 'boolean', 'base_price' => 'decimal:2', 'tax_rate' => 'decimal:2'];
|
||||
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
|
||||
{
|
||||
|
||||
@@ -10,9 +10,32 @@ class ShippingRate extends Model
|
||||
|
||||
protected $casts = ['active' => 'boolean', 'price' => 'decimal:2', 'free_from' => 'decimal:2'];
|
||||
|
||||
public static function forCart(float $total, string $zone = 'DE'): ?self
|
||||
// Länder → Zonen-Mapping
|
||||
public static array $countryZones = [
|
||||
'DE' => 'DE',
|
||||
'AT' => 'DACH',
|
||||
'CH' => 'DACH',
|
||||
'LI' => 'DACH',
|
||||
'FR' => 'EU', 'NL' => 'EU', 'BE' => 'EU', 'LU' => 'EU',
|
||||
'IT' => 'EU', 'ES' => 'EU', 'PT' => 'EU', 'PL' => 'EU',
|
||||
'CZ' => 'EU', 'SK' => 'EU', 'HU' => 'EU', 'RO' => 'EU',
|
||||
'BG' => 'EU', 'HR' => 'EU', 'SI' => 'EU', 'GR' => 'EU',
|
||||
'DK' => 'EU', 'SE' => 'EU', 'FI' => 'EU', 'EE' => 'EU',
|
||||
'LV' => 'EU', 'LT' => 'EU', 'IE' => 'EU', 'MT' => 'EU',
|
||||
'CY' => 'EU',
|
||||
];
|
||||
|
||||
public static function zoneForCountry(string $country): string
|
||||
{
|
||||
return self::where('zone', $zone)->where('active', true)->first();
|
||||
return self::$countryZones[strtoupper($country)] ?? 'WORLD';
|
||||
}
|
||||
|
||||
public static function forCart(float $total, string $country = 'DE'): ?self
|
||||
{
|
||||
$zone = self::zoneForCountry($country);
|
||||
$rate = self::where('zone', $zone)->where('active', true)->first();
|
||||
// Fallback auf DE wenn keine Zone gefunden
|
||||
return $rate ?? self::where('zone', 'DE')->where('active', true)->first();
|
||||
}
|
||||
|
||||
public function getCostForTotal(float $total): float
|
||||
|
||||
Reference in New Issue
Block a user