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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user