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:
@@ -155,11 +155,13 @@ class ShopController extends Controller
|
||||
if (empty($cart)) return redirect('/shop');
|
||||
|
||||
$subtotal = collect($cart)->sum(fn ($i) => $i['price'] * $i['qty']);
|
||||
$customer = \Illuminate\Support\Facades\Auth::guard('shop')->user();
|
||||
|
||||
return view('shop.checkout', [
|
||||
'tenant' => $tenant,
|
||||
'cart' => $cart,
|
||||
'subtotal' => $subtotal,
|
||||
'customer' => $customer,
|
||||
'deliveryOptions' => (array) data_get($tenant->settings, 'shop.delivery_methods', ['pickup']),
|
||||
'cartCount' => $this->cartCount(),
|
||||
]);
|
||||
@@ -188,9 +190,13 @@ class ShopController extends Controller
|
||||
$deliveryFee = ($freeOver > 0 && $subtotal >= $freeOver) ? 0.0 : $fee;
|
||||
}
|
||||
|
||||
$order = DB::transaction(function () use ($tenant, $cart, $data, $deliveryFee) {
|
||||
$shopCustomer = \Illuminate\Support\Facades\Auth::guard('shop')->user();
|
||||
|
||||
$order = DB::transaction(function () use ($tenant, $cart, $data, $deliveryFee, $shopCustomer) {
|
||||
$order = OnlineOrder::create([
|
||||
'number' => OnlineOrder::generateNumber($tenant->id),
|
||||
'shop_customer_id' => $shopCustomer?->id,
|
||||
'client_id' => $shopCustomer?->client_id,
|
||||
'customer_name' => $data['customer_name'],
|
||||
'customer_phone' => $data['customer_phone'],
|
||||
'customer_email' => $data['customer_email'] ?? null,
|
||||
|
||||
Reference in New Issue
Block a user