Add coupons, newsletter, country-based shipping, sale prices, USP bar
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:
2026-06-21 11:07:14 +02:00
co-authored by Claude Sonnet 4.6
parent 5dad8b9324
commit 092dae6085
27 changed files with 782 additions and 51 deletions
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Shop;
use App\Http\Controllers\Controller;
use App\Models\Coupon;
use App\Models\ShippingRate;
use App\Services\CartService;
use App\Services\OrderService;
@@ -21,12 +22,49 @@ class CheckoutController extends Controller
return redirect()->route('cart.index')->with('error', 'Ihr Warenkorb ist leer.');
}
$subtotal = $this->cart->subtotal();
$shippingRate = ShippingRate::forCart($subtotal);
$country = session('checkout_country', 'DE');
$shippingRate = ShippingRate::forCart($subtotal, $country);
$shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0;
$total = $subtotal + $shippingCost;
$discount = $this->getCouponDiscount($subtotal);
$total = max(0, $subtotal - $discount) + $shippingCost;
$userAddresses = auth()->user()?->addresses ?? collect();
$couponCode = session('coupon_code');
return view('shop.checkout.index', compact('subtotal', 'shippingCost', 'total', 'userAddresses'));
return view('shop.checkout.index', compact('subtotal', 'shippingCost', 'total', 'userAddresses', 'discount', 'couponCode'));
}
public function applyCoupon(Request $request)
{
$code = trim($request->input('coupon_code', ''));
if (!$code) {
return back()->with('coupon_error', 'Bitte Gutscheincode eingeben.');
}
$coupon = Coupon::findValid($code);
if (!$coupon) {
return back()->with('coupon_error', 'Gutscheincode ungültig oder abgelaufen.');
}
$subtotal = $this->cart->subtotal();
if ($coupon->min_order_value && $subtotal < $coupon->min_order_value) {
return back()->with('coupon_error', 'Mindestbestellwert von ' . number_format($coupon->min_order_value, 2, ',', '.') . ' € nicht erreicht.');
}
session(['coupon_code' => $coupon->code]);
return back()->with('coupon_success', 'Gutschein "' . $coupon->code . '" angewendet!');
}
public function removeCoupon()
{
session()->forget('coupon_code');
return back()->with('coupon_success', 'Gutschein entfernt.');
}
public function shippingCost(Request $request)
{
$country = strtoupper($request->input('country', 'DE'));
session(['checkout_country' => $country]);
$subtotal = $this->cart->subtotal();
$shippingRate = ShippingRate::forCart($subtotal, $country);
$cost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0;
return response()->json(['cost' => $cost, 'formatted' => number_format($cost, 2, ',', '.') . ' €']);
}
public function storeAddress(Request $request)
@@ -83,10 +121,13 @@ class CheckoutController extends Controller
if ($request->isMethod('get')) {
$items = $this->cart->get();
$subtotal = $this->cart->subtotal();
$shippingRate = ShippingRate::forCart($subtotal);
$country = $checkoutData['shipping']['country'] ?? $checkoutData['billing']['country'] ?? 'DE';
$shippingRate = ShippingRate::forCart($subtotal, $country);
$shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0;
$total = $subtotal + $shippingCost;
return view('shop.checkout.confirm', compact('checkoutData', 'items', 'subtotal', 'shippingCost', 'total'));
$discount = $this->getCouponDiscount($subtotal);
$total = max(0, $subtotal - $discount) + $shippingCost;
$couponCode = session('coupon_code');
return view('shop.checkout.confirm', compact('checkoutData', 'items', 'subtotal', 'shippingCost', 'total', 'discount', 'couponCode'));
}
$order = $this->orderService->createFromSession(
@@ -94,7 +135,7 @@ class CheckoutController extends Controller
$checkoutData['payment_method']
);
session()->forget('checkout_data');
session()->forget(['checkout_data', 'checkout_country']);
return redirect()->route('checkout.thankyou', $order->order_number);
}
@@ -104,4 +145,15 @@ class CheckoutController extends Controller
$order = \App\Models\Order::where('order_number', $order)->firstOrFail();
return view('shop.checkout.thankyou', compact('order'));
}
private function getCouponDiscount(float $subtotal): float
{
if ($code = session('coupon_code')) {
$coupon = Coupon::findValid($code);
if ($coupon) {
return $coupon->calcDiscount($subtotal);
}
}
return 0;
}
}