diff --git a/app/CustomFuncPao.php b/app/CustomFuncPao.php new file mode 100644 index 00000000..d4b0fcc7 --- /dev/null +++ b/app/CustomFuncPao.php @@ -0,0 +1,36 @@ +' . json_encode($array, JSON_PRETTY_PRINT) . ''; +}; + +function isKeyPresent($array, $key) +{ + foreach ($array as $item) { + if (isset($item->key) && $item->key === $key) { + return true; + } + } + return false; +} + +function getValueByKey($array, $key) +{ + foreach ($array as $item) { + if (isset($item->key) && $item->key === $key) { + return $item->value; + } + } + return null; // If key is not found +} + +// Funzione per aggiornare il valore di un certo key in un array di oggetti +function updateValueByKey(&$array, $key, $newValue) { + foreach ($array as &$item) { + if ($item['key'] === $key) { + $item['value'] = $newValue; + break; // Se trova il key, termina il loop + } + } +} diff --git a/routes/web.php b/routes/web.php index 49866810..2117971b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -51,6 +51,9 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; +require_once app_path('CustomFuncPao.php'); + + Route::get('/', function () { return view('welcome'); }); @@ -6059,30 +6062,6 @@ Route::get('/ordineclientegm/{id}', function ($id) { Route::get('/provapao', [TestPaoController::class, 'provapao']); -function showarray($array) -{ - echo '
' . json_encode($array, JSON_PRETTY_PRINT) . ''; -}; - -function isKeyPresent($array, $key) -{ - foreach ($array as $item) { - if (isset($item->key) && $item->key === $key) { - return true; - } - } - return false; -} - -function getValueByKey($array, $key) -{ - foreach ($array as $item) { - if (isset($item->key) && $item->key === $key) { - return $item->value; - } - } - return null; // If key is not found -} Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $postid) { try { @@ -6101,9 +6080,9 @@ Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $po $titolo = $product['name']; echo "Prodotto trovato: " . $product['name'] . "StockQty = " . $product['stock_quantity']; + if (isKeyPresent($product['meta_data'], '_is_pre_order')) { - echo "TROVATO ! "; $preorder = getValueByKey($product['meta_data'], '_is_pre_order'); } @@ -6127,6 +6106,9 @@ Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $po $idprodotto = $product['parent_id']; if ($idprodotto > 0) { + updateValueByKey($product['meta_data'], '_is_pre_order', 'true'); + $data['meta_data'] = $product['meta_data']; + $variation = Variation::update($idprodotto, $product['id'], $data); if ($variation) { echo "Aggiornato Preorder: [ParentId=" . $idprodotto . '] ProdId= ' . $product['id'] . ' ' . $variation['name'] . "