This commit is contained in:
paoloar77
2024-05-18 13:45:55 +02:00
parent 73e6e6f612
commit 6746cfec48

View File

@@ -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'] . "<br>";
$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 . ")<br>";
} else {
echo "Il prodotto non esiste";
}