feat: shop customer accounts (register/login + order history)

Schema:
- shop_customers (company_id, name, phone unique-per-tenant, email, password,
  client_id auto-linked, last_login_at)
- online_orders.shop_customer_id nullable FK

Auth:
- New 'shop' guard (session driver, shop_customers provider) in config/auth.php
- ShopCustomer Authenticatable with hashed password cast and BelongsToTenant
  global scope — login attempts naturally scoped to current tenant subdomain

Flow:
- ShopAuthController: register / login / logout / account
- Register auto-links to existing Client by phone match
- /shop/account: order history (only the logged customer's orders) + profile
- Checkout prefills name/phone/email from logged customer + sets
  shop_customer_id (and client_id from auto-link) on the placed order
- Layout nav switches between Login/Register and "👤 Name + Ieșire"

Tests (8 new):
- register creates customer + auto-login
- register auto-links existing Client by phone
- duplicate phone rejected
- login validates credentials
- /account requires auth (redirects to /shop/login)
- /account lists only the logged customer's orders
- checkout attaches shop_customer_id
- customers tenant-isolated

Full suite: 117 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 19:43:39 +00:00
parent dfb92bf5e2
commit 75386c354a
13 changed files with 556 additions and 5 deletions
+47
View File
@@ -0,0 +1,47 @@
@extends('shop.layout')
@section('title', 'Contul meu')
@section('content')
@php
$currency = $tenant->settings['currency'] ?? 'MDL';
$statuses = \App\Models\Tenant\OnlineOrder::STATUSES;
@endphp
<h1 style="font-size:22px;margin-bottom:16px;">Salut, {{ $customer->name }}!</h1>
<div class="card" style="margin-bottom:16px;">
<h3 style="font-size:15px;margin-bottom:10px;">Date contact</h3>
<p class="muted">📞 {{ $customer->phone }}</p>
@if ($customer->email)<p class="muted">✉️ {{ $customer->email }}</p>@endif
</div>
<h2 style="font-size:18px;margin-bottom:12px;">Comenzile mele ({{ $orders->count() }})</h2>
@if ($orders->isEmpty())
<div class="card" style="text-align:center;padding:32px;">
<p class="muted">Nu ai nicio comandă încă.</p>
<a class="btn" href="/shop" style="margin-top:12px;">Vezi catalogul</a>
</div>
@else
<div class="card">
<table class="cart">
<thead>
<tr>
<th>Nr.</th><th>Data</th><th>Articole</th><th class="r">Total</th><th>Status</th><th></th>
</tr>
</thead>
<tbody>
@foreach ($orders as $order)
<tr>
<td><strong>#{{ $order->number }}</strong></td>
<td>{{ $order->created_at->format('d.m.Y') }}</td>
<td>{{ $order->items()->count() }}</td>
<td class="r">{{ number_format((float) $order->total, 2) }} {{ $currency }}</td>
<td><span class="status-pill" style="font-size:11px;">{{ $statuses[$order->status] ?? $order->status }}</span></td>
<td><a href="{{ $order->trackingUrl() }}" class="muted" style="text-decoration:underline;">Detalii </a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@endsection
+31
View File
@@ -0,0 +1,31 @@
@extends('shop.layout')
@section('title', 'Login')
@section('content')
<div style="max-width:380px;margin:0 auto;">
<h1 style="font-size:22px;margin-bottom:16px;">Intră în cont</h1>
@if ($errors->any())
<div class="card" style="border-color:#fca5a5;background:#fef2f2;margin-bottom:14px;">
<ul style="margin:0;padding-left:18px;color:#991b1b;font-size:14px;">
@foreach ($errors->all() as $e)<li>{{ $e }}</li>@endforeach
</ul>
</div>
@endif
<form method="POST" action="/shop/login" class="card">
@csrf
<div class="field"><label>Telefon *</label>
<input type="text" name="phone" value="{{ old('phone') }}" required placeholder="+373…">
</div>
<div class="field"><label>Parolă *</label>
<input type="password" name="password" required>
</div>
<button type="submit" class="btn block">Intră</button>
</form>
<p class="muted" style="text-align:center;margin-top:12px;">
Nu ai cont? <a href="/shop/register" style="color:inherit;text-decoration:underline;">Înregistrare</a>
</p>
</div>
@endsection
@@ -0,0 +1,40 @@
@extends('shop.layout')
@section('title', 'Înregistrare')
@section('content')
<div style="max-width:420px;margin:0 auto;">
<h1 style="font-size:22px;margin-bottom:16px;">Înregistrare cont</h1>
@if ($errors->any())
<div class="card" style="border-color:#fca5a5;background:#fef2f2;margin-bottom:14px;">
<ul style="margin:0;padding-left:18px;color:#991b1b;font-size:14px;">
@foreach ($errors->all() as $e)<li>{{ $e }}</li>@endforeach
</ul>
</div>
@endif
<form method="POST" action="/shop/register" class="card">
@csrf
<div class="field"><label>Nume *</label>
<input type="text" name="name" value="{{ old('name') }}" required>
</div>
<div class="field"><label>Telefon *</label>
<input type="text" name="phone" value="{{ old('phone') }}" required placeholder="+373…">
</div>
<div class="field"><label>Email</label>
<input type="email" name="email" value="{{ old('email') }}">
</div>
<div class="field"><label>Parolă *</label>
<input type="password" name="password" required minlength="6">
</div>
<div class="field"><label>Confirmă parola *</label>
<input type="password" name="password_confirmation" required minlength="6">
</div>
<button type="submit" class="btn block">Creează cont</button>
</form>
<p class="muted" style="text-align:center;margin-top:12px;">
Ai deja cont? <a href="/shop/login" style="color:inherit;text-decoration:underline;">Login</a>
</p>
</div>
@endsection
+3 -3
View File
@@ -21,15 +21,15 @@
@csrf
<div class="field">
<label>Nume complet *</label>
<input type="text" name="customer_name" value="{{ old('customer_name') }}" required>
<input type="text" name="customer_name" value="{{ old('customer_name', ($customer ?? null)?->name) }}" required>
</div>
<div class="field">
<label>Telefon *</label>
<input type="text" name="customer_phone" value="{{ old('customer_phone') }}" required placeholder="+373…">
<input type="text" name="customer_phone" value="{{ old('customer_phone', ($customer ?? null)?->phone) }}" required placeholder="+373…">
</div>
<div class="field">
<label>Email</label>
<input type="email" name="customer_email" value="{{ old('customer_email') }}">
<input type="email" name="customer_email" value="{{ old('customer_email', ($customer ?? null)?->email) }}">
</div>
<div class="field">
<label>Livrare *</label>
+9
View File
@@ -72,6 +72,15 @@
<a href="/shop/cart">🛒 Coș
@if (($cartCount ?? 0) > 0)<span class="cart-badge">{{ $cartCount }}</span>@endif
</a>
@auth('shop')
<a href="/shop/account">👤 {{ Auth::guard('shop')->user()->name }}</a>
<form method="POST" action="/shop/logout" style="display:inline;">@csrf
<button type="submit" style="background:transparent;border:0;color:inherit;cursor:pointer;font:inherit;">Ieșire</button>
</form>
@else
<a href="/shop/login">Login</a>
<a href="/shop/register" style="background:rgba(255,255,255,.2);border-radius:6px;padding:4px 10px;">Înregistrare</a>
@endauth
</nav>
</div>
</header>