- 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>
46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?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.');
|
|
}
|
|
}
|