diff --git a/app/Console/Commands/OrderUpdateGm.php b/app/Console/Commands/OrderUpdateGm.php index fa0dc740..c3645ab9 100755 --- a/app/Console/Commands/OrderUpdateGm.php +++ b/app/Console/Commands/OrderUpdateGm.php @@ -37,42 +37,45 @@ class OrderUpdateGm extends Command } /** - * Execute the console command. + * Handles the order update process from GM. + * + * This command fetches orders from WooCommerce with a pending, processing, or on-hold status, and checks if they exist in the GM system. If an order is found in GM, it checks the status and updates the WooCommerce order accordingly. If an order is updated, an email is sent to the admin with the details. * * @return int */ public function handle() { + echo "OrderUpdateGM... "; $productLogger = new ProductLogger(null, 'checkorders', true); $page = 1; $orderupdated = 0; try { $all_orderswoo = new Collection(); // Assicurati che all_orderswoo sia inizializzato se non l'hai già fatto. $page = 1; // Inizializza la pagina - + do { $options = ['per_page' => 100, 'page' => $page, 'status' => ["pending", "processing", "on-hold"]]; $this->info('Fetching orders with options: ' . json_encode($options)); $orderswoo = Order::get($options); // Usa 'get' invece di 'all' - + // Controlla se il risultato è una collezione o un errore if (empty($orderswoo) || $orderswoo->isEmpty()) { $productLogger->addLog('Error', 'No orders returned.'); break; // Esci dal ciclo in caso di errore } - + // Merge le nuove ordinazioni nella collezione esistente $all_orderswoo = $all_orderswoo->merge($orderswoo); $page++; } while ($orderswoo->count() > 0); // Continua finché ci sono ordini - + } catch (\Exception $e) { if (isset($productLogger)) { $productLogger->addLog('Error', $e->getMessage()); $productLogger->setLogandSendEmail('Ordini'); } } - + foreach ($all_orderswoo as $orderwoo) { $productLogger->addLog('', "Processing order #{$orderwoo->id}..."); diff --git a/routes/web.php b/routes/web.php index 7931f229..b6fec46f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2229,7 +2229,7 @@ Route::post('/updatecreate', function (Request $request) { } //$orderold = $productLogger->addLog('', 'Creazione Ordine... codice=' . $request->id); - $order->IdInternet = $request->id; + $order->IdInternet = 'FDV_' . $request->id; $order->Enabled = 1; $order->idSito = 7; $order->DataOra = $request->date_created;