Files
WitShop/app/Models/ShippingRate.php
T
marcoandClaude Sonnet 4.6 092dae6085
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 8s
Add coupons, newsletter, country-based shipping, sale prices, USP bar
- 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>
2026-06-21 11:07:14 +02:00

49 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ShippingRate extends Model
{
protected $fillable = ['name','zone','price','free_from','active'];
protected $casts = ['active' => 'boolean', 'price' => 'decimal:2', 'free_from' => 'decimal:2'];
// 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::$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
{
if ($this->free_from !== null && $total >= (float) $this->free_from) {
return 0.0;
}
return (float) $this->price;
}
}