aggiorna quantita in base se è in prevendita

This commit is contained in:
paoloar77
2024-05-20 01:23:47 +02:00
parent a983293991
commit 024144a942
4 changed files with 167 additions and 114 deletions

View File

@@ -6066,112 +6066,7 @@ Route::get('/provapao', [TestPaoController::class, 'provapao']);
Route::get('/aggiornapreorder/{idarticolo}/{aggiornapreordine}', function ($idarticolo, $aggiornapreordine) {
try {
// Aggiorna Preorder
$product = Product::where('sku', $idarticolo)->first();
// get the article by product
$article = Article::where('IdArticolo', $idarticolo)->first();
// showarray($article);
showarray($product);
$product_id = $product['id'];
$sku = $product['sku'];
$campoPreOrder = '_wpro_variable_is_preorder';
if ($product) {
$titolo = $product['name'];
echo "Prodotto trovato: " . $product['name'] . "StockQty = " . $product['stock_quantity'] . "<br>";
$preorder = false;
if (isKeyPresent($product['meta_data'], $campoPreOrder)) {
$preorder = getValueByKey($product['meta_data'], $campoPreOrder);
}
if ($preorder) {
if ($preorder === 'true') {
echo "<span class='badge badge-success' style='color: green;'>PREORDER SI !</span>: " . $preorder;
} else {
echo "<span class='badge badge-success' style='color: green;'>PREORDER:</span>: " . $preorder;
}
} else {
echo "<span style='color: red;'>preorder non presente !</span>: ";
}
echo "<br>";
/*foreach ($variations as $variation) {
$found_key_version = array_search('Versione', array_column($variation->attributes, 'name'));
if ($variation->attributes[$found_key_version]->option == 'Nuovo') {
$id = 0;
}
}*/
if ($aggiornapreordine === '1') {
$data = [];
$datenow = date('Y-m-d');
$idprodotto = $product['parent_id'];
if ($idprodotto > 0) {
echo "Variazioni: " . $product['parent_id'] . "<br>";
$variations = Variation::all($product['parent_id']);
showarray($variations);
for ($i = 0; $i < count($variations); $i++) {
$variation = $variations[$i];
if ($variation->id == $product['id']) {
// convert object into array
$data = json_decode(json_encode($variation), true);
break;
}
}
$data['stock_quantity'] = '1000';
echo "Data:";
showarray($data);
$agg = true;
$data['meta_data'] = $product['meta_data'];
if ($agg) {
updateValueByKey($data['meta_data'], $campoPreOrder, 'yes');
updateValueByKey($data['meta_data'], '_is_pre_order', 'yes');
updateValueByKey($data['meta_data'], '_pre_order_date', $datenow);
updateValueByKey($data['meta_data'], '_wpro_date_label_variable', '');
updateValueByKey($data['meta_data'], '_wpro_no_date_label_variable', '');
updateValueByKey($data['meta_data'], '_wpro_manage_price_variable', '');
updateValueByKey($data['meta_data'], '_wpro_price_variable', '');
updateValueByKey($data['meta_data'], '_wpro_label_variable', 'Pre Ordinalo!');
updateValueByKey($data['meta_data'], '_wpro_price_type_variable', 'manual');
updateValueByKey($data['meta_data'], '_wpro_amount_price_variable', 'fixed');
updateValueByKey($data['meta_data'], '_wpro_date_variable', '');
updateValueByKey($data['meta_data'], '_wpro_time_variable', '');
updateValueByKey($data['meta_data'], '_rank_math_gtin_code', '');
}
echo "<br>Dati da Salvare:";
showarray($data);
$variation = Variation::update($idprodotto, $product['id'], $data);
// Product::update($idprodotto, $data);
if ($variation) {
echo "Aggiornato Preorder: [ParentId=" . $idprodotto . '] ProdId= ' . $product['id'] . ' ' . $variation['name'] . "<br>";
}
// $log2 .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . ' - Articolo aggiornato - ' . $variation['permalink'] . "\n";
}
}
} else {
echo "Il prodotto non esiste";
}
} catch (Exception $e) {
echo "Errore: " . $e->getMessage();
}
setPreOrder($idarticolo, $aggiornapreordine, true);
});
Route::get('/paolibri', function () {