From 965c997d301bc445cc24efe28f4876d0f4783ef0 Mon Sep 17 00:00:00 2001 From: paoloar77 Date: Tue, 2 Jul 2024 13:50:38 +0200 Subject: [PATCH] corretto problema sul customer, che se era a zero non andava avanti. --- routes/web.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/routes/web.php b/routes/web.php index a861b801..31f483c7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2222,10 +2222,30 @@ Route::post('/updatecreate', function (Request $request) { } $productLogger->addLog('', 'Cerco il customer_id: ' . $request->customer_id); - $customer = Customer::find($request->customer_id); + + $CodClienteInternet = $request->customer_id; + + if ($CodClienteInternet > 0) { + $customer = Customer::find($CodClienteInternet); + } else { + $customer = $request; + $customer['id'] = 0; + $customer['last_name'] = $request->billing['last_name']; + $customer['first_name'] = $request->billing['first_name']; + $customer['billing'] = $request->billing; + } $productLogger->addLog('', 'crea Cliente: ' . $customer['last_name'] . " " . $customer['first_name']); $cliente = new Clientegm(); + + if ($CodClienteInternet > 0) { + $clients = Clientegm::where('CodClienteInternet', $CodClienteInternet)->get(); + // se l'array non รจ vuoto + if (!$clients->isEmpty()) { + $cliente = $clients->first(); + } + } + $cliente->CodClienteInternet = isset($customer['id']) ? $customer['id'] : ''; $cliente->Nominativo = isset($customer['last_name']) ? $customer['last_name'] . " " . $customer['first_name'] : ''; $cliente->Indirizzo = isset($customer['billing']->address_1) ? $customer['billing']->address_1 . " " . $customer['billing']->address_2 : ''; @@ -2255,7 +2275,6 @@ Route::post('/updatecreate', function (Request $request) { if ($changedest) { $productLogger->addLog('', 'Change Destinazione:'); $clientedest = new Clientegmdest(); - $clientedest = new Clientegmdest(); $clientedest->CodDestInternet = $request->customer_id; $clientedest->Nominativo = $request->shipping['last_name'] ?? ''; $clientedest->Indirizzo = $request->shipping['address_1'] ?? '';