diff --git a/app/CustomFuncPao.php b/app/CustomFuncPao.php
index 2d4d81fe..584fc777 100644
--- a/app/CustomFuncPao.php
+++ b/app/CustomFuncPao.php
@@ -32,7 +32,7 @@ use Illuminate\Support\Facades\Request;
define('QTA_IN_PREVENDITA', 10000);
define('QTA_MINIMA_PER_PREVENDITA', 9000);
-define('CAMPO_PREORDINE','_ywpo_preorder');
+define('CAMPO_PREORDINE', '_ywpo_preorder');
setlocale(LC_TIME, 'it_IT.UTF-8');
@@ -955,6 +955,21 @@ function showprice($prezzo)
}
}
+function findInsideProduct(array $prodotto, string $miocampo): ?string
+{
+ if (!isset($prodotto['meta_data']) || !is_array($prodotto['meta_data'])) {
+ return null;
+ }
+
+ foreach ($prodotto['meta_data'] as $meta) {
+ if ($meta['key'] === $miocampo) {
+ return $meta['value'];
+ }
+ }
+
+ return null;
+}
+
function getRigaArticoloByArt($article, $ind, $sep)
{
@@ -993,6 +1008,9 @@ function getRigaArticoloByArt($article, $ind, $sep)
}
}
+ $preorder = findInsideProduct($prodotto, CAMPO_PREORDINE);
+ $preorder_attivato = $preorder === 'yes';
+
// echo '[' . $ind . ']' . $sep . $mydatestr . $sep . $article->IdArticolo . $sep . $article->Titolo . $sep . $article->DescrizioneStatoProdotto . $sep . $article->DescrizioneFormato . ' [Quantita = ' . $article->QtaDisponibile . ']';
$myview = '[' . $ind . ']' . $sep .
'' . $article->IdArticolo . '' . $sep .
@@ -1004,7 +1022,7 @@ function getRigaArticoloByArt($article, $ind, $sep)
' [' . showprice($prezzo) . ' ]' . $sep .
'[In Stock = ' . $qtyinstock . ']' . $sep;
- if ($qtyinstock < QTA_MINIMA_PER_PREVENDITA) {
+ if (!$preorder_attivato || $qtyinstock < QTA_MINIMA_PER_PREVENDITA) {
$myview .= 'Imposta in PRE-ORDINE!' . $sep;
} else {
$myview .= 'Impostalo Non Disponibile' . $sep;
@@ -1015,14 +1033,13 @@ function getRigaArticoloByArt($article, $ind, $sep)
if ($prodotto) {
- if (isset($prodotto[CAMPO_PREORDINE])) {
- $str .= '
PREORDINE: ' . $prodotto[CAMPO_PREORDINE] . '';
- }
- if (isset($prodotto['_wpro_label_variable'])) {
- $str .= 'Etichetta: ' . $prodotto['_wpro_label_variable'];
- }
- if (isset($prodotto['_wpro_date_variable'])) {
- $str .= 'Data Preordine: ' . $prodotto['_wpro_date_variable'];
+ $datepreorder = findInsideProduct($prodotto, '_ywpo_for_sale_date');
+
+ if ($preorder_attivato) {
+ $str .= ' PREORDINE ATTIVO! ';
+ if ($datepreorder) {
+ $str .= ' Data PreOrdine: ' . $datepreorder . '';
+ }
}
$str .= '
';
}
@@ -1033,6 +1050,7 @@ function getRigaArticoloByArt($article, $ind, $sep)
return $str;
}
+
function showCartolibri()
{
$articles = getArticoliCartolibro();