Cambiato idInternet con 'FDV_' aggiunto all'inizio.

This commit is contained in:
paoloar77
2024-10-03 11:53:26 +02:00
parent cdf3ed84f2
commit c3c41bd1e7
2 changed files with 10 additions and 7 deletions

View File

@@ -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 * @return int
*/ */
public function handle() public function handle()
{ {
echo "OrderUpdateGM... ";
$productLogger = new ProductLogger(null, 'checkorders', true); $productLogger = new ProductLogger(null, 'checkorders', true);
$page = 1; $page = 1;
$orderupdated = 0; $orderupdated = 0;
try { try {
$all_orderswoo = new Collection(); // Assicurati che all_orderswoo sia inizializzato se non l'hai già fatto. $all_orderswoo = new Collection(); // Assicurati che all_orderswoo sia inizializzato se non l'hai già fatto.
$page = 1; // Inizializza la pagina $page = 1; // Inizializza la pagina
do { do {
$options = ['per_page' => 100, 'page' => $page, 'status' => ["pending", "processing", "on-hold"]]; $options = ['per_page' => 100, 'page' => $page, 'status' => ["pending", "processing", "on-hold"]];
$this->info('Fetching orders with options: ' . json_encode($options)); $this->info('Fetching orders with options: ' . json_encode($options));
$orderswoo = Order::get($options); // Usa 'get' invece di 'all' $orderswoo = Order::get($options); // Usa 'get' invece di 'all'
// Controlla se il risultato è una collezione o un errore // Controlla se il risultato è una collezione o un errore
if (empty($orderswoo) || $orderswoo->isEmpty()) { if (empty($orderswoo) || $orderswoo->isEmpty()) {
$productLogger->addLog('Error', 'No orders returned.'); $productLogger->addLog('Error', 'No orders returned.');
break; // Esci dal ciclo in caso di errore break; // Esci dal ciclo in caso di errore
} }
// Merge le nuove ordinazioni nella collezione esistente // Merge le nuove ordinazioni nella collezione esistente
$all_orderswoo = $all_orderswoo->merge($orderswoo); $all_orderswoo = $all_orderswoo->merge($orderswoo);
$page++; $page++;
} while ($orderswoo->count() > 0); // Continua finché ci sono ordini } while ($orderswoo->count() > 0); // Continua finché ci sono ordini
} catch (\Exception $e) { } catch (\Exception $e) {
if (isset($productLogger)) { if (isset($productLogger)) {
$productLogger->addLog('Error', $e->getMessage()); $productLogger->addLog('Error', $e->getMessage());
$productLogger->setLogandSendEmail('Ordini'); $productLogger->setLogandSendEmail('Ordini');
} }
} }
foreach ($all_orderswoo as $orderwoo) { foreach ($all_orderswoo as $orderwoo) {
$productLogger->addLog('', "Processing order #{$orderwoo->id}..."); $productLogger->addLog('', "Processing order #{$orderwoo->id}...");

View File

@@ -2229,7 +2229,7 @@ Route::post('/updatecreate', function (Request $request) {
} }
//$orderold = //$orderold =
$productLogger->addLog('', 'Creazione Ordine... codice=' . $request->id); $productLogger->addLog('', 'Creazione Ordine... codice=' . $request->id);
$order->IdInternet = $request->id; $order->IdInternet = 'FDV_' . $request->id;
$order->Enabled = 1; $order->Enabled = 1;
$order->idSito = 7; $order->idSito = 7;
$order->DataOra = $request->date_created; $order->DataOra = $request->date_created;