Refine design (less clunky, fully mobile-friendly), seed only Fidget Toys, Pokemon & Film popculture, and add direct custom model ordering
This commit is contained in:
@@ -89,6 +89,80 @@ class CartController extends Controller
|
||||
return redirect()->route('cart.index')->with('success', "{$product->name} is toegevoegd aan je winkelwagen!");
|
||||
}
|
||||
|
||||
public function addCustom(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'model_name' => 'nullable|string|max:255',
|
||||
'model_url' => 'nullable|url|max:1000',
|
||||
'model_file' => 'nullable|file|max:51200', // 50MB
|
||||
'size' => 'required|in:klein,medium,groot',
|
||||
'material' => 'required|string',
|
||||
'color' => 'required|string',
|
||||
'infill' => 'nullable|string',
|
||||
'notes' => 'nullable|string|max:1000',
|
||||
'quantity' => 'required|integer|min:1|max:20',
|
||||
]);
|
||||
|
||||
if (! $request->hasFile('model_file') && empty($validated['model_url'])) {
|
||||
return back()->withInput()->with('error', 'Upload een 3D-bestand (.stl, .3mf, .obj, .step) of vul een MakerWorld/Printables link in.');
|
||||
}
|
||||
|
||||
$filePath = null;
|
||||
$originalName = null;
|
||||
if ($request->hasFile('model_file')) {
|
||||
$file = $request->file('model_file');
|
||||
$originalName = $file->getClientOriginalName();
|
||||
$filePath = $file->store('custom_models', 'public');
|
||||
}
|
||||
|
||||
$material = Material::where('code', $validated['material'])->first();
|
||||
|
||||
// Basisprijs op basis van formaat
|
||||
$sizePrices = [
|
||||
'klein' => 9.95, // tot 8 cm
|
||||
'medium' => 16.95, // tot 15 cm
|
||||
'groot' => 24.95, // tot 22 cm
|
||||
];
|
||||
$unitPrice = $sizePrices[$validated['size']] ?? 16.95;
|
||||
|
||||
if ($material) {
|
||||
$unitPrice *= $material->price_multiplier;
|
||||
}
|
||||
|
||||
$unitPrice = round($unitPrice, 2);
|
||||
|
||||
$name = ! empty($validated['model_name'])
|
||||
? $validated['model_name']
|
||||
: ($originalName ?: 'Eigen 3D Model');
|
||||
|
||||
$cartKey = md5('custom_'.($filePath ?: ($validated['model_url'] ?? '')).'_'.$validated['material'].'_'.$validated['color'].'_'.$validated['size']);
|
||||
|
||||
$cart = session()->get('cart', []);
|
||||
|
||||
$cart[$cartKey] = [
|
||||
'id' => null,
|
||||
'is_custom' => true,
|
||||
'name' => 'Custom Print: '.$name,
|
||||
'slug' => 'custom-3d-print',
|
||||
'image_url' => 'https://images.unsplash.com/photo-1581092160607-ee22621dd758?auto=format&fit=crop&w=400&q=80',
|
||||
'material' => $material ? $material->name : $validated['material'],
|
||||
'material_code' => $validated['material'],
|
||||
'color' => $validated['color'],
|
||||
'scale' => ucfirst($validated['size']),
|
||||
'infill' => $validated['infill'] ?? 'Standaard (20%)',
|
||||
'price' => $unitPrice,
|
||||
'quantity' => (int) $validated['quantity'],
|
||||
'custom_file_path' => $filePath,
|
||||
'custom_file_name' => $originalName,
|
||||
'custom_model_url' => $validated['model_url'] ?? null,
|
||||
'custom_notes' => $validated['notes'] ?? null,
|
||||
];
|
||||
|
||||
session()->put('cart', $cart);
|
||||
|
||||
return redirect()->route('cart.index')->with('success', "Jouw eigen 3D model '{$name}' is direct toegevoegd aan je winkelwagen!");
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
|
||||
@@ -78,10 +78,18 @@ class CheckoutController extends Controller
|
||||
]);
|
||||
|
||||
foreach ($cart as $item) {
|
||||
$productName = $item['name'];
|
||||
if (! empty($item['custom_model_url'])) {
|
||||
$productName .= ' (Link: '.$item['custom_model_url'].')';
|
||||
}
|
||||
if (! empty($item['custom_file_name'])) {
|
||||
$productName .= ' [Bestand: '.$item['custom_file_name'].']';
|
||||
}
|
||||
|
||||
OrderItem::create([
|
||||
'order_id' => $order->id,
|
||||
'product_id' => $item['id'],
|
||||
'product_name' => $item['name'],
|
||||
'product_id' => $item['id'] ?? null,
|
||||
'product_name' => $productName,
|
||||
'material' => $item['material'] ?? null,
|
||||
'color' => $item['color'] ?? null,
|
||||
'scale' => $item['scale'] ?? '100%',
|
||||
|
||||
Reference in New Issue
Block a user