This commit is contained in:
paoloar77
2024-05-19 13:06:17 +02:00
parent 62153977b4
commit efdd9a098c
2 changed files with 43 additions and 25 deletions

36
app/CustomFuncPao.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
function showarray($array)
{
echo '<pre>' . json_encode($array, JSON_PRETTY_PRINT) . '</pre>';
};
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
}
}
}

View File

@@ -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 '<pre>' . json_encode($array, JSON_PRETTY_PRINT) . '</pre>';
};
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 {
@@ -6102,8 +6081,8 @@ Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $po
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'] . "<br>";