diff --git a/routes/web.php b/routes/web.php index e4dc2278..ec36093b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -814,7 +814,7 @@ Route::get('/artlibrousato', function () { } echo "Finito"; */ -}); +}); Route::get( '/test2', @@ -1670,7 +1670,8 @@ Route::get('/autori_test', function () { } }); -function getvalstr($mystr, $value, $separato = false) { +function getvalstr($mystr, $value, $separato = false) +{ $my = ''; if ($mystr) { $my = " " . $mystr . ": " . $value; @@ -1686,7 +1687,6 @@ function getvalstr($mystr, $value, $separato = false) { } return $my; - } @@ -2140,108 +2140,115 @@ Route::post('/updatecreate', function (Request $request) { //dd($webhook); + try { - if (($request->status == 'on-hold' && $request->payment_method == 'bacs') || ($request->status == 'processing' && $request->payment_method == 'wc_gateway_gestpay') || ($request->status == 'processing' && $request->payment_method == 'paypal')) { - $changedest = false; - if (($request->shipping['address_1'] != null && $request->shipping['address_1'] != '' && $request->shipping['address_1'] != $request->billing['address_1']) || ($request->shipping['first_name'] != null && $request->shipping['first_name'] != '' && $request->shipping['first_name'] != $request->billing['first_name'])) { - $changedest = true; - } - //$orderold = - $order = new Order(); - $order->IdInternet = $request->id; - $order->CodClienteInternet = $request->customer_id; - $order->Enabled = 1; - $order->DataOra = $request->date_created; - $order->Note = $request->customer_note; - $order->Totale = $request->total; - if ($request->payment_method == 'wc_gateway_gestpay') { - $order->CodPagamentoGM = 'CARTASELLA'; - } - if ($request->payment_method == 'paypal') { - $order->CodPagamentoGM = '472'; - } - if ($request->payment_method == 'bacs') { - $order->CodPagamentoGM = 'BONIFPOSTALE'; - $order->FlagSospeso = 1; - } - $order->Spedizioniere = 'GLS'; - $order->ImportoSpedizione = $request->shipping_total; + Log::info('updatecreate: ARRIVATO ORDINE'); - if ($changedest) { - $order->CodDestInternet = $request->customer_id; - } - $order->save(); - - $prodotti = $request->line_items; - foreach ($prodotti as $prodotto) { - $orderdetail = new Orderdetail(); - $orderdetail->IdInternet = $request->id; - $sku = $prodotto['sku']; - $codifica = false; - if (strlen($sku) > 7 || strpos($sku, 'USATO') === 0) { - $codifica = true; + if (($request->status == 'on-hold' && $request->payment_method == 'bacs') || ($request->status == 'processing' && $request->payment_method == 'wc_gateway_gestpay') || ($request->status == 'processing' && $request->payment_method == 'paypal')) { + $changedest = false; + if (($request->shipping['address_1'] != null && $request->shipping['address_1'] != '' && $request->shipping['address_1'] != $request->billing['address_1']) || ($request->shipping['first_name'] != null && $request->shipping['first_name'] != '' && $request->shipping['first_name'] != $request->billing['first_name'])) { + $changedest = true; } - if ($codifica) { - - } else { - $orderdetail->CodArticoloGM = intval($prodotto['sku']); + //$orderold = + Log::info('Creazione Ordine... codice=' . $request->id); + $order = new Order(); + $order->IdInternet = $request->id; + $order->CodClienteInternet = $request->customer_id; + $order->Enabled = 1; + $order->DataOra = $request->date_created; + $order->Note = $request->customer_note; + $order->Totale = $request->total; + if ($request->payment_method == 'wc_gateway_gestpay') { + $order->CodPagamentoGM = 'CARTASELLA'; } + if ($request->payment_method == 'paypal') { + $order->CodPagamentoGM = '472'; + } + if ($request->payment_method == 'bacs') { + $order->CodPagamentoGM = 'BONIFPOSTALE'; + $order->FlagSospeso = 1; + } + $order->Spedizioniere = 'GLS'; + $order->ImportoSpedizione = $request->shipping_total; + + if ($changedest) { + $order->CodDestInternet = $request->customer_id; + } + $order->save(); + Log::info('Order:' . json_encode($order)); - - $orderdetail->Qta = $prodotto['quantity']; - $orderdetail->PrezzoLordo = $prodotto['total']; - $orderdetail->Enabled = 1; - $orderdetail->DataOra = $request->date_created; - $orderdetail->save(); - } - $customer = Customer::find($request->customer_id); - $cliente = new Clientegm(); - $cliente->CodClienteInternet = $customer['id']; - $cliente->Nominativo = $customer['last_name'] . " " . $customer['first_name']; - $cliente->Indirizzo = $customer['billing']->address_1 . " " . $customer['billing']->address_2; - $cliente->Citta = $customer['billing']->city; - $cliente->Cap = $customer['billing']->postcode; - $cliente->Provincia = $customer['billing']->state; - $cliente->Telefono = $customer['billing']->phone; - $cliente->Email = $customer['billing']->email; - $cliente->IdNazione = 227; - $metas = $customer['meta_data']; - foreach ($metas as $meta) { + $prodotti = $request->line_items; + foreach ($prodotti as $prodotto) { + $orderdetail = new Orderdetail(); + $orderdetail->IdInternet = $request->id; + $sku = $prodotto['sku']; + $codifica = false; + if (strlen($sku) > 7 || strpos($sku, 'USATO') === 0) { + $codifica = true; + } + if ($codifica) { + } else { + $orderdetail->CodArticoloGM = intval($prodotto['sku']); + Log::info('$orderdetail->CodArticoloGM' . $orderdetail->CodArticoloGM); + } - if ($meta->key == 'cod_fiscale') { - $cliente->CodiceFiscale = $meta->value; - } elseif ($meta->key == 'vat') { - $cliente->PIVA = $meta->value; + Log::info('sku=', $sku); + Log::info('Dettaglio Ordine:' . json_encode($orderdetail)); + + $orderdetail->Qta = $prodotto['quantity']; + $orderdetail->PrezzoLordo = $prodotto['total']; + $orderdetail->Enabled = 1; + $orderdetail->DataOra = $request->date_created; + $orderdetail->save(); } - } - $cliente->IdInternet = $request->id; - $cliente->save(); - if ($changedest) { - $clientedest = new Clientegmdest(); - $clientedest->CodDestInternet = $request->customer_id; - $clientedest->Nominativo = $request->shipping['last_name'] . " " . $request->shipping['first_name']; - $clientedest->Indirizzo = $request->shipping['address_1'] . " " . $request->shipping['address_2']; - $clientedest->Citta = $request->shipping['city']; - $clientedest->Cap = $request->shipping['postcode']; - $clientedest->Provincia = $request->shipping['state']; - $clientedest->Telefono = $request->shipping['phone']; + $customer = Customer::find($request->customer_id); + Log::info('crea Cliente: ' . $customer['last_name'] . " " . $customer['first_name']); + $cliente = new Clientegm(); + $cliente->CodClienteInternet = $customer['id']; + $cliente->Nominativo = $customer['last_name'] . " " . $customer['first_name']; + $cliente->Indirizzo = $customer['billing']->address_1 . " " . $customer['billing']->address_2; + $cliente->Citta = $customer['billing']->city; + $cliente->Cap = $customer['billing']->postcode; + $cliente->Provincia = $customer['billing']->state; + $cliente->Telefono = $customer['billing']->phone; + $cliente->Email = $customer['billing']->email; $cliente->IdNazione = 227; - $clientedest->IdInternet = $request->id; - $clientedest->save(); - } - Log::debug($request->all()); - Log::info('Inserito ordine'); - } //end if status - - - - - + $metas = $customer['meta_data']; + foreach ($metas as $meta) { + if ($meta->key == 'cod_fiscale') { + $cliente->CodiceFiscale = $meta->value; + } elseif ($meta->key == 'vat') { + $cliente->PIVA = $meta->value; + } + } + $cliente->IdInternet = $request->id; + $cliente->save(); + Log::info('Cliente:' . json_encode($cliente)); + if ($changedest) { + $clientedest = new Clientegmdest(); + $clientedest->CodDestInternet = $request->customer_id; + $clientedest->Nominativo = $request->shipping['last_name'] . " " . $request->shipping['first_name']; + $clientedest->Indirizzo = $request->shipping['address_1'] . " " . $request->shipping['address_2']; + $clientedest->Citta = $request->shipping['city']; + $clientedest->Cap = $request->shipping['postcode']; + $clientedest->Provincia = $request->shipping['state']; + $clientedest->Telefono = $request->shipping['phone']; + $cliente->IdNazione = 227; + $clientedest->IdInternet = $request->id; + $clientedest->save(); + Log::info('Cliente Dest:' . json_encode($clientedest)); + } + Log::debug($request->all()); + Log::info('Inserito ordine'); + } //end if status + } catch (Exception $e) { + Log::error($e->getMessage()); + } }); @@ -5991,7 +5998,7 @@ Route::get('/mylinkspao', function (Illuminate\Http\Request $request) { Route::get('/handle-article-action-pao/{id}/{action}', function ($id, $action) { set_time_limit(0); ini_set("memory_limit", "512M"); - + if ($action == 'search') { // Logica di ricerca dell'articolo return loadArticleByIdArticle($id); @@ -6020,4 +6027,3 @@ Route::get('/handle-article-action-pao/{id}/{action}', function ($id, $action) { Route::get('/product/{sku}', [TestPaoController::class, 'getProductBySku']); -