cart->count() === 0) { return redirect()->route('cart.index')->with('error', 'Ihr Warenkorb ist leer.'); } $subtotal = $this->cart->subtotal(); $shippingRate = ShippingRate::forCart($subtotal); $shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0; $total = $subtotal + $shippingCost; $userAddresses = auth()->user()?->addresses ?? collect(); return view('shop.checkout.index', compact('subtotal', 'shippingCost', 'total', 'userAddresses')); } public function storeAddress(Request $request) { $rules = [ 'billing.first_name' => 'required|string|max:100', 'billing.last_name' => 'required|string|max:100', 'billing.street' => 'required|string|max:255', 'billing.zip' => 'required|string|max:10', 'billing.city' => 'required|string|max:100', 'billing.country' => 'required|string|max:2', 'payment_method' => 'required|in:prepayment,invoice', 'agb' => 'accepted', ]; if (!auth()->check()) { $rules['email'] = 'required|email'; } if ($request->input('shipping_same') !== '1') { $rules['shipping.first_name'] = 'required|string|max:100'; $rules['shipping.last_name'] = 'required|string|max:100'; $rules['shipping.street'] = 'required|string|max:255'; $rules['shipping.zip'] = 'required|string|max:10'; $rules['shipping.city'] = 'required|string|max:100'; $rules['shipping.country'] = 'required|string|max:2'; } $data = $request->validate($rules); if ($request->input('shipping_same') === '1') { $data['shipping'] = $data['billing']; } $data['email'] = $request->input('email'); session(['checkout_data' => $data]); return redirect()->route('checkout.confirm'); } public function payment() { return redirect()->route('checkout.index'); } public function confirm(Request $request) { $checkoutData = session('checkout_data'); if (!$checkoutData || $this->cart->count() === 0) { return redirect()->route('checkout.index'); } if ($request->isMethod('get')) { $items = $this->cart->get(); $subtotal = $this->cart->subtotal(); $shippingRate = ShippingRate::forCart($subtotal); $shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0; $total = $subtotal + $shippingCost; return view('shop.checkout.confirm', compact('checkoutData', 'items', 'subtotal', 'shippingCost', 'total')); } $order = $this->orderService->createFromSession( $checkoutData, $checkoutData['payment_method'] ); session()->forget('checkout_data'); return redirect()->route('checkout.thankyou', $order->order_number); } public function thankyou(string $order) { $order = \App\Models\Order::where('order_number', $order)->firstOrFail(); return view('shop.checkout.thankyou', compact('order')); } }