diff --git a/routes/web.php b/routes/web.php index 3db31e97..4ed7c364 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6060,36 +6060,41 @@ Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $po // Aggiorna Preorder $product = Product::where('sku', $idarticolo)->first(); + $product_id = $product['id']; + if ($product) { echo "Prodotto trovato: " . $product['name'] . "
"; - $preorder = true; + $stock_status = DB::table('wp_postmeta') + ->where('post_id', $product_id) + ->where('meta_key', '_stock_status') + ->value('meta_value'); - if ($preorder) { - $data = [ - 'stock_status' => 'preorder', - 'meta_data' => [ - [ - 'key' => '_preorder_date', - 'value' => now()->format('Y-m-d H:i:s') - ] - ] - ]; + echo "Stock Status Iniziale: " . $stock_status; - // Salva le modifiche - $updated = Product::update($product['id'], $data); + // Imposta lo stato del prodotto in "pre-order" + DB::table('wp_postmeta') + ->updateOrInsert( + ['post_id' => $product_id, 'meta_key' => '_stock_status'], + ['meta_value' => 'preorder'] + ); - if($updated) { - $product = Product::where('sku', $idarticolo)->first(); - echo "DOPO:"; - dd($product); - echo "Lo stato e la data di preordine sono stati aggiornati con successo."; - } else { - echo "Si è verificato un problema durante l'aggiornamento."; - } - } + // Aggiungi la data di preordine + $output = DB::table('wp_postmeta') + ->updateOrInsert( + ['post_id' => $product_id, 'meta_key' => '_preorder_date'], + ['meta_value' => now()->format('Y-m-d H:i:s')] + ); + + $stock_status = DB::table('wp_postmeta') + ->where('post_id', $product_id) + ->where('meta_key', '_stock_status') + ->value('meta_value'); + + echo "*** Stock Status Finale: " . $stock_status; + echo "Prodotto impostato correttamente in modalità pre-order. (" . $output . ")
"; } else { echo "Il prodotto non esiste"; }