Initial commit

This commit is contained in:
2026-10-31 13:24:24 +01:00
commit e6805f2245
87 changed files with 16180 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
<?php
namespace App\Http\Controllers;
use App\Models\Order;
use App\Models\OrderItem;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class CheckoutController extends Controller
{
public function index()
{
$cart = session()->get('cart', []);
if (empty($cart)) {
return redirect()->route('cart.index')->with('error', 'Je winkelwagen is nog leeg.');
}
$subtotal = 0;
foreach ($cart as $item) {
$subtotal += $item['price'] * $item['quantity'];
}
$shipping = $subtotal > 50 ? 0.00 : 4.95;
$total = $subtotal + $shipping;
return view('checkout.index', compact('cart', 'subtotal', 'shipping', 'total'));
}
public function store(Request $request)
{
$cart = session()->get('cart', []);
if (empty($cart)) {
return redirect()->route('cart.index')->with('error', 'Je winkelwagen is leeg.');
}
$validated = $request->validate([
'customer_name' => 'required|string|max:255',
'customer_email' => 'required|email|max:255',
'customer_phone' => 'nullable|string|max:50',
'shipping_street' => 'required|string|max:255',
'shipping_number' => 'required|string|max:50',
'shipping_postal_code' => 'required|string|max:20',
'shipping_city' => 'required|string|max:100',
'notes' => 'nullable|string|max:1000',
'payment_method' => 'required|string|in:ideal,bancontact,overboeking',
]);
$subtotal = 0;
foreach ($cart as $item) {
$subtotal += $item['price'] * $item['quantity'];
}
$shipping = $subtotal > 50 ? 0.00 : 4.95;
$total = $subtotal + $shipping;
$orderNumber = 'J3D-' . date('Y') . '-' . strtoupper(Str::random(6));
$order = Order::create([
'order_number' => $orderNumber,
'customer_name' => $validated['customer_name'],
'customer_email' => $validated['customer_email'],
'customer_phone' => $validated['customer_phone'] ?? null,
'shipping_street' => $validated['shipping_street'],
'shipping_number' => $validated['shipping_number'],
'shipping_postal_code' => $validated['shipping_postal_code'],
'shipping_city' => $validated['shipping_city'],
'shipping_country' => 'Nederland',
'notes' => $validated['notes'] ?? null,
'status' => 'in_behandeling',
'subtotal' => $subtotal,
'shipping_cost' => $shipping,
'total' => $total,
'payment_status' => 'in_afwachting',
'payment_method' => $validated['payment_method'],
]);
foreach ($cart as $item) {
OrderItem::create([
'order_id' => $order->id,
'product_id' => $item['id'],
'product_name' => $item['name'],
'material' => $item['material'] ?? null,
'color' => $item['color'] ?? null,
'scale' => $item['scale'] ?? '100%',
'infill' => $item['infill'] ?? 'Standaard (20%)',
'quantity' => $item['quantity'],
'unit_price' => $item['price'],
'total_price' => $item['price'] * $item['quantity'],
]);
}
// Leeg winkelwagen na succesvolle plaatsing
session()->forget('cart');
return redirect()->route('checkout.success', $order->order_number);
}
public function success($orderNumber)
{
$order = Order::with('items')->where('order_number', $orderNumber)->firstOrFail();
return view('checkout.success', compact('order'));
}
}