Initial commit: WitShop Laravel Online-Shop
- Laravel 11, Blade, Alpine.js, Tailwind CSS - Produkt- & Kategorieverwaltung mit Varianten - Checkout (Vorkasse + Rechnung), Session-Warenkorb - Admin-Backend (Dashboard, Bestellungen, Kunden, CMS) - DSGVO-konform: Cookie-Consent, Impressum, Widerruf, AGB - PDF-Rechnung via dompdf, SMTP-Mailversand - Kundenverwaltung mit manueller Freischaltung Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\PaymentReceivedMail;
|
||||
use App\Models\Order;
|
||||
use App\Services\InvoiceService;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private OrderService $orderService,
|
||||
private InvoiceService $invoiceService,
|
||||
) {}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Order::with('addresses')->latest();
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->status);
|
||||
}
|
||||
if ($request->filled('payment')) {
|
||||
$query->where('payment_method', $request->payment);
|
||||
}
|
||||
if ($request->filled('q')) {
|
||||
$query->where('order_number', 'like', '%'.$request->q.'%');
|
||||
}
|
||||
|
||||
$orders = $query->paginate(25);
|
||||
return view('admin.orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function show(Order $order)
|
||||
{
|
||||
$order->load('items', 'addresses', 'user');
|
||||
return view('admin.orders.show', compact('order'));
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, Order $order)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'status' => 'required|in:' . implode(',', array_keys(Order::$statusLabels)),
|
||||
'tracking_code' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$this->orderService->updateStatus($order, $data['status'], $data['tracking_code'] ?? null);
|
||||
|
||||
// Bei Zahlungseingang: Rechnung per Mail senden
|
||||
if ($data['status'] === 'payment_received') {
|
||||
$pdf = $this->invoiceService->generate($order);
|
||||
$email = $order->guest_email ?? $order->user?->email;
|
||||
if ($email) {
|
||||
Mail::to($email)->send(new PaymentReceivedMail($order, $pdf->output(), $this->invoiceService->filename($order)));
|
||||
}
|
||||
}
|
||||
|
||||
return back()->with('success', 'Status aktualisiert.');
|
||||
}
|
||||
|
||||
public function sendInvoice(Order $order)
|
||||
{
|
||||
$pdf = $this->invoiceService->generate($order);
|
||||
$email = $order->guest_email ?? $order->user?->email;
|
||||
if ($email) {
|
||||
Mail::to($email)->send(new PaymentReceivedMail($order, $pdf->output(), $this->invoiceService->filename($order)));
|
||||
}
|
||||
return back()->with('success', 'Rechnung erneut gesendet.');
|
||||
}
|
||||
|
||||
public function downloadInvoice(Order $order)
|
||||
{
|
||||
return $this->invoiceService->generate($order)->download($this->invoiceService->filename($order));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user