diff --git a/routes/web.php b/routes/web.php index 241d4c47..2ea850c7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2255,17 +2255,25 @@ Route::post('/updatecreate', function (Request $request) { $creatoNuovoCliente = false; - 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; - $customer['meta_data'] = $request->meta_data; - } - $productLogger->addLog('', 'crea Cliente: ' . $customer['last_name'] . " " . $customer['first_name']); + // if ($CodClienteInternet > 0) { + // $customer = Customer::find($CodClienteInternet); + // } else { + // $customer = $request; + + $nome = $request->billing['first_name']; + $cognome = $request->billing['last_name']; + $indirizzo1 = $request->billing['address_1']; + $indirizzo2 = isset($request->billing['address_2']) ? $request->billing['address_2'] : ''; + $citta = $request->billing['city']; + $postcode = $request->billing['postcode']; + $provincia = $request->billing['state']; + $telefono = $request->billing['phone']; + $email = $request->billing['phone']; + $nazione = $request->billing['country']; + + $meta_data = $request->meta_data; + // } + $productLogger->addLog('', 'crea Cliente: ' . $nome . " " . $cognome); $cliente = null; if ($clienteinGM) { @@ -2278,19 +2286,24 @@ Route::post('/updatecreate', function (Request $request) { $creatoNuovoCliente = true; } - $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 : ''; - $cliente->Citta = isset($customer['billing']->city) ? $customer['billing']->city : ''; - $cliente->Cap = isset($customer['billing']->postcode) ? $customer['billing']->postcode : ''; - $cliente->Provincia = isset($customer['billing']->state) ? $customer['billing']->state : ''; - $cliente->Telefono = isset($customer['billing']->phone) ? $customer['billing']->phone : ''; - $cliente->Email = isset($customer['billing']->email) ? $customer['billing']->email : ''; - $cliente->IdNazione = 227; + $cliente->CodClienteInternet = $CodClienteInternet; + $cliente->Nominativo = $nome . " " . $cognome; + $cliente->Indirizzo = $indirizzo1 . ($indirizzo2 ? (' ' . $indirizzo2) : ''); + $cliente->Citta = $citta; + $cliente->Cap = $postcode; + $cliente->Provincia = $provincia; + $cliente->Telefono = $telefono; + $cliente->Email = $email; + if ($nazione == 'IT') { + $cliente->IdNazione = 227; // ITALIA + } else { + //++DA FARE !! PER ALTRE NAZIONI + $cliente->IdNazione = $nazione; + } + $cliente->IdInternet = $myidInternet; - $metas = $customer['meta_data']; try { - foreach ($metas as $meta) { + foreach ($meta_data as $meta) { if ($meta->key == 'cod_fiscale') { $cliente->CodiceFiscale = $meta->value; @@ -2301,9 +2314,6 @@ Route::post('/updatecreate', function (Request $request) { } catch (\Throwable $th) { $productLogger->addLog('', 'Errore: ' . $th->getMessage()); } - if ($creatoNuovoCliente) { - $cliente->IdInternet = $myidInternet; - } $productLogger->addLog('', ' ...fine compilazione campi Cliente' . json_encode($cliente)); try { @@ -2317,16 +2327,34 @@ Route::post('/updatecreate', function (Request $request) { if ($changedest) { $productLogger->addLog('', 'Change Destinazione:'); $clientedest = new Clientegmdest(); - $clientedest->CodDestInternet = $request->customer_id; - $clientedest->Nominativo = $request->shipping['last_name'] ?? ''; - $clientedest->Indirizzo = $request->shipping['address_1'] ?? ''; - $clientedest->Indirizzo .= $request->shipping['address_2'] ?? ''; - $clientedest->Citta = $request->shipping['city'] ?? ''; - $clientedest->Cap = $request->shipping['postcode'] ?? ''; - $clientedest->Provincia = $request->shipping['state'] ?? ''; - $clientedest->Telefono = $request->shipping['phone'] ?? ''; - $clientedest->IdNazione = 227; - $clientedest->IdInternet = $request->id; + + $nome = $request->shipping['first_name']; + $cognome = $request->shipping['last_name']; + $indirizzo1 = $request->shipping['address_1']; + $indirizzo2 = isset($request->shipping['address_2']) ? $request->shipping['address_2'] : ''; + $citta = $request->shipping['city']; + $postcode = $request->shipping['postcode']; + $provincia = $request->shipping['state']; + $telefono = $request->shipping['phone']; + $email = $request->shipping['phone']; + $nazione = $request->shipping['country']; + + $clientedest->CodClienteInternet = $CodClienteInternet; + $clientedest->Nominativo = $nome . " " . $cognome; + $clientedest->Indirizzo = $indirizzo1 . ($indirizzo2 ? (' ' . $indirizzo2) : ''); + $clientedest->Citta = $citta; + $clientedest->Cap = $postcode; + $clientedest->Provincia = $provincia; + $clientedest->Telefono = $telefono; + $clientedest->Email = $email; + if ($nazione == 'IT') { + $clientedest->IdNazione = 227; // ITALIA + } else { + //++DA FARE !! PER ALTRE NAZIONI + $clientedest->IdNazione = $nazione; + } + $clientedest->IdInternet = $myidInternet; + $clientedest->save(); try { @@ -5917,181 +5945,6 @@ Route::get('/testclientegm/{id}', function ($id) { echo "
Cliente:" . json_encode($cliente); }); -Route::get('/test_updatecreate', function () { - - $request = '{ - "id": 68121, - "parent_id": 0, - "status": "processing", - "currency": "EUR", - "version": "9.0.2", - "prices_include_tax": true, - "date_created": "2024-07-11T12:48:56", - "date_modified": "2024-07-11T12:49:00", - "discount_total": "0.00", - "discount_tax": "0.00", - "shipping_total": "0.00", - "shipping_tax": "0.00", - "cart_tax": "0.00", - "total": "9.98", - "total_tax": "0.00", - "customer_id": 81, - "order_key": "wc_order_Uyz0DGlMoozIp", - "billing": { - "first_name": "TEST PAOLO", - "last_name": "TEST PAOLO", - "company": null, - "address_1": "TEST DI PAOLO NON SPEDIRE", - "address_2": null, - "city": "ROMA", - "state": "RM", - "postcode": "47900", - "country": "IT", - "email": "surya@riso.app", - "phone": null - }, - "shipping": { - "first_name": "TEST PAOLO", - "last_name": "TEST PAOLO", - "company": null, - "address_1": "TEST DI PAOLO NON SPEDIRE", - "address_2": null, - "city": "ROMA", - "state": "RM", - "postcode": "47900", - "country": "IT", - "phone": null - }, - "payment_method": "test", - "payment_method_title": "Test Pagamento per PROVE", - "transaction_id": null, - "customer_ip_address": "172.71.99.230", - "customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/126.0.0.0 Safari\/537.36", - "created_via": "checkout", - "customer_note": null, - "date_completed": null, - "date_paid": "2024-07-11T12:49:00", - "cart_hash": "df374a92c5ab9fc0895aea1509930d7f", - "number": "68121", - "meta_data": [ - { - "id": 1382750, - "key": "is_vat_exempt", - "value": "no" - }, - { - "id": 1382751, - "key": "yaydp_product_pricing_rules", - "value": [] - }, - { - "id": 1382752, - "key": "yaydp_cart_discount_rules", - "value": [] - }, - { - "id": 1382753, - "key": "yaydp_checkout_fee_rules", - "value": [] - } - ], - "line_items": [ - { - "id": 202, - "name": "Cos\u00ec come sei! - Nuovo", - "product_id": 64524, - "variation_id": 64525, - "quantity": 1, - "tax_class": null, - "subtotal": "9.98", - "subtotal_tax": "0.00", - "total": "9.98", - "total_tax": "0.00", - "taxes": [], - "meta_data": [ - { - "id": 1733, - "key": "pa_versione", - "value": "nuovo", - "display_key": "Versione", - "display_value": "Nuovo" - }, - { - "id": 1740, - "key": "_reduced_stock", - "value": "1", - "display_key": "_reduced_stock", - "display_value": "1" - } - ], - "sku": "21897", - "price": 9.975, - "image": { - "id": 65079, - "src": "https:\/\/i0.wp.com\/www.fioredellavita.it\/wp-content\/uploads\/2024\/04\/cosi-come-sei.jpg?fit=450%2C369&ssl=1" - }, - "parent_name": "Cos\u00ec come sei!" - } - ], - "tax_lines": [], - "shipping_lines": [ - { - "id": 203, - "method_title": "Spedizione gratuita", - "method_id": "free_shipping", - "instance_id": "2", - "total": "0.00", - "total_tax": "0.00", - "taxes": [], - "meta_data": [ - { - "id": 1739, - "key": "Prodotti", - "value": "Cos\u00ec come sei! - Nuovo × 1", - "display_key": "Prodotti", - "display_value": "Cos\u00ec come sei! - Nuovo × 1" - } - ] - } - ], - "fee_lines": [], - "coupon_lines": [], - "refunds": [], - "payment_url": "https:\/\/www.fioredellavita.it\/pagamento\/order-pay\/68121\/?pay_for_order=true&key=wc_order_Uyz0DGlMoozIp", - "is_editable": false, - "needs_payment": false, - "needs_processing": true, - "date_created_gmt": "2024-07-11T10:48:56", - "date_modified_gmt": "2024-07-11T10:49:00", - "date_completed_gmt": null, - "date_paid_gmt": "2024-07-11T10:49:00", - "currency_symbol": "\u20ac", - "_links": { - "self": [ - { - "href": "https:\/\/www.fioredellavita.it\/wp-json\/wc\/v3\/orders\/68121" - } - ], - "collection": [ - { - "href": "https:\/\/www.fioredellavita.it\/wp-json\/wc\/v3\/orders" - } - ], - "customer": [ - { - "href": "https:\/\/www.fioredellavita.it\/wp-json\/wc\/v3\/customers\/81" - } - ] - } - }'; - - $requestObject = json_decode($request); - - echo 'REQUEST OBJECT: ' . json_encode($requestObject, JSON_PRETTY_PRINT) . PHP_EOL; - - updateCreate($requestObject); -}); - Route::get('/test31', function () { $ora_update = Carbon::now(); $settingora = Setting::where('key', 'update_products')->first();