This commit is contained in:
paoloar77
2024-05-18 15:27:12 +02:00
parent 6746cfec48
commit 81a90fdda7
13 changed files with 279 additions and 516 deletions

View File

@@ -20,6 +20,10 @@ use Carbon\Carbon;
use Illuminate\Support\Facades\Route;
use Codexshaper\WooCommerce\Facades\WooCommerce;
use App\Models\Post;
use App\Models\PostMeta;
/*
|--------------------------------------------------------------------------
| Web Routes
@@ -6065,36 +6069,23 @@ Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $po
if ($product) {
echo "Prodotto trovato: " . $product['name'] . "<br>";
$stock_status = DB::table('wp_postmeta')
->where('post_id', $product_id)
->where('meta_key', '_stock_status')
->value('meta_value');
$post_meta_data = PostMeta::where('post_id', $product_id)->get();
$stock_status = $post_meta_data['_stock_status'];
echo "Stock Status Iniziale: " . $stock_status;
// Imposta lo stato del prodotto in "pre-order"
DB::table('wp_postmeta')
->updateOrInsert(
['post_id' => $product_id, 'meta_key' => '_stock_status'],
['meta_value' => 'preorder']
);
$campo = '_stock_status';
$valore = 'preorder';
// 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')]
);
$rowCount = PostMeta::where('post_id', $product_id)
->update([$campo => $valore]);
$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 . ")<br>";
if ($rowCount > 0) {
echo "*** Nuovo valore: " . $valore . " ***<br> Righe aggiornate: " . $rowCount;
} else {
echo "Errore: Nessuna riga aggiornata";
}
} else {
echo "Il prodotto non esiste";
}