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,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Attribute;
|
||||
use App\Models\AttributeValue;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AttributeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$attributes = Attribute::with('values')->get();
|
||||
return view('admin.attributes.index', compact('attributes'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate(['name' => 'required|string|max:255']);
|
||||
Attribute::create($data);
|
||||
return back()->with('success', 'Attribut erstellt.');
|
||||
}
|
||||
|
||||
public function destroy(Attribute $attribute)
|
||||
{
|
||||
$attribute->delete();
|
||||
return back()->with('success', 'Attribut gelöscht.');
|
||||
}
|
||||
|
||||
public function storeValue(Request $request, Attribute $attribute)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'value' => 'required|string|max:255',
|
||||
'sort_order' => 'integer',
|
||||
]);
|
||||
$attribute->values()->create($data);
|
||||
return back()->with('success', 'Wert hinzugefügt.');
|
||||
}
|
||||
|
||||
public function destroyValue(AttributeValue $value)
|
||||
{
|
||||
$value->delete();
|
||||
return back()->with('success', 'Wert gelöscht.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Banner;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BannerController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$banners = Banner::orderBy('sort_order')->get();
|
||||
return view('admin.banners.index', compact('banners'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.banners.form');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $this->validated($request);
|
||||
Banner::create($data);
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Banner erstellt.');
|
||||
}
|
||||
|
||||
public function edit(Banner $banner)
|
||||
{
|
||||
return view('admin.banners.form', compact('banner'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Banner $banner)
|
||||
{
|
||||
$data = $this->validated($request, $banner);
|
||||
$banner->update($data);
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Banner aktualisiert.');
|
||||
}
|
||||
|
||||
public function destroy(Banner $banner)
|
||||
{
|
||||
$banner->delete();
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Banner gelöscht.');
|
||||
}
|
||||
|
||||
private function validated(Request $request, ?Banner $banner = null): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'headline' => 'nullable|string|max:255',
|
||||
'subtext' => 'nullable|string|max:500',
|
||||
'button_label' => 'nullable|string|max:100',
|
||||
'button_link' => 'nullable|string|max:500',
|
||||
'sort_order' => 'integer',
|
||||
'active' => 'boolean',
|
||||
]);
|
||||
$data['active'] = $request->boolean('active');
|
||||
if ($request->hasFile('image')) {
|
||||
$data['image'] = $request->file('image')->store('banners', 'public');
|
||||
} elseif ($banner) {
|
||||
$data['image'] = $banner->image;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$categories = Category::with('parent')->orderBy('sort_order')->get();
|
||||
return view('admin.categories.index', compact('categories'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$parents = Category::whereNull('parent_id')->orderBy('name')->get();
|
||||
return view('admin.categories.form', compact('parents'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'parent_id' => 'nullable|exists:categories,id',
|
||||
'description' => 'nullable|string',
|
||||
'sort_order' => 'integer',
|
||||
'active' => 'boolean',
|
||||
]);
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$data['active'] = $request->boolean('active');
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$data['image'] = $request->file('image')->store('categories', 'public');
|
||||
}
|
||||
|
||||
Category::create($data);
|
||||
return redirect()->route('admin.categories.index')->with('success', 'Kategorie erstellt.');
|
||||
}
|
||||
|
||||
public function edit(Category $category)
|
||||
{
|
||||
$parents = Category::whereNull('parent_id')->where('id', '!=', $category->id)->orderBy('name')->get();
|
||||
return view('admin.categories.form', compact('category', 'parents'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Category $category)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'parent_id' => 'nullable|exists:categories,id',
|
||||
'description' => 'nullable|string',
|
||||
'sort_order' => 'integer',
|
||||
'active' => 'boolean',
|
||||
]);
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$data['active'] = $request->boolean('active');
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$data['image'] = $request->file('image')->store('categories', 'public');
|
||||
}
|
||||
|
||||
$category->update($data);
|
||||
return redirect()->route('admin.categories.index')->with('success', 'Kategorie aktualisiert.');
|
||||
}
|
||||
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$category->delete();
|
||||
return redirect()->route('admin.categories.index')->with('success', 'Kategorie gelöscht.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = User::where('role', 'customer')->withCount('orders');
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('name', 'like', '%'.$request->q.'%')
|
||||
->orWhere('email', 'like', '%'.$request->q.'%');
|
||||
});
|
||||
}
|
||||
|
||||
$customers = $query->latest()->paginate(25);
|
||||
return view('admin.customers.index', compact('customers'));
|
||||
}
|
||||
|
||||
public function show(User $customer)
|
||||
{
|
||||
abort_if($customer->isAdmin(), 404);
|
||||
|
||||
$customer->load('addresses');
|
||||
|
||||
$orders = $customer->orders()
|
||||
->with('addresses')
|
||||
->latest()
|
||||
->paginate(15);
|
||||
|
||||
$stats = [
|
||||
'total_orders' => $customer->orders()->count(),
|
||||
'total_revenue' => $customer->orders()
|
||||
->whereNotIn('status', ['cancelled'])
|
||||
->sum('total'),
|
||||
'open_orders' => $customer->orders()
|
||||
->whereIn('status', ['new', 'payment_received', 'processing'])
|
||||
->count(),
|
||||
'last_order' => $customer->orders()->latest()->first(),
|
||||
];
|
||||
|
||||
return view('admin.customers.show', compact('customer', 'orders', 'stats'));
|
||||
}
|
||||
|
||||
public function toggleApproval(User $customer)
|
||||
{
|
||||
abort_if($customer->isAdmin(), 403);
|
||||
|
||||
$approving = ! $customer->approved;
|
||||
$customer->approved = $approving;
|
||||
|
||||
if ($approving && ! $customer->email_verified_at) {
|
||||
$customer->email_verified_at = now();
|
||||
}
|
||||
|
||||
$customer->save();
|
||||
|
||||
$status = $approving ? 'freigeschaltet' : 'gesperrt';
|
||||
return back()->with('success', "Kunde {$customer->name} wurde {$status}.");
|
||||
}
|
||||
|
||||
public function destroy(User $customer)
|
||||
{
|
||||
abort_if($customer->isAdmin(), 403);
|
||||
$customer->delete();
|
||||
return redirect()->route('admin.customers.index')->with('success', 'Kunde gelöscht.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductVariant;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$todayRevenue = Order::whereDate('created_at', today())->whereIn('status', ['payment_received','processing','shipped','completed'])->sum('total');
|
||||
$monthRevenue = Order::whereMonth('created_at', now()->month)->whereYear('created_at', now()->year)->whereIn('status', ['payment_received','processing','shipped','completed'])->sum('total');
|
||||
$openOrders = Order::where('status', 'new')->count();
|
||||
$lowStock = ProductVariant::whereColumn('stock', '<=', 'stock_warning')->where('active', true)->with('product')->get();
|
||||
$recentOrders = Order::with('addresses')->latest()->take(10)->get();
|
||||
|
||||
return view('admin.dashboard.index', compact('todayRevenue', 'monthRevenue', 'openOrders', 'lowStock', 'recentOrders'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Faq;
|
||||
use App\Models\FaqGroup;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FaqController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$groups = FaqGroup::with('faqs')->orderBy('sort_order')->get();
|
||||
return view('admin.faqs.index', compact('groups'));
|
||||
}
|
||||
|
||||
public function storeGroup(Request $request)
|
||||
{
|
||||
$data = $request->validate(['name' => 'required|string|max:255', 'sort_order' => 'integer']);
|
||||
FaqGroup::create($data);
|
||||
return back()->with('success', 'Gruppe erstellt.');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'faq_group_id' => 'nullable|exists:faq_groups,id',
|
||||
'question' => 'required|string|max:500',
|
||||
'answer' => 'required|string',
|
||||
'sort_order' => 'integer',
|
||||
]);
|
||||
Faq::create($data);
|
||||
return back()->with('success', 'FAQ erstellt.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Faq $faq)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'question' => 'required|string|max:500',
|
||||
'answer' => 'required|string',
|
||||
'sort_order' => 'integer',
|
||||
]);
|
||||
$faq->update($data);
|
||||
return back()->with('success', 'FAQ aktualisiert.');
|
||||
}
|
||||
|
||||
public function destroy(Faq $faq)
|
||||
{
|
||||
$faq->delete();
|
||||
return back()->with('success', 'FAQ gelöscht.');
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Page;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$pages = Page::orderBy('type')->orderBy('title')->get();
|
||||
return view('admin.pages.index', compact('pages'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.pages.form');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $this->validated($request);
|
||||
Page::create($data);
|
||||
return redirect()->route('admin.pages.index')->with('success', 'Seite erstellt.');
|
||||
}
|
||||
|
||||
public function edit(Page $page)
|
||||
{
|
||||
return view('admin.pages.form', compact('page'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Page $page)
|
||||
{
|
||||
$data = $this->validated($request, $page);
|
||||
$page->update($data);
|
||||
return redirect()->route('admin.pages.index')->with('success', 'Seite aktualisiert.');
|
||||
}
|
||||
|
||||
public function destroy(Page $page)
|
||||
{
|
||||
$page->delete();
|
||||
return redirect()->route('admin.pages.index')->with('success', 'Seite gelöscht.');
|
||||
}
|
||||
|
||||
private function validated(Request $request, ?Page $page = null): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'slug' => 'nullable|string|max:255',
|
||||
'type' => 'required|in:static,blog,faq',
|
||||
'content' => 'nullable|string',
|
||||
'meta_title' => 'nullable|string|max:255',
|
||||
'meta_description' => 'nullable|string|max:500',
|
||||
'published' => 'boolean',
|
||||
'published_at' => 'nullable|date',
|
||||
'show_in_footer' => 'boolean',
|
||||
'show_in_nav' => 'boolean',
|
||||
'nav_sort' => 'integer|min:0',
|
||||
]);
|
||||
$data['slug'] = $data['slug'] ? Str::slug($data['slug']) : Str::slug($data['title']);
|
||||
$data['published'] = $request->boolean('published');
|
||||
$data['show_in_footer'] = $request->boolean('show_in_footer');
|
||||
$data['show_in_nav'] = $request->boolean('show_in_nav');
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Attribute;
|
||||
use App\Models\AttributeValue;
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductImage;
|
||||
use App\Models\ProductVariant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Product::with('category')->latest();
|
||||
if ($request->filled('q')) {
|
||||
$query->where('name', 'like', '%'.$request->q.'%');
|
||||
}
|
||||
$products = $query->paginate(25);
|
||||
return view('admin.products.index', compact('products'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$categories = Category::orderBy('name')->get();
|
||||
$attributes = Attribute::with('values')->get();
|
||||
$variantsJson = '[]';
|
||||
return view('admin.products.form', compact('categories', 'attributes', 'variantsJson'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'category_id' => 'nullable|exists:categories,id',
|
||||
'description' => 'nullable|string',
|
||||
'base_price' => 'required|numeric|min:0',
|
||||
'tax_rate' => 'required|numeric|in:7,19',
|
||||
'weight' => 'nullable|numeric|min:0',
|
||||
'active' => 'boolean',
|
||||
'featured' => 'boolean',
|
||||
'track_stock' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
]);
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$data['active'] = $request->boolean('active');
|
||||
$data['featured'] = $request->boolean('featured');
|
||||
$data['track_stock'] = $request->boolean('track_stock');
|
||||
|
||||
$product = Product::create($data);
|
||||
|
||||
$this->syncImages($request, $product);
|
||||
$this->syncVariants($request, $product);
|
||||
|
||||
return redirect()->route('admin.products.index')->with('success', 'Artikel erstellt.');
|
||||
}
|
||||
|
||||
public function edit(Product $product)
|
||||
{
|
||||
$product->load('images', 'variants.attributeValues.attribute');
|
||||
$categories = Category::orderBy('name')->get();
|
||||
$attributes = Attribute::with('values')->get();
|
||||
$variantsJson = json_encode($product->variants->map(fn($v) => [
|
||||
'id' => $v->id,
|
||||
'sku' => $v->sku,
|
||||
'price_override' => $v->price_override,
|
||||
'stock' => $v->stock,
|
||||
'stock_warning' => $v->stock_warning,
|
||||
'active' => (bool) $v->active,
|
||||
'attribute_value_ids' => $v->attributeValues->pluck('id')->values()->all(),
|
||||
]));
|
||||
return view('admin.products.form', compact('product', 'categories', 'attributes', 'variantsJson'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Product $product)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'category_id' => 'nullable|exists:categories,id',
|
||||
'description' => 'nullable|string',
|
||||
'base_price' => 'required|numeric|min:0',
|
||||
'tax_rate' => 'required|numeric|in:7,19',
|
||||
'weight' => 'nullable|numeric|min:0',
|
||||
'active' => 'boolean',
|
||||
'featured' => 'boolean',
|
||||
'track_stock' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
]);
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$data['active'] = $request->boolean('active');
|
||||
$data['featured'] = $request->boolean('featured');
|
||||
$data['track_stock'] = $request->boolean('track_stock');
|
||||
|
||||
$product->update($data);
|
||||
|
||||
$this->syncImages($request, $product);
|
||||
$this->syncVariants($request, $product);
|
||||
|
||||
return redirect()->route('admin.products.index')->with('success', 'Artikel aktualisiert.');
|
||||
}
|
||||
|
||||
public function destroy(Product $product)
|
||||
{
|
||||
$product->delete();
|
||||
return redirect()->route('admin.products.index')->with('success', 'Artikel gelöscht.');
|
||||
}
|
||||
|
||||
private function syncImages(Request $request, Product $product): void
|
||||
{
|
||||
if ($request->hasFile('images')) {
|
||||
foreach ($request->file('images') as $i => $file) {
|
||||
$path = $file->store('products', 'public');
|
||||
ProductImage::create(['product_id' => $product->id, 'path' => $path, 'sort_order' => $i]);
|
||||
}
|
||||
}
|
||||
// Bild löschen
|
||||
if ($request->filled('delete_images')) {
|
||||
ProductImage::whereIn('id', $request->delete_images)
|
||||
->where('product_id', $product->id)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
private function syncVariants(Request $request, Product $product): void
|
||||
{
|
||||
$variants = $request->input('variants', []);
|
||||
$existingIds = [];
|
||||
|
||||
foreach ($variants as $v) {
|
||||
if (empty($v['sku'])) continue;
|
||||
|
||||
$variant = isset($v['id'])
|
||||
? ProductVariant::find($v['id'])
|
||||
: null;
|
||||
|
||||
$variantData = [
|
||||
'product_id' => $product->id,
|
||||
'sku' => $v['sku'],
|
||||
'price_override' => filled($v['price_override']) ? $v['price_override'] : null,
|
||||
'stock' => (int) ($v['stock'] ?? 0),
|
||||
'stock_warning' => (int) ($v['stock_warning'] ?? 5),
|
||||
'active' => isset($v['active']),
|
||||
];
|
||||
|
||||
if ($variant) {
|
||||
$variant->update($variantData);
|
||||
} else {
|
||||
$variant = ProductVariant::create($variantData);
|
||||
}
|
||||
|
||||
// Attributwerte synchronisieren
|
||||
$valueIds = array_filter((array) ($v['attribute_value_ids'] ?? []));
|
||||
$variant->attributeValues()->sync($valueIds);
|
||||
|
||||
$existingIds[] = $variant->id;
|
||||
}
|
||||
|
||||
// Nicht mehr vorhandene Varianten löschen
|
||||
$product->variants()->whereNotIn('id', $existingIds)->delete();
|
||||
|
||||
// Sicherstellen dass jedes Produkt mindestens eine Standard-Variante hat
|
||||
if ($product->variants()->count() === 0) {
|
||||
ProductVariant::create([
|
||||
'product_id' => $product->id,
|
||||
'sku' => 'DEFAULT-' . $product->id,
|
||||
'price_override'=> null,
|
||||
'stock' => 0,
|
||||
'stock_warning' => 5,
|
||||
'active' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
private array $keys = [
|
||||
'shop_name','shop_email','shop_phone','shop_address','shop_owner','shop_vat_id',
|
||||
'bank_name','bank_iban','bank_bic','invoice_payment_days',
|
||||
'smtp_host','smtp_port','smtp_user','smtp_password','smtp_from_name','smtp_from_email',
|
||||
'cookie_consent','google_analytics','require_customer_approval',
|
||||
];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$settings = [];
|
||||
foreach ($this->keys as $key) {
|
||||
$settings[$key] = Setting::get($key, '');
|
||||
}
|
||||
$settings['shop_logo'] = Setting::get('shop_logo', '');
|
||||
return view('admin.settings.index', compact('settings'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
foreach ($this->keys as $key) {
|
||||
Setting::set($key, $request->input($key, ''));
|
||||
}
|
||||
|
||||
// Logo hochladen
|
||||
if ($request->hasFile('shop_logo')) {
|
||||
$path = $request->file('shop_logo')->store('branding', 'public');
|
||||
Setting::set('shop_logo', $path);
|
||||
}
|
||||
// Logo löschen
|
||||
if ($request->boolean('delete_logo')) {
|
||||
Setting::set('shop_logo', '');
|
||||
}
|
||||
|
||||
// SMTP live in .env-Werte schreiben (für aktuellen Request anwenden)
|
||||
config([
|
||||
'mail.mailers.smtp.host' => Setting::get('smtp_host'),
|
||||
'mail.mailers.smtp.port' => Setting::get('smtp_port'),
|
||||
'mail.mailers.smtp.username' => Setting::get('smtp_user'),
|
||||
'mail.mailers.smtp.password' => Setting::get('smtp_password'),
|
||||
'mail.from.address' => Setting::get('smtp_from_email'),
|
||||
'mail.from.name' => Setting::get('smtp_from_name'),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Einstellungen gespeichert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShippingRate;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ShippingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$rates = ShippingRate::orderBy('zone')->get();
|
||||
return view('admin.settings.shipping', compact('rates'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'zone' => 'required|string|max:10',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'free_from' => 'nullable|numeric|min:0',
|
||||
'active' => 'boolean',
|
||||
]);
|
||||
$data['active'] = $request->boolean('active');
|
||||
ShippingRate::create($data);
|
||||
return back()->with('success', 'Versandkosten erstellt.');
|
||||
}
|
||||
|
||||
public function update(Request $request, ShippingRate $rate)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'zone' => 'required|string|max:10',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'free_from' => 'nullable|numeric|min:0',
|
||||
'active' => 'boolean',
|
||||
]);
|
||||
$data['active'] = $request->boolean('active');
|
||||
$rate->update($data);
|
||||
return back()->with('success', 'Versandkosten aktualisiert.');
|
||||
}
|
||||
|
||||
public function destroy(ShippingRate $rate)
|
||||
{
|
||||
$rate->delete();
|
||||
return back()->with('success', 'Versandkosten gelöscht.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
$user = auth()->user();
|
||||
if ($user->isAdmin()) {
|
||||
return redirect()->intended(route('admin.dashboard'));
|
||||
}
|
||||
return redirect()->intended(route('account.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(route('dashboard', absolute: false))
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function (User $user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$requiresApproval = (bool) Setting::get('require_customer_approval', false);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
'approved' => ! $requiresApproval,
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
if ($requiresApproval) {
|
||||
return redirect()->route('login')
|
||||
->with('status', 'Registrierung erfolgreich. Ihr Konto wird nach Prüfung durch einen Administrator freigeschaltet.');
|
||||
}
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect()->route('account.index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Address;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$orders = auth()->user()->orders()->latest()->take(5)->get();
|
||||
return view('shop.account.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$orders = auth()->user()->orders()->latest()->paginate(10);
|
||||
return view('shop.account.orders', compact('orders'));
|
||||
}
|
||||
|
||||
public function orderDetail(Order $order)
|
||||
{
|
||||
abort_unless($order->user_id === auth()->id(), 403);
|
||||
$order->load('items', 'addresses');
|
||||
return view('shop.account.order', compact('order'));
|
||||
}
|
||||
|
||||
public function addresses()
|
||||
{
|
||||
$addresses = auth()->user()->addresses()->get();
|
||||
return view('shop.account.addresses', compact('addresses'));
|
||||
}
|
||||
|
||||
public function storeAddress(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'first_name' => 'required|string|max:100',
|
||||
'last_name' => 'required|string|max:100',
|
||||
'company' => 'nullable|string|max:255',
|
||||
'street' => 'required|string|max:255',
|
||||
'zip' => 'required|string|max:10',
|
||||
'city' => 'required|string|max:100',
|
||||
'country' => 'required|string|max:2',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
]);
|
||||
$data['user_id'] = auth()->id();
|
||||
Address::create($data);
|
||||
return back()->with('success', 'Adresse gespeichert.');
|
||||
}
|
||||
|
||||
public function destroyAddress(Address $address)
|
||||
{
|
||||
abort_unless($address->user_id === auth()->id(), 403);
|
||||
$address->delete();
|
||||
return back()->with('success', 'Adresse gelöscht.');
|
||||
}
|
||||
|
||||
public function settings()
|
||||
{
|
||||
return view('shop.account.settings');
|
||||
}
|
||||
|
||||
public function updateSettings(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|unique:users,email,' . auth()->id(),
|
||||
'password' => 'nullable|min:8|confirmed',
|
||||
]);
|
||||
|
||||
$user = auth()->user();
|
||||
$user->name = $data['name'];
|
||||
$user->email = $data['email'];
|
||||
if (!empty($data['password'])) {
|
||||
$user->password = bcrypt($data['password']);
|
||||
}
|
||||
$user->save();
|
||||
|
||||
return back()->with('success', 'Einstellungen gespeichert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShippingRate;
|
||||
use App\Services\CartService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
public function __construct(private CartService $cart) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$items = $this->cart->get();
|
||||
$subtotal = $this->cart->subtotal();
|
||||
$shippingRate = ShippingRate::forCart($subtotal);
|
||||
$shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0;
|
||||
$total = $subtotal + $shippingCost;
|
||||
|
||||
return view('shop.cart.index', compact('items', 'subtotal', 'shippingRate', 'shippingCost', 'total'));
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$request->validate(['variant_id' => 'required|exists:product_variants,id', 'qty' => 'integer|min:1']);
|
||||
$this->cart->add($request->variant_id, $request->integer('qty', 1));
|
||||
return back()->with('success', 'Artikel zum Warenkorb hinzugefügt.');
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
foreach ($request->input('qty', []) as $key => $qty) {
|
||||
$this->cart->update($key, (int) $qty);
|
||||
}
|
||||
return back()->with('success', 'Warenkorb aktualisiert.');
|
||||
}
|
||||
|
||||
public function remove(string $key)
|
||||
{
|
||||
$this->cart->remove($key);
|
||||
return back()->with('success', 'Artikel entfernt.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShippingRate;
|
||||
use App\Services\CartService;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private CartService $cart,
|
||||
private OrderService $orderService,
|
||||
) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if ($this->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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\FaqGroup;
|
||||
|
||||
class FaqController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$groups = FaqGroup::with('faqs')->orderBy('sort_order')->get();
|
||||
return view('shop.faq', compact('groups'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Banner;
|
||||
use App\Models\Category;
|
||||
use App\Models\Page;
|
||||
use App\Models\Product;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$banners = Banner::where('active', true)->orderBy('sort_order')->get();
|
||||
$categories = Category::whereNull('parent_id')->where('active', true)->orderBy('sort_order')->get();
|
||||
$topProducts = Product::where('active', true)->where('featured', true)->latest()->take(8)->get();
|
||||
$newProducts = Product::where('active', true)->latest()->take(8)->get();
|
||||
$blogPosts = Page::where('type', 'blog')->where('published', true)->latest('published_at')->take(3)->get();
|
||||
|
||||
return view('shop.home', compact('banners', 'categories', 'topProducts', 'newProducts', 'blogPosts'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderTrackingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('shop.order_tracking');
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$request->validate(['order_number' => 'required|string', 'email' => 'required|email']);
|
||||
$order = Order::where('order_number', $request->order_number)
|
||||
->where(function ($q) use ($request) {
|
||||
$q->where('guest_email', $request->email)
|
||||
->orWhereHas('user', fn($u) => $u->where('email', $request->email));
|
||||
})->with('items', 'addresses')->first();
|
||||
|
||||
if (!$order) {
|
||||
return back()->with('error', 'Bestellung nicht gefunden. Bitte prüfen Sie die Bestellnummer und E-Mail-Adresse.');
|
||||
}
|
||||
|
||||
return view('shop.order_tracking', compact('order'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Page;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
public function show(string $slug)
|
||||
{
|
||||
$page = Page::where('slug', $slug)->where('published', true)->firstOrFail();
|
||||
return view('shop.page', compact('page'));
|
||||
}
|
||||
|
||||
public function blog()
|
||||
{
|
||||
$posts = Page::where('type', 'blog')->where('published', true)->latest('published_at')->paginate(10);
|
||||
return view('shop.blog.index', compact('posts'));
|
||||
}
|
||||
|
||||
public function blogPost(string $slug)
|
||||
{
|
||||
$post = Page::where('slug', $slug)->where('type', 'blog')->where('published', true)->firstOrFail();
|
||||
return view('shop.blog.post', compact('post'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Product::with(['images', 'category'])->where('active', true);
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$query->where('name', 'like', '%'.$request->q.'%');
|
||||
}
|
||||
if ($request->filled('min_price')) {
|
||||
$query->where('base_price', '>=', $request->min_price);
|
||||
}
|
||||
if ($request->filled('max_price')) {
|
||||
$query->where('base_price', '<=', $request->max_price);
|
||||
}
|
||||
|
||||
$products = $query->orderBy('sort_order')->paginate(16);
|
||||
$categories = Category::whereNull('parent_id')->where('active', true)->get();
|
||||
|
||||
return view('shop.products.index', compact('products', 'categories'));
|
||||
}
|
||||
|
||||
public function category(string $slug)
|
||||
{
|
||||
$category = Category::where('slug', $slug)->where('active', true)->firstOrFail();
|
||||
$categoryIds = collect([$category->id])->merge($category->children->pluck('id'));
|
||||
$products = Product::with(['images'])->where('active', true)->whereIn('category_id', $categoryIds)->orderBy('sort_order')->paginate(16);
|
||||
|
||||
return view('shop.products.index', compact('products', 'category'));
|
||||
}
|
||||
|
||||
public function show(string $slug)
|
||||
{
|
||||
$product = Product::with(['images', 'category', 'variants.attributeValues.attribute'])
|
||||
->where('slug', $slug)
|
||||
->where('active', true)
|
||||
->firstOrFail();
|
||||
|
||||
$related = Product::where('category_id', $product->category_id)
|
||||
->where('id', '!=', $product->id)
|
||||
->where('active', true)
|
||||
->take(4)->get();
|
||||
|
||||
return view('shop.products.show', compact('product', 'related'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\WiderrufsformularMail;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class WiderrufsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('shop.widerruf');
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'first_name' => 'required|string|max:255',
|
||||
'last_name' => 'required|string|max:255',
|
||||
'email' => 'required|email',
|
||||
'street' => 'required|string|max:255',
|
||||
'zip' => 'required|string|max:20',
|
||||
'city' => 'required|string|max:255',
|
||||
'customer_number' => 'nullable|string|max:100',
|
||||
'order_number' => 'nullable|string|max:100',
|
||||
'order_date' => 'nullable|date',
|
||||
'date' => 'required|date',
|
||||
'product' => 'required|string|max:500',
|
||||
'reason_category' => 'nullable|string|max:100',
|
||||
'reason' => 'nullable|string|max:2000',
|
||||
'refund_method' => 'nullable|string|in:original,bank,credit',
|
||||
'privacy_accepted' => 'accepted',
|
||||
'accuracy_confirmed'=> 'accepted',
|
||||
]);
|
||||
$data['name'] = $data['first_name'] . ' ' . $data['last_name'];
|
||||
|
||||
$shopEmail = Setting::get('shop_email');
|
||||
Mail::to($shopEmail)->send(new WiderrufsformularMail($data));
|
||||
Mail::to($data['email'])->send(new WiderrufsformularMail($data, true));
|
||||
|
||||
return back()->with('success', 'Ihr Widerrufsformular wurde erfolgreich übermittelt. Sie erhalten eine Bestätigungsmail.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AdminMiddleware
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (!auth()->check() || !auth()->user()->isAdmin()) {
|
||||
abort(403, 'Zugriff verweigert.');
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsureUserIsApproved
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (auth()->check() && ! auth()->user()->isApproved()) {
|
||||
auth()->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect()->route('login')
|
||||
->with('error', 'Ihr Konto wurde noch nicht freigeschaltet. Bitte warten Sie auf die Bestätigung durch einen Administrator.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($this->user()->id),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderConfirmationMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Order $order) {}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
->subject('Bestellbestätigung ' . $this->order->order_number . ' – ' . Setting::get('shop_name'))
|
||||
->view('emails.order_confirmation');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderShippedMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Order $order) {}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
->subject('Ihre Bestellung wurde versendet – ' . $this->order->order_number)
|
||||
->view('emails.order_shipped');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PaymentReceivedMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Order $order,
|
||||
private string $pdfContent,
|
||||
private string $pdfFilename,
|
||||
) {}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
->subject('Ihre Rechnung – ' . $this->order->order_number . ' – ' . Setting::get('shop_name'))
|
||||
->view('emails.payment_received')
|
||||
->attachData($this->pdfContent, $this->pdfFilename, ['mime' => 'application/pdf']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class WiderrufsformularMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public array $data,
|
||||
public bool $isConfirmation = false,
|
||||
) {}
|
||||
|
||||
public function build()
|
||||
{
|
||||
$subject = $this->isConfirmation
|
||||
? 'Bestätigung Ihres Widerrufs – ' . Setting::get('shop_name')
|
||||
: 'Neues Widerrufsformular eingegangen';
|
||||
|
||||
return $this->subject($subject)->view('emails.widerruf');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
protected $fillable = ['user_id','first_name','last_name','company','street','street2','zip','city','country','phone','is_default'];
|
||||
|
||||
protected $casts = ['is_default' => 'boolean'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Attribute extends Model
|
||||
{
|
||||
protected $fillable = ['name'];
|
||||
|
||||
public function values(): HasMany
|
||||
{
|
||||
return $this->hasMany(AttributeValue::class)->orderBy('sort_order');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class AttributeValue extends Model
|
||||
{
|
||||
protected $fillable = ['attribute_id','value','sort_order'];
|
||||
|
||||
public function attribute(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Attribute::class);
|
||||
}
|
||||
|
||||
public function variants(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ProductVariant::class, 'product_variant_attribute_values');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
protected $fillable = ['image','headline','subtext','button_label','button_link','sort_order','active'];
|
||||
|
||||
protected $casts = ['active' => 'boolean'];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
protected $fillable = ['parent_id','name','slug','description','image','sort_order','active'];
|
||||
|
||||
protected $casts = ['active' => 'boolean'];
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id')->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function products(): HasMany
|
||||
{
|
||||
return $this->hasMany(Product::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Faq extends Model
|
||||
{
|
||||
protected $fillable = ['faq_group_id','question','answer','sort_order'];
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(FaqGroup::class, 'faq_group_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class FaqGroup extends Model
|
||||
{
|
||||
protected $fillable = ['name','sort_order'];
|
||||
|
||||
public function faqs(): HasMany
|
||||
{
|
||||
return $this->hasMany(Faq::class)->orderBy('sort_order');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'order_number','user_id','guest_email','status','payment_method',
|
||||
'subtotal','tax_total','shipping_cost','total','tracking_code','notes','paid_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'paid_at' => 'datetime',
|
||||
'subtotal' => 'decimal:2',
|
||||
'tax_total' => 'decimal:2',
|
||||
'shipping_cost' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
];
|
||||
|
||||
public static array $statusLabels = [
|
||||
'new' => 'Neu',
|
||||
'payment_received' => 'Zahlung eingegangen',
|
||||
'processing' => 'In Bearbeitung',
|
||||
'shipped' => 'Versendet',
|
||||
'completed' => 'Abgeschlossen',
|
||||
'cancelled' => 'Storniert',
|
||||
];
|
||||
|
||||
public static array $paymentLabels = [
|
||||
'prepayment' => 'Vorkasse',
|
||||
'invoice' => 'Rechnung',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(OrderItem::class);
|
||||
}
|
||||
|
||||
public function addresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(OrderAddress::class);
|
||||
}
|
||||
|
||||
public function billingAddress()
|
||||
{
|
||||
return $this->addresses()->where('type', 'billing')->first();
|
||||
}
|
||||
|
||||
public function shippingAddress()
|
||||
{
|
||||
return $this->addresses()->where('type', 'shipping')->first();
|
||||
}
|
||||
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return self::$statusLabels[$this->status] ?? $this->status;
|
||||
}
|
||||
|
||||
public function getPaymentLabelAttribute(): string
|
||||
{
|
||||
return self::$paymentLabels[$this->payment_method] ?? $this->payment_method;
|
||||
}
|
||||
|
||||
public static function generateOrderNumber(): string
|
||||
{
|
||||
return 'ORD-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -5));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class OrderAddress extends Model
|
||||
{
|
||||
protected $fillable = ['order_id','type','first_name','last_name','company','street','street2','zip','city','country','phone'];
|
||||
|
||||
public function order(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
return trim("{$this->first_name} {$this->last_name}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class OrderItem extends Model
|
||||
{
|
||||
protected $fillable = ['order_id','product_variant_id','product_name','variant_label','quantity','unit_price','tax_rate'];
|
||||
|
||||
protected $casts = ['unit_price' => 'decimal:2', 'tax_rate' => 'decimal:2'];
|
||||
|
||||
public function order(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function variant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ProductVariant::class, 'product_variant_id');
|
||||
}
|
||||
|
||||
public function getLineTotalAttribute(): float
|
||||
{
|
||||
return round($this->unit_price * $this->quantity, 2);
|
||||
}
|
||||
|
||||
public function getTaxAmountAttribute(): float
|
||||
{
|
||||
$net = $this->unit_price / (1 + $this->tax_rate / 100);
|
||||
return round(($this->unit_price - $net) * $this->quantity, 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Page extends Model
|
||||
{
|
||||
protected $fillable = ['slug','title','content','type','image','meta_title','meta_description','published','published_at','show_in_footer','show_in_nav','nav_sort'];
|
||||
|
||||
protected $casts = ['published' => 'boolean', 'published_at' => 'datetime', 'show_in_footer' => 'boolean', 'show_in_nav' => 'boolean'];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
protected $fillable = ['category_id','name','slug','description','base_price','tax_rate','weight','active','featured','track_stock','sort_order'];
|
||||
|
||||
protected $casts = ['active' => 'boolean', 'featured' => 'boolean', 'track_stock' => 'boolean', 'base_price' => 'decimal:2', 'tax_rate' => 'decimal:2'];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function images(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProductImage::class)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function variants(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProductVariant::class);
|
||||
}
|
||||
|
||||
/** Effektiver Bruttopreis (Basispreis, wenn keine Variante gewählt) */
|
||||
public function getDisplayPriceAttribute(): float
|
||||
{
|
||||
return (float) $this->base_price;
|
||||
}
|
||||
|
||||
public function getNetPriceAttribute(): float
|
||||
{
|
||||
return round($this->base_price / (1 + $this->tax_rate / 100), 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ProductImage extends Model
|
||||
{
|
||||
protected $fillable = ['product_id','path','sort_order'];
|
||||
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class ProductVariant extends Model
|
||||
{
|
||||
protected $fillable = ['product_id','sku','price_override','stock','stock_warning','active'];
|
||||
|
||||
protected $casts = ['active' => 'boolean', 'price_override' => 'decimal:2'];
|
||||
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function attributeValues(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(AttributeValue::class, 'product_variant_attribute_values')
|
||||
->with('attribute');
|
||||
}
|
||||
|
||||
public function getEffectivePriceAttribute(): float
|
||||
{
|
||||
return (float) ($this->price_override ?? $this->product->base_price);
|
||||
}
|
||||
|
||||
public function getLabelAttribute(): string
|
||||
{
|
||||
return $this->attributeValues->map(fn($v) => $v->value)->join(', ');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $fillable = ['key','value'];
|
||||
|
||||
public static function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return Cache::remember("setting_{$key}", 3600, function () use ($key, $default) {
|
||||
return self::where('key', $key)->value('value') ?? $default;
|
||||
});
|
||||
}
|
||||
|
||||
public static function set(string $key, mixed $value): void
|
||||
{
|
||||
self::updateOrCreate(['key' => $key], ['value' => $value]);
|
||||
Cache::forget("setting_{$key}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ShippingRate extends Model
|
||||
{
|
||||
protected $fillable = ['name','zone','price','free_from','active'];
|
||||
|
||||
protected $casts = ['active' => 'boolean', 'price' => 'decimal:2', 'free_from' => 'decimal:2'];
|
||||
|
||||
public static function forCart(float $total, string $zone = 'DE'): ?self
|
||||
{
|
||||
return self::where('zone', $zone)->where('active', true)->first();
|
||||
}
|
||||
|
||||
public function getCostForTotal(float $total): float
|
||||
{
|
||||
if ($this->free_from !== null && $total >= (float) $this->free_from) {
|
||||
return 0.0;
|
||||
}
|
||||
return (float) $this->price;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
protected $fillable = ['name', 'email', 'password', 'role', 'approved'];
|
||||
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'approved' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function isApproved(): bool
|
||||
{
|
||||
return $this->isAdmin() || (bool) $this->approved;
|
||||
}
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return in_array($this->role, ['admin', 'super_admin']);
|
||||
}
|
||||
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return $this->role === 'super_admin';
|
||||
}
|
||||
|
||||
public function addresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(Address::class);
|
||||
}
|
||||
|
||||
public function orders(): HasMany
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ProductVariant;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class CartService
|
||||
{
|
||||
private const SESSION_KEY = 'cart';
|
||||
|
||||
public function get(): array
|
||||
{
|
||||
return Session::get(self::SESSION_KEY, []);
|
||||
}
|
||||
|
||||
public function add(int $variantId, int $qty = 1): void
|
||||
{
|
||||
$cart = $this->get();
|
||||
$key = "v{$variantId}";
|
||||
if (isset($cart[$key])) {
|
||||
$cart[$key]['qty'] += $qty;
|
||||
} else {
|
||||
$variant = ProductVariant::with('product')->findOrFail($variantId);
|
||||
$cart[$key] = [
|
||||
'variant_id' => $variantId,
|
||||
'product_name' => $variant->product->name,
|
||||
'variant_label'=> $variant->label,
|
||||
'price' => $variant->effective_price,
|
||||
'tax_rate' => $variant->product->tax_rate,
|
||||
'qty' => $qty,
|
||||
];
|
||||
}
|
||||
Session::put(self::SESSION_KEY, $cart);
|
||||
}
|
||||
|
||||
public function update(string $key, int $qty): void
|
||||
{
|
||||
$cart = $this->get();
|
||||
if (isset($cart[$key])) {
|
||||
if ($qty <= 0) {
|
||||
unset($cart[$key]);
|
||||
} else {
|
||||
$cart[$key]['qty'] = $qty;
|
||||
}
|
||||
}
|
||||
Session::put(self::SESSION_KEY, $cart);
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
{
|
||||
$cart = $this->get();
|
||||
unset($cart[$key]);
|
||||
Session::put(self::SESSION_KEY, $cart);
|
||||
}
|
||||
|
||||
public function clear(): void
|
||||
{
|
||||
Session::forget(self::SESSION_KEY);
|
||||
}
|
||||
|
||||
public function subtotal(): float
|
||||
{
|
||||
return array_sum(array_map(fn($i) => $i['price'] * $i['qty'], $this->get()));
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return array_sum(array_column($this->get(), 'qty'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Order;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
|
||||
class InvoiceService
|
||||
{
|
||||
public function generate(Order $order): \Barryvdh\DomPDF\PDF
|
||||
{
|
||||
$order->load('items', 'addresses');
|
||||
return Pdf::loadView('pdf.invoice', compact('order'))
|
||||
->setPaper('a4', 'portrait');
|
||||
}
|
||||
|
||||
public function filename(Order $order): string
|
||||
{
|
||||
return 'Rechnung-' . $order->order_number . '.pdf';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Mail\OrderConfirmationMail;
|
||||
use App\Mail\OrderShippedMail;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderAddress;
|
||||
use App\Models\OrderItem;
|
||||
use App\Models\ProductVariant;
|
||||
use App\Models\ShippingRate;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class OrderService
|
||||
{
|
||||
public function __construct(private CartService $cart) {}
|
||||
|
||||
public function createFromSession(array $addressData, string $paymentMethod): Order
|
||||
{
|
||||
$items = $this->cart->get();
|
||||
$subtotal = $this->cart->subtotal();
|
||||
|
||||
$shippingRate = ShippingRate::forCart($subtotal);
|
||||
$shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0;
|
||||
|
||||
$taxTotal = array_sum(array_map(function ($item) {
|
||||
$net = $item['price'] / (1 + $item['tax_rate'] / 100);
|
||||
return round(($item['price'] - $net) * $item['qty'], 2);
|
||||
}, $items));
|
||||
|
||||
$order = Order::create([
|
||||
'order_number' => Order::generateOrderNumber(),
|
||||
'user_id' => auth()->id(),
|
||||
'guest_email' => auth()->check() ? null : ($addressData['email'] ?? null),
|
||||
'status' => 'new',
|
||||
'payment_method' => $paymentMethod,
|
||||
'subtotal' => $subtotal,
|
||||
'tax_total' => $taxTotal,
|
||||
'shipping_cost' => $shippingCost,
|
||||
'total' => $subtotal + $shippingCost,
|
||||
]);
|
||||
|
||||
foreach ($items as $item) {
|
||||
OrderItem::create([
|
||||
'order_id' => $order->id,
|
||||
'product_variant_id'=> $item['variant_id'],
|
||||
'product_name' => $item['product_name'],
|
||||
'variant_label' => $item['variant_label'],
|
||||
'quantity' => $item['qty'],
|
||||
'unit_price' => $item['price'],
|
||||
'tax_rate' => $item['tax_rate'],
|
||||
]);
|
||||
// Bestand reduzieren — nur wenn track_stock aktiv
|
||||
$variant = ProductVariant::with('product')->find($item['variant_id']);
|
||||
if ($variant && $variant->product->track_stock) {
|
||||
$variant->decrement('stock', $item['qty']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['billing', 'shipping'] as $type) {
|
||||
$src = $addressData[$type] ?? $addressData['billing'];
|
||||
OrderAddress::create(array_merge($src, ['order_id' => $order->id, 'type' => $type]));
|
||||
}
|
||||
|
||||
$this->cart->clear();
|
||||
|
||||
Mail::to($order->guest_email ?? $order->user?->email)->send(new OrderConfirmationMail($order));
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
public function updateStatus(Order $order, string $newStatus, ?string $trackingCode = null): void
|
||||
{
|
||||
$order->status = $newStatus;
|
||||
|
||||
if ($newStatus === 'payment_received' && !$order->paid_at) {
|
||||
$order->paid_at = now();
|
||||
}
|
||||
|
||||
if ($trackingCode) {
|
||||
$order->tracking_code = $trackingCode;
|
||||
}
|
||||
|
||||
$order->save();
|
||||
|
||||
if ($newStatus === 'shipped') {
|
||||
$email = $order->guest_email ?? $order->user?->email;
|
||||
if ($email) {
|
||||
Mail::to($email)->send(new OrderShippedMail($order));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user