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