This commit is contained in:
paoloar77
2025-01-16 09:28:55 +01:00
parent 0b4ec86cba
commit 64ecadce59

View File

@@ -1144,20 +1144,24 @@ class ArticleFormatter
private static function findInsideProduct($product, $field) private static function findInsideProduct($product, $field)
{ {
try {
// Se il campo specificato non è presente, restituisce null // Se il campo specificato non è presente, restituisce null
if (!isset($product['meta_data']) || !is_array($product['meta_data'])) { if (!isset($product->meta_data) || !is_array($product->meta_data)) {
return null; return null;
} }
// Cerca nella meta_data il valore corrispondente alla chiave specificata // Cerca nella meta_data il valore corrispondente alla chiave specificata
foreach ($product['meta_data'] as $meta) { foreach ($product->meta_data as $meta) {
if (isset($meta['key']) && $meta['key'] === $field) { if (isset($meta->key) && $meta->key === $field) {
return $meta['value']; return $meta->value; // Accedi come oggetto
} }
} }
// Restituisce null se non trovato // Restituisce null se non trovato
return null; return null;
} catch (Exception $e) {
echo $e->getMessage();
}
} }
} }