2024-05-19 13:06:17 +02:00
< ? php
2024-12-18 08:56:53 +01:00
use App\ArticoliFatturati ;
2025-01-15 20:50:45 +01:00
use App\Http\Controllers\Controller ;
2024-06-15 17:05:38 +02:00
use Carbon\Carbon ;
use Codexshaper\WooCommerce\Facades\Product ;
use Illuminate\Console\Command ;
use App\Setting ;
use App\Article ;
2024-07-11 14:40:33 +02:00
use App\Clientegm ;
2024-06-15 17:05:38 +02:00
use App\Mylog ;
use Codexshaper\WooCommerce\Models\Product as ModelsProduct ;
use Codexshaper\WooCommerce\Facades\Variation ;
use Codexshaper\WooCommerce\Facades\Category ;
2024-08-14 16:31:58 +02:00
use Codexshaper\WooCommerce\Facades\WooCommerce ;
2024-06-15 17:05:38 +02:00
use Illuminate\Support\Collection ;
use Illuminate\Support\Facades\Log ;
use Illuminate\Support\Facades\Mail ;
use Illuminate\Support\Facades\DB ;
2024-06-15 17:05:04 +02:00
2025-01-15 20:50:45 +01:00
2024-06-13 09:04:07 +02:00
use App\Orderdetail ;
2024-06-17 14:41:58 +02:00
use App\Services\ProductLogger ;
2024-07-18 15:35:08 +02:00
use App\Order as AppOrder ;
2024-07-22 11:37:56 +02:00
use App\OrderdetailWeb ;
2024-07-22 11:35:49 +02:00
use App\OrderWeb as AppOrderWeb ;
2024-06-13 09:13:17 +02:00
use Illuminate\Support\Facades\Schema ;
2024-05-20 01:23:47 +02:00
2024-07-16 11:00:18 +02:00
use Illuminate\Support\Facades\Request ;
2025-01-15 20:50:45 +01:00
use App\Helpers\MyConfig ;
2024-12-20 17:25:19 +01:00
2025-01-16 08:48:38 +01:00
MyConfig :: init ();
2024-06-18 10:03:19 +02:00
setlocale ( LC_TIME , 'it_IT.UTF-8' );
2024-05-19 13:06:17 +02:00
function showarray ( $array )
{
echo '<pre>' . json_encode ( $array , JSON_PRETTY_PRINT ) . '</pre>' ;
2024-12-18 08:56:53 +01:00
}
;
2024-05-19 13:06:17 +02:00
2024-05-21 01:18:26 +02:00
function getarraystr ( $array )
{
return '<pre>' . json_encode ( $array , JSON_PRETTY_PRINT ) . '</pre>' ;
2024-12-18 08:56:53 +01:00
}
;
2024-05-21 01:18:26 +02:00
2024-05-19 13:06:17 +02:00
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
2024-05-20 01:23:47 +02:00
function updateValueByKey ( & $array , $key , $newValue )
{
2024-05-19 13:11:57 +02:00
foreach ( $array as & $item ) {
2024-05-19 16:31:05 +02:00
if ( is_object ( $item ) && property_exists ( $item , 'key' ) && $item -> key === $key ) {
2024-05-19 13:11:57 +02:00
$item -> value = $newValue ;
2024-05-19 16:31:05 +02:00
return ; // Se trova il key, termina il loop
2024-05-19 13:11:57 +02:00
}
}
2024-05-19 16:27:15 +02:00
2024-05-19 16:31:05 +02:00
// Se il key non esiste nell'array, aggiungi il nuovo key-value pair
$newItem = new stdClass ();
$newItem -> key = $key ;
$newItem -> value = $newValue ;
$array [] = $newItem ; // Aggiungi il nuovo elemento all'array
2024-05-19 13:11:57 +02:00
}
2024-05-20 01:23:47 +02:00
function updateValueByKeyArr ( & $array , $key , $newValue )
{
2024-05-19 13:06:17 +02:00
foreach ( $array as & $item ) {
if ( $item [ 'key' ] === $key ) {
$item [ 'value' ] = $newValue ;
break ; // Se trova il key, termina il loop
}
}
2024-05-19 16:27:15 +02:00
$array [ $key ] = $newValue ;
2024-05-19 13:06:17 +02:00
}
2024-05-20 01:23:47 +02:00
2024-06-19 18:19:17 +02:00
function formatDateToItalian ( $date_string , $input_format = 'Y-m-d H:i:s.u' )
{
2024-06-18 10:03:19 +02:00
// Crea un oggetto DateTime dal formato della stringa di input
$date = DateTime :: createFromFormat ( $input_format , $date_string );
// Verifica se la creazione dell'oggetto DateTime è riuscita
if ( $date ) {
// Crea l'oggetto IntlDateFormatter per formattare la data in italiano
$formatter = new IntlDateFormatter (
'it_IT' , // Imposta la localizzazione in italiano
IntlDateFormatter :: FULL ,
IntlDateFormatter :: NONE ,
'Europe/Rome' , // Imposta il fuso orario (opzionale)
IntlDateFormatter :: GREGORIAN ,
'd MMMM yyyy' // Specifica il formato desiderato
);
// Formatta la data
return ucfirst ( $formatter -> format ( $date ));
} else {
return false ; // Ritorna false se la data non è valida o il formato non è corretto
}
}
2024-07-16 10:48:28 +02:00
2024-05-20 01:23:47 +02:00
function setPreOrder ( $sku , $aggiornapreordine , $debug )
{
try {
// Aggiorna Preorder
$product = Product :: where ( 'sku' , $sku ) -> first ();
2024-05-20 08:38:48 +02:00
if ( $debug ) {
echo " Product: " . $sku ;
2024-05-20 01:23:47 +02:00
showarray ( $product );
2024-05-20 08:38:48 +02:00
}
2024-05-20 22:57:08 +02:00
2024-12-20 12:47:48 +01:00
//$campoPreOrder = '_wpro_variable_is_preorder';
2025-01-15 20:50:45 +01:00
$campoPreOrder = MyConfig :: $campoPreordine ;
2024-05-20 01:23:47 +02:00
2025-01-15 21:01:32 +01:00
echo " Campo preorder " . $campoPreOrder ;
2024-05-20 01:23:47 +02:00
if ( $product ) {
$titolo = $product [ 'name' ];
if ( $debug )
2024-05-21 01:24:02 +02:00
echo " Prodotto trovato: " . $titolo . " StockQty = " . $product [ 'stock_quantity' ] . " <br> " ;
2024-05-20 01:23:47 +02:00
$preorder = false ;
if ( isKeyPresent ( $product [ 'meta_data' ], $campoPreOrder )) {
$preorder = getValueByKey ( $product [ 'meta_data' ], $campoPreOrder );
}
if ( $debug ) {
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> " ;
}
2024-06-18 09:13:43 +02:00
$idprodotto = $product [ 'parent_id' ];
2024-06-18 09:27:55 +02:00
2024-05-20 01:23:47 +02:00
if ( $aggiornapreordine === '1' ) {
$data = [];
2024-06-18 09:46:45 +02:00
$article = getArticoloById ( $sku );
2024-06-19 18:19:17 +02:00
echo $article -> titolo . " DataPubblicazione: " . $article -> DataPubblicazione . " <br> " ;
2024-06-18 09:58:01 +02:00
2024-06-19 18:19:17 +02:00
$datepubblstr = " " ;
$datepubbllabel = " " ;
$label_prenotalo_con_data = " " ;
2024-06-18 09:33:44 +02:00
2024-06-19 18:19:17 +02:00
if ( $article -> DataPubblicazione ) {
$datepubbl = DateTime :: createFromFormat ( 'Y-m-d H:i:s.u' , $article -> DataPubblicazione );
2024-06-18 09:49:25 +02:00
2024-06-19 18:19:17 +02:00
if ( $datepubbl !== false ) {
$datepubblstr = $datepubbl -> format ( 'Y-m-d' );
$datepubbllabel = formatDateToItalian ( $article -> DataPubblicazione );
$label_prenotalo_con_data = 'Prenotalo per riceverlo entro il ' . $datepubbllabel ;
} else {
// Gestire il caso in cui la data di pubblicazione non è valida
echo " Errore: La data di pubblicazione non è valida.<br> " ;
}
2024-06-19 18:08:01 +02:00
}
2024-05-20 01:23:47 +02:00
if ( $idprodotto > 0 ) {
2024-06-18 09:49:25 +02:00
if ( $debug ) {
2024-05-20 01:23:47 +02:00
echo " Variazioni: " . $product [ 'parent_id' ] . " <br> " ;
2024-06-18 09:49:25 +02:00
echo " Data Pubblicazione: " . $datepubblstr . " <br> " ;
}
2024-05-20 01:23:47 +02:00
$variations = Variation :: all ( $product [ 'parent_id' ]);
if ( $debug )
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 ;
}
}
2025-01-15 20:50:45 +01:00
$data [ 'stock_quantity' ] = MyConfig :: $qtaInPrevendita ;
2024-05-20 01:23:47 +02:00
if ( $debug ) {
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' );
2024-06-18 09:49:25 +02:00
updateValueByKey ( $data [ 'meta_data' ], '_pre_order_date' , $datepubblstr );
2024-12-20 12:47:48 +01:00
updateValueByKey ( $data [ 'meta_data' ], '_ywpo_for_sale_date' , $datepubblstr );
2024-06-18 09:34:51 +02:00
updateValueByKey ( $data [ 'meta_data' ], '_wpro_date_label_variable' , $label_prenotalo_con_data );
2024-05-20 01:23:47 +02:00
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' );
2024-06-18 09:49:25 +02:00
updateValueByKey ( $data [ 'meta_data' ], '_wpro_date_variable' , $datepubblstr );
2024-05-20 01:23:47 +02:00
updateValueByKey ( $data [ 'meta_data' ], '_wpro_time_variable' , '' );
updateValueByKey ( $data [ 'meta_data' ], '_rank_math_gtin_code' , '' );
}
if ( $debug ) {
echo " <br>Dati da Salvare: " ;
showarray ( $data );
}
$variation = Variation :: update ( $idprodotto , $product [ 'id' ], $data );
2024-05-20 22:57:08 +02:00
2024-05-20 01:23:47 +02:00
if ( $variation ) {
if ( $debug )
echo " Aggiornato Preorder: [ParentId= " . $idprodotto . '] ProdId= ' . $product [ 'id' ] . ' ' . $variation [ 'name' ] . " <br> " ;
}
}
2024-06-18 09:16:53 +02:00
} else if ( $aggiornapreordine === '-1' ) {
2024-06-18 09:13:43 +02:00
if ( $idprodotto > 0 ) {
$variations = Variation :: all ( $product [ 'parent_id' ]);
if ( $debug )
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' ] = 0 ;
if ( $debug ) {
echo " Data: " ;
showarray ( $data );
}
$agg = true ;
$data [ 'meta_data' ] = $product [ 'meta_data' ];
if ( $agg ) {
updateValueByKey ( $data [ 'meta_data' ], $campoPreOrder , 'no' );
updateValueByKey ( $data [ 'meta_data' ], '_is_pre_order' , 'no' );
}
if ( $debug ) {
echo " <br>Dati da Salvare: " ;
showarray ( $data );
}
$variation = Variation :: update ( $idprodotto , $product [ 'id' ], $data );
if ( $variation ) {
if ( $debug )
echo " Aggiornato come Non Disponibile : [ParentId= " . $idprodotto . '] ProdId= ' . $product [ 'id' ] . ' ' . $variation [ 'name' ] . " <br> " ;
}
}
2024-07-08 12:12:24 +02:00
} else if ( $aggiornapreordine === '0' ) {
if ( $idprodotto > 0 ) {
$variations = Variation :: all ( $product [ 'parent_id' ]);
if ( $debug )
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 ;
}
}
$agg = true ;
$data [ 'meta_data' ] = $product [ 'meta_data' ];
if ( $agg ) {
updateValueByKey ( $data [ 'meta_data' ], $campoPreOrder , 'no' );
updateValueByKey ( $data [ 'meta_data' ], '_is_pre_order' , 'no' );
}
if ( $debug ) {
echo " <br>Dati da Salvare: " ;
showarray ( $data );
}
$variation = Variation :: update ( $idprodotto , $product [ 'id' ], $data );
if ( $variation ) {
if ( $debug )
echo " Aggiornato come in Vendita : [ParentId= " . $idprodotto . '] ProdId= ' . $product [ 'id' ] . ' ' . $variation [ 'name' ] . " <br> " ;
}
}
2024-05-20 01:23:47 +02:00
}
} else {
if ( $debug )
echo " Il prodotto non esiste " ;
}
} catch ( Exception $e ) {
echo " Errore: " . $e -> getMessage ();
}
}
2024-06-21 13:19:35 +02:00
function setDataPubblicazione ( $sku , $debug )
{
try {
// Aggiorna Preorder
$product = Product :: where ( 'sku' , $sku ) -> first ();
if ( $debug ) {
echo " Product: " . $sku ;
showarray ( $product );
}
if ( $product ) {
$titolo = $product [ 'name' ];
if ( $debug )
echo " Prodotto trovato: " . $titolo . " StockQty = " . $product [ 'stock_quantity' ] . " <br> " ;
$idprodotto = $product [ 'parent_id' ];
if ( true ) {
$data = [];
$article = getArticoloById ( $sku );
echo $article -> titolo . " DataPubblicazione: " . $article -> DataPubblicazione . " <br> " ;
$datepubblstr = " " ;
$datepubbl_ts = 0 ;
if ( $article -> DataPubblicazione ) {
$datepubbl = DateTime :: createFromFormat ( 'Y-m-d H:i:s.u' , $article -> DataPubblicazione );
if ( $datepubbl !== false ) {
$datepubbl_ts = $datepubbl -> getTimestamp ();
$datepubblstr = $datepubbl -> format ( 'd/m/Y' );
}
}
if ( $idprodotto > 0 ) {
if ( $debug ) {
echo " Variazioni: " . $product [ 'parent_id' ] . " <br> " ;
echo " Data Pubblicazione: " . $datepubblstr . " <br> " ;
}
$variations = Variation :: all ( $product [ 'parent_id' ]);
if ( $debug )
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 ;
}
}
$agg = true ;
// $data['meta_data'] = $product['meta_data'];
if ( $data ) {
$dataPubbSaved = getValueByKey ( $product [ 'meta_data' ], 'DataPubblicazione' );
if ( $dataPubbSaved != $datepubbl_ts ) {
updateValueByKey ( $data [ 'meta_data' ], 'DataPubblicazione' , $datepubbl_ts );
updateValueByKey ( $data [ 'meta_data' ], 'DataPubbStr' , $datepubblstr );
if ( $debug ) {
echo " <br>Dati da Salvare: " ;
showarray ( $data );
}
$variation = Variation :: update ( $idprodotto , $product [ 'id' ], $data );
if ( $variation ) {
if ( $debug )
echo " Aggiornato: [ParentId= " . $idprodotto . '] ProdId= ' . $product [ 'id' ] . ' ' . $variation [ 'name' ] . " <br> " ;
}
return true ;
}
}
}
}
} else {
if ( $debug )
echo " Il prodotto non esiste " ;
}
return false ;
} catch ( Exception $e ) {
echo " Errore: " . $e -> getMessage ();
}
}
2024-06-15 21:29:12 +02:00
function isArticleInPrevendita ( $id , $checkqtanegativa )
2024-05-20 22:57:08 +02:00
{
2024-05-21 00:33:50 +02:00
return loadArticleByIdArticle ( $id , true );
2024-05-20 22:57:08 +02:00
}
2024-05-20 23:46:21 +02:00
2024-06-15 21:29:12 +02:00
function loadArticleByIdArticle ( $id , $checkprevendita = false , $checkqtanegativa = false )
2024-05-20 23:46:21 +02:00
{
try {
2024-05-21 00:23:34 +02:00
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
2024-05-20 23:46:21 +02:00
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
2024-05-21 00:23:34 +02:00
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
2024-05-20 23:46:21 +02:00
})
2024-05-21 00:23:34 +02:00
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
2024-05-20 23:46:21 +02:00
})
2024-05-21 00:33:50 +02:00
-> leftJoin ( DB :: raw ( '(SELECT o.Codice, o.QtaDisponibile FROM T_WEB_Disponibile o JOIN (SELECT Codice, MAX(DataOra) as data1 from T_WEB_Disponibile GROUP BY Codice) p ON o.Codice = p.Codice AND o.DataOra = p.data1 ) q' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'q.Codice' );
2024-05-21 00:23:34 +02:00
})
2024-05-21 00:33:50 +02:00
-> where ( 'T_WEB_Articoli.IdArticolo' , $id )
-> get ();
2024-05-21 00:44:43 +02:00
if ( $checkprevendita ) {
foreach ( $articles as $article ) {
$qtaneg = $article -> QtaDisponibile < 0 ;
$inprevendita = false ;
if ( $article ) {
2024-06-15 21:29:12 +02:00
$inprevendita = ( $article -> DescrizioneStatoProdotto === 'In prevendita' );
if ( $checkqtanegativa ) {
$inprevendita = $inprevendita && $qtaneg ;
}
2024-05-21 00:44:43 +02:00
}
if ( $inprevendita ) {
return true ;
2024-05-21 00:33:50 +02:00
}
}
2024-05-21 00:44:43 +02:00
return false ;
}
2024-05-20 23:46:21 +02:00
2024-06-15 15:53:38 +02:00
$ris = 'Articles di ' . $id . ' :' . PHP_EOL ;
2024-06-15 15:49:57 +02:00
$ris .= getarraystr ( $articles ); // Converte solo i dati specificati in JSON
2024-06-13 08:57:58 +02:00
2024-06-15 15:53:38 +02:00
try {
2024-06-15 18:29:22 +02:00
$product = Product :: where ( 'sku' , $id ) -> first ();
2024-06-13 08:57:58 +02:00
2024-06-15 15:53:38 +02:00
$ris .= 'Product:' . PHP_EOL ;
2024-06-15 18:29:22 +02:00
$ris .= getarraystr ( $product );
2024-06-15 15:53:38 +02:00
} catch ( \Exception $e ) {
$ris .= " !!! Errore loadArticleByIdArticle Product: " . $e -> getMessage ();
}
2024-05-21 01:11:16 +02:00
2024-06-13 08:57:58 +02:00
return $ris ;
2024-05-20 23:51:58 +02:00
} catch ( \Exception $e ) {
2024-06-15 15:49:11 +02:00
return " Errore loadArticleByIdArticle: " . $e -> getMessage ();
2024-05-20 23:46:21 +02:00
}
}
2024-05-21 00:44:43 +02:00
2024-09-03 12:04:36 +02:00
function loadArticleByISBN ( $isbn , $checkprevendita = false , $checkqtanegativa = false )
{
try {
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
})
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
})
-> leftJoin ( DB :: raw ( '(SELECT o.Codice, o.QtaDisponibile FROM T_WEB_Disponibile o JOIN (SELECT Codice, MAX(DataOra) as data1 from T_WEB_Disponibile GROUP BY Codice) p ON o.Codice = p.Codice AND o.DataOra = p.data1 ) q' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'q.Codice' );
})
-> where ( 'T_WEB_Articoli.Ean13' , $isbn )
-> get ();
if ( $checkprevendita ) {
foreach ( $articles as $article ) {
$qtaneg = $article -> QtaDisponibile < 0 ;
$inprevendita = false ;
if ( $article ) {
$inprevendita = ( $article -> DescrizioneStatoProdotto === 'In prevendita' );
if ( $checkqtanegativa ) {
$inprevendita = $inprevendita && $qtaneg ;
}
}
if ( $inprevendita ) {
return true ;
}
}
return false ;
}
$ris = 'Articles ISBN ' . $isbn . ' :' . PHP_EOL ;
$ris .= getarraystr ( $articles ); // Converte solo i dati specificati in JSON
try {
$product = Product :: where ( 'sku' , $isbn ) -> first ();
$ris .= 'Product:' . PHP_EOL ;
$ris .= getarraystr ( $product );
} catch ( \Exception $e ) {
$ris .= " !!! Errore loadArticleByISBN Product: " . $e -> getMessage ();
}
return $ris ;
} catch ( \Exception $e ) {
return " Errore loadArticleByISBN: " . $e -> getMessage ();
}
}
2024-08-15 13:07:52 +02:00
2024-08-14 15:30:25 +02:00
function showTest ()
{
2024-08-15 13:07:52 +02:00
$sku = " 16670 " ;
2024-08-14 15:30:25 +02:00
2024-08-15 13:07:52 +02:00
$mystr = '*** TEST: codarticolo: ' . $sku . '<br>' ;
if ( $sku ) {
2024-08-14 15:30:25 +02:00
try {
2024-08-23 14:47:40 +02:00
// $products = WooCommerce::get('products', ['sku' => $sku]);
$product = Product :: where ( 'sku' , $sku ) -> first ();
2024-09-03 12:04:36 +02:00
2024-08-15 13:07:52 +02:00
// Verifica se ci sono prodotti trovati
2024-08-23 14:47:40 +02:00
$mystr .= response () -> json ( $product ); // Restituisce il primo prodotto
2024-08-14 16:58:04 +02:00
// print_r($product);
2024-08-14 16:57:28 +02:00
// $product = Product::all();
2024-08-14 15:30:25 +02:00
} catch ( \Exception $e ) {
2024-08-14 16:31:58 +02:00
$mystr .= " Errore: " . $e -> getMessage () . '<br>' ;
2024-08-14 15:30:25 +02:00
}
2024-08-14 16:31:58 +02:00
if ( isset ( $product ))
$mystr .= response () -> json ( $product );
2024-08-14 15:30:25 +02:00
}
2024-09-03 12:04:36 +02:00
return $mystr ;
2024-08-14 15:30:25 +02:00
}
2024-05-22 14:29:58 +02:00
function showOrdini ()
{
2024-07-16 19:31:05 +02:00
$str = " " ;
2024-06-13 09:04:07 +02:00
try {
2024-07-16 19:31:05 +02:00
// $str = Schema::getColumnListing('Orderdetails');
$orders = Orderdetail :: orderBy ( 'DataOra' , 'desc' )
2024-07-16 10:57:31 +02:00
-> take ( 5 )
2024-06-13 09:08:18 +02:00
-> get ();
2024-07-16 19:31:05 +02:00
$sep = " " ;
2024-08-13 09:27:46 +02:00
// dd($orders);
2024-08-13 09:26:19 +02:00
2024-07-16 19:31:05 +02:00
$baseUrl = Request :: root (); // URL di base (dominio)
// Show the fields of the orders
foreach ( $orders as $order ) {
2024-08-13 09:31:34 +02:00
$product = Product :: where ( 'sku' , $order -> CodArticoloGM ) -> first ();
2024-07-22 11:37:56 +02:00
2024-08-22 22:16:07 +02:00
// dd($product);
2024-08-13 09:31:34 +02:00
// $product = null;
2024-08-13 09:27:46 +02:00
2024-07-22 11:37:56 +02:00
if ( $product )
$titolo = " <a href=' " . $product [ 'permalink' ] . " ' target='_blank'><span style='font-weigth: bold;'> " . $product [ 'name' ] . " </span></a> " ;
else
$titolo = " " ;
$str .= getvalstr ( " " , $order -> Codice ) . " " ;
$str .= getvalstr ( " " , $order -> DataOra );
$str .= getvalstr ( " " , $titolo );
$str .= getvalstr ( " Ordine " , $order -> IdInternet , true ) . " " ;
2024-07-26 18:09:39 +02:00
$str .= getvalstr ( " Cod Cliente " , $order -> CodClienteInternet , true );
2024-07-22 11:37:56 +02:00
$str .= getvalstr ( " Articolo " , $order -> CodArticoloGM , true );
2024-07-22 12:25:09 +02:00
$str .= getvalstr ( " IdSito " , $order -> IdSito , true );
2024-07-22 11:37:56 +02:00
$str .= getvalstr ( " Prezzo " , $order -> PrezzoLordo );
$str .= getvalstr ( " Quantità " , $order -> Qta );
if ( $order -> PercSconto )
$str .= getvalstr ( " Sconto " , $order -> PercSconto );
if ( $order -> Descrizione )
$str .= getvalstr ( " Descr " , $order -> Descrizione );
2024-08-12 10:44:54 +02:00
$str .= ' <a href="' . $baseUrl . '/setordine/' . $order -> IdInternet . '/idsito/" target="_blank">[IMPOSTA IDSITO FDV]</a> ' . $sep ;
$str .= ' <a href="' . $baseUrl . '/setordine/' . $order -> IdInternet . '/del/" target="_blank">ELIMINA!</a> ' . $sep ;
2024-07-22 11:37:56 +02:00
// $str .= getarraystr($product) . "<br>";
// $str .= $product;
$str .= '<br>' ;
}
} catch ( \Exception $e ) {
return " Errore: " . $e -> getMessage ();
}
return $str ;
}
function showOrdiniWeb ()
{
$str = " " ;
try {
$orders = OrderdetailWeb :: orderBy ( 'DataOra' , 'desc' )
-> take ( 5 )
-> get ();
$sep = " " ;
$baseUrl = Request :: root (); // URL di base (dominio)
// Show the fields of the orders
foreach ( $orders as $order ) {
2024-07-16 19:31:05 +02:00
$product = Product :: where ( 'sku' , $order -> CodArticoloGM ) -> first ();
2024-11-27 12:38:26 +01:00
if ( isset ( $product [ 'permalink' ])) {
2024-11-27 12:39:34 +01:00
$mylink = " <a href=' " . $product [ 'permalink' ] . " ' target='_blank'> " ;
2024-11-27 12:38:26 +01:00
$finelink = " </a> " ;
} else {
$mylink = " " ;
$finelink = " " ;
2024-12-18 08:56:53 +01:00
}
2024-11-27 12:38:26 +01:00
2024-11-27 12:40:48 +01:00
if ( $product && isset ( $product [ 'name' ]))
2024-11-27 12:38:26 +01:00
$titolo = $mylink . " <span style='font-weigth: bold;'> " . $product [ 'name' ] . " </span> " . $finelink ;
2024-07-16 19:31:05 +02:00
else
$titolo = " " ;
$str .= getvalstr ( " " , $order -> Codice ) . " " ;
$str .= getvalstr ( " " , $order -> DataOra );
$str .= getvalstr ( " " , $titolo );
$str .= getvalstr ( " Ordine " , $order -> IdInternet , true ) . " " ;
2024-07-26 18:08:50 +02:00
$str .= getvalstr ( " Cod Cliente " , $order -> CodClienteInternet , true );
2024-07-16 19:31:05 +02:00
$str .= getvalstr ( " Articolo " , $order -> CodArticoloGM , true );
$str .= getvalstr ( " Prezzo " , $order -> PrezzoLordo );
2024-07-22 12:25:09 +02:00
$str .= getvalstr ( " IdSito " , $order -> IdSito , true );
2024-07-16 19:31:05 +02:00
$str .= getvalstr ( " Quantità " , $order -> Qta );
if ( $order -> PercSconto )
$str .= getvalstr ( " Sconto " , $order -> PercSconto );
if ( $order -> Descrizione )
$str .= getvalstr ( " Descr " , $order -> Descrizione );
2024-07-22 11:55:22 +02:00
// $str .= ' <a href="' . $baseUrl . '/setordine/' . $order->IdInternet . '/del/" target="_blank">ELIMINA!</a>' . $sep;
2024-07-26 15:55:19 +02:00
$str .= ' <a href="' . $baseUrl . '/setordine/' . $order -> IdInternet . '/idsito/" target="_blank">IMPOSTA IDSITO FDV</a>' . $sep ;
2024-07-16 19:31:05 +02:00
// $str .= getarraystr($product) . "<br>";
// $str .= $product;
$str .= '<br>' ;
}
2024-06-13 09:04:07 +02:00
} catch ( \Exception $e ) {
return " Errore: " . $e -> getMessage ();
}
2024-07-16 19:31:05 +02:00
return $str ;
2024-06-13 09:04:07 +02:00
}
2024-07-16 19:31:05 +02:00
2024-12-18 08:20:00 +01:00
function showArticoliFatturatiWeb ()
{
$str = " " ;
try {
$orders = ArticoliFatturati :: orderBy ( 'DataOra' , 'desc' )
2024-12-18 08:58:11 +01:00
-> take ( 20 )
2024-12-18 08:20:00 +01:00
-> get ();
$sep = " " ;
$baseUrl = Request :: root (); // URL di base (dominio)
// Show the fields of the orders
foreach ( $orders as $order ) {
2024-12-18 08:56:53 +01:00
$usaprod = true ;
2024-12-18 08:20:00 +01:00
2024-12-18 08:56:53 +01:00
if ( $usaprod ) {
$product = Product :: where ( 'sku' , $order -> CodArticolo ) -> first ();
if ( isset ( $product [ 'permalink' ])) {
$mylink = " <a href=' " . $product [ 'permalink' ] . " ' target='_blank'> " ;
$finelink = " </a> " ;
} else {
$mylink = " " ;
$finelink = " " ;
}
if ( $product && isset ( $product [ 'name' ]))
$titolo = $mylink . " <span style='font-weigth: bold;'> " . $product [ 'name' ] . " </span> " . $finelink ;
else
$titolo = " " ;
2024-12-18 08:20:00 +01:00
} else {
$titolo = " " ;
2024-12-18 08:56:53 +01:00
}
2024-12-18 08:20:00 +01:00
$str .= getvalstr ( " " , $order -> Codice ) . " " ;
$str .= getvalstr ( " " , $order -> AnnoDoc ) . " " ;
$str .= getvalstr ( " " , $order -> NumeroDoc ) . " " ;
$str .= getvalstr ( " " , $order -> TipoDoc ) . " " ;
$str .= getvalstr ( " Articolo " , $order -> CodArticolo , true );
$str .= getvalstr ( " Quantità " , $order -> Qta );
$str .= getvalstr ( " " , $order -> DataOra );
$str .= getvalstr ( " " , $order -> Stato );
$str .= getvalstr ( " " , $order -> Note );
2024-12-18 08:58:11 +01:00
$str .= getvalstr ( " " , $titolo );
2024-12-18 08:20:00 +01:00
$str .= getvalstr ( " Ordine " , $order -> IdInternet , true ) . " " ;
if ( $order -> PercSconto )
$str .= getvalstr ( " Sconto " , $order -> PercSconto );
if ( $order -> Descrizione )
$str .= getvalstr ( " Descr " , $order -> Descrizione );
// $str .= ' <a href="' . $baseUrl . '/setordine/' . $order->IdInternet . '/idsito/" target="_blank">IMPOSTA IDSITO FDV</a>' . $sep;
$str .= '<br>' ;
}
} catch ( \Exception $e ) {
return " Errore: " . $e -> getMessage ();
}
return $str ;
}
2024-07-18 15:50:30 +02:00
function getStructTable ( $tableName )
{
2024-07-18 15:40:02 +02:00
$str = '' ;
2024-07-18 15:41:39 +02:00
$columns = Schema :: getColumnListing ( $tableName );
2024-07-18 15:40:02 +02:00
2024-07-18 15:56:04 +02:00
$str .= '<br><span style="font-weight: bold;">Tabella: ' . $tableName . '</span><br>' ;
2024-07-18 15:40:02 +02:00
2024-07-18 15:50:30 +02:00
$str .= '<pre>' ;
2024-07-18 15:57:41 +02:00
// Recupera i tipi di dati e lunghezza per ogni colonna
$types = DB :: select ( " SELECT column_name, data_type, character_maximum_length
FROM information_schema . columns
WHERE table_name = '$tableName' " );
$columnInfo = [];
2024-07-18 15:56:04 +02:00
foreach ( $types as $type ) {
2024-07-18 15:57:41 +02:00
$columnInfo [ $type -> column_name ] = [
'data_type' => $type -> data_type ,
'length' => $type -> character_maximum_length
];
2024-07-18 15:56:04 +02:00
}
2024-07-18 15:57:41 +02:00
// Stampa la struttura della tabella con i tipi di dati e lunghezza dei campi
2024-07-18 15:40:02 +02:00
foreach ( $columns as $column ) {
2024-07-18 15:57:41 +02:00
$str .= ' ' . $column . " - " . $columnInfo [ $column ][ 'data_type' ] . " ( " . $columnInfo [ $column ][ 'length' ] . " ) " . " <br> " ;
2024-07-18 15:40:02 +02:00
}
2024-07-18 15:50:30 +02:00
$str .= '</pre>' ;
2024-07-18 15:40:02 +02:00
return $str ;
2024-07-18 15:50:30 +02:00
}
2024-07-18 15:40:02 +02:00
2024-07-18 15:50:30 +02:00
function getAllTables ()
{
2024-07-18 15:51:45 +02:00
$tables = DB :: select ( " SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' " );
2024-07-18 15:50:30 +02:00
$tableNames = array_map ( 'current' , $tables );
return $tableNames ;
}
function getAllTablesStr ()
{
// Utilizzo della funzione per ottenere la lista delle tabelle
$tables = getAllTables ();
$str = " TABELLE:<br> " ;
// Stampa la lista delle tabelle
foreach ( $tables as $table ) {
2024-07-18 15:53:13 +02:00
$str .= getStructTable ( $table ) . '<br>' ;
2024-07-18 15:50:30 +02:00
}
return $str ;
2024-07-18 15:40:02 +02:00
}
2024-07-16 10:48:28 +02:00
function setOrdine ( $idinternet , $mode )
{
2024-07-18 15:04:18 +02:00
try {
2024-07-18 15:40:02 +02:00
2024-12-18 08:56:53 +01:00
$str = " setOrdine: mode = " . $mode . ' idinternet=' . $idinternet ;
2024-07-18 15:40:02 +02:00
2024-07-18 17:10:55 +02:00
// $str .= getAllTablesStr();
2024-07-18 15:50:30 +02:00
2024-07-18 15:40:02 +02:00
$str .= getStructTable ( 'T_WOO_TestateOrdini' );
2024-07-18 15:43:50 +02:00
$ordine = Orderdetail :: where ( 'IdInternet' , $idinternet ) -> first ();
2024-07-18 15:04:18 +02:00
2024-07-18 15:44:40 +02:00
$ordergm = AppOrder :: where ( 'IdInternet' , $idinternet ) -> first ();
2024-07-18 15:18:03 +02:00
2024-07-18 15:45:18 +02:00
if ( $ordergm ) {
2024-07-18 15:44:40 +02:00
$str .= getarraystr ( $ordergm ) . " <br> " ;
2024-07-18 15:22:58 +02:00
// $ordergm = $ordergms[0];
// $str .= getarraystr($ordergm) . "<br>";
2024-07-18 15:18:03 +02:00
}
2024-07-18 15:44:40 +02:00
if ( $ordine ) {
2024-07-18 15:18:03 +02:00
2024-07-18 15:07:56 +02:00
if ( $ordine )
$str .= getarraystr ( $ordine ) . " <br> " ;
2024-07-16 10:48:28 +02:00
2024-07-18 15:07:56 +02:00
$prodotto = Product :: where ( 'sku' , $ordine [ " CodArticoloGM " ]) -> first ();
2024-07-16 10:48:28 +02:00
2024-07-18 15:07:56 +02:00
if ( $prodotto )
$str .= getarraystr ( $prodotto ) . " <br> " ;
2024-07-18 15:08:27 +02:00
if ( $mode === 'del' && $ordine ) {
2024-07-18 15:09:34 +02:00
$str .= " ... Cancellazione in CORSO ... " ;
2024-07-18 15:07:56 +02:00
// delete record $ordine
$deletedCount = Orderdetail :: where ( 'IdInternet' , $idinternet ) -> delete ();
$str .= " <br><span style='color: red;'>Numero di record eliminati: " . $deletedCount . " </span> " ;
}
2024-07-26 15:55:19 +02:00
if ( $mode === 'idsito' && $ordine ) {
$str .= " ... CAMBIA ID SITO ... " ;
// Update field IdSito to "7"
$updatedCount = Orderdetail :: where ( 'IdInternet' , $idinternet )
-> update ([
'IdSito' => " 7 "
]);
2024-08-12 10:44:54 +02:00
2024-07-26 15:55:19 +02:00
$str .= " <br><span style='color: red;'>record Aggiornati: " . $updatedCount . " </span> " ;
}
2024-07-18 15:04:18 +02:00
}
} catch ( \Exception $e ) {
$str .= " Errore: " . $e -> getMessage ();
2024-07-16 10:48:28 +02:00
}
return $str ;
}
2024-07-26 15:55:19 +02:00
function showRecordOrder ( $orders )
2024-06-13 09:04:07 +02:00
{
2024-06-13 08:57:58 +02:00
try {
2024-07-26 15:55:19 +02:00
$str = '' ;
2024-07-22 11:35:49 +02:00
// Show the fields of the orders
foreach ( $orders as $order ) {
$str .= getvalstr ( " IdInternet " , $order -> IdInternet , true ) . " " ;
2024-07-22 12:05:26 +02:00
$str .= getvalstr ( " CodCliente " , $order -> CodClienteInternet , true );
2024-07-22 11:55:22 +02:00
$str .= getvalstr ( " IdSito " , $order -> IdSito , true );
2024-07-22 12:05:26 +02:00
$str .= getvalstr ( " Note " , $order -> Note , true );
$str .= getvalstr ( " Totale " , $order -> Totale , true );
$str .= getvalstr ( " DataOra " , $order -> DataOra , true );
$str .= getvalstr ( " DataSpedizione " , $order -> DataSpedizione , true );
2024-07-22 11:35:49 +02:00
$str .= '<br>' ;
}
2024-07-26 15:55:19 +02:00
} catch ( \Exception $e ) {
return " Errore showDettOrdini: " . $e -> getMessage ();
}
return $str ;
}
function showDettOrdini ()
{
$str = " Ordini Woocommerce: " . PHP_EOL . '<br>' ;
try {
// sort DataOra desc
$orders = AppOrder :: all () -> sortByDesc ( 'DataOra' );
2024-07-22 11:35:49 +02:00
2024-07-26 15:55:19 +02:00
$str .= showRecordOrder ( $orders );
2024-07-22 11:55:22 +02:00
} catch ( \Exception $e ) {
return " Errore showDettOrdini: " . $e -> getMessage ();
}
return $str ;
}
2024-07-22 12:29:29 +02:00
function showDettSingleOrdine ( $idordine )
{
$str = " Ordini Woocommerce: " . PHP_EOL . '<br>' ;
try {
// sort DataOra desc
$orders = AppOrder :: where ( 'IdInternet' , $idordine ) -> get ();
2024-07-26 15:55:19 +02:00
$str .= showRecordOrder ( $orders );
2024-07-22 12:29:29 +02:00
} catch ( \Exception $e ) {
return " Errore showDettOrdini: " . $e -> getMessage ();
}
return $str ;
}
function showDettOrdiniWeb ()
{
try {
$str = " Ordini T_WEB_TestateOrdini: " . PHP_EOL . '<br>' ;
$orders = AppOrderWeb :: all () -> sortByDesc ( 'DataOra' );
2024-07-26 15:55:19 +02:00
$str .= showRecordOrder ( $orders );
2024-07-22 12:29:29 +02:00
} catch ( \Exception $e ) {
return " Errore showDettOrdini: " . $e -> getMessage ();
}
return $str ;
}
function showDettSingleOrdineWeb ( $idordine )
2024-07-22 11:55:22 +02:00
{
try {
2024-07-22 12:05:26 +02:00
2024-07-22 11:55:22 +02:00
$str = " Ordini T_WEB_TestateOrdini: " . PHP_EOL . '<br>' ;
2024-07-22 11:35:49 +02:00
2024-07-22 12:18:19 +02:00
$orders = AppOrderWeb :: where ( 'IdInternet' , $idordine ) -> get ();
2024-06-13 08:57:58 +02:00
2024-07-26 15:55:19 +02:00
$str .= showRecordOrder ( $orders );
2024-06-13 08:57:58 +02:00
} catch ( \Exception $e ) {
2024-06-15 17:17:46 +02:00
return " Errore showDettOrdini: " . $e -> getMessage ();
2024-05-22 14:29:58 +02:00
}
2024-06-13 09:00:40 +02:00
return $str ;
2024-05-22 14:29:58 +02:00
}
2024-06-18 09:13:43 +02:00
function showprice ( $prezzo )
{
2024-09-05 17:44:53 +02:00
try {
return ' € ' . number_format ( $prezzo , 2 );
} catch ( \Exception $e ) {
return $prezzo ;
}
2024-06-17 16:00:43 +02:00
}
2024-12-20 17:43:10 +01:00
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 ;
}
2024-12-20 17:52:30 +01:00
class ArticleFormatter
2024-09-05 17:16:56 +02:00
{
2025-01-15 20:50:45 +01:00
2024-12-20 17:52:30 +01:00
public static function getArticleRow ( $article , $index , $separator )
{
try {
$product = self :: getProduct ( $article -> IdArticolo );
$stockInfo = self :: getStockInfo ( $product );
$preorderInfo = self :: getPreorderInfo ( $product );
return self :: formatArticleRow (
$article ,
$index ,
$separator ,
$product ,
$stockInfo ,
$preorderInfo
);
} catch ( \Exception $e ) {
return " Errore getRigaArticoloByArt: " . $e -> getMessage ();
}
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
private static function getProduct ( $sku )
{
return Product :: where ( 'sku' , $sku ) -> first ();
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
private static function getStockInfo ( $product )
{
if ( ! $product ) {
return [
'quantity' => 0 ,
'price' => '' ,
'color' => 'black' ,
'permalink' => ''
];
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
$quantity = intval ( $product [ 'stock_quantity' ]);
$price = $product [ 'sale_price' ] ? : $product [ 'price' ];
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
return [
'quantity' => $quantity ,
'price' => $price ,
'color' => $quantity <= 0 ? 'red' : 'green' ,
'permalink' => $product [ 'permalink' ]
];
}
2024-09-05 17:43:21 +02:00
2024-12-20 17:52:30 +01:00
private static function getPreorderInfo ( $product )
{
if ( ! $product ) {
return [ 'active' => false , 'date' => null ];
}
2024-09-05 17:43:21 +02:00
2024-12-20 17:52:30 +01:00
return [
2025-01-15 20:50:45 +01:00
'active' => self :: findInsideProduct ( $product , MyConfig :: $campoPreordine ) === 'yes' ,
2024-12-20 17:52:30 +01:00
'date' => self :: findInsideProduct ( $product , '_ywpo_for_sale_date' )
];
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
private static function formatArticleRow ( $article , $index , $separator , $product , $stockInfo , $preorderInfo )
{
$elements = [
self :: formatIndexAndId ( $index , $article , $separator ),
self :: formatTitleLink ( $article , $stockInfo , $separator ),
self :: formatPublicationInfo ( $article , $separator ),
self :: formatStockInfo ( $article , $stockInfo , $separator ),
self :: formatPreorderActions ( $article , $preorderInfo , $stockInfo , $separator ),
self :: formatUpdateDateLink ( $article , $separator )
];
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
$output = implode ( '' , $elements );
if ( $product && $preorderInfo [ 'active' ]) {
$output .= self :: formatPreorderStatus ( $preorderInfo [ 'date' ]);
2024-09-05 17:40:41 +02:00
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
return $output . '<br>' ;
}
2024-12-20 17:43:52 +01:00
2024-12-20 17:52:30 +01:00
private static function formatIndexAndId ( $index , $article , $separator )
{
return sprintf (
'[%d]%s<a href="%s?id=%s" target="_blank">%s</a>%s' ,
$index ,
$separator ,
$article -> permalink ,
$article -> IdArticolo ,
$article -> IdArticolo ,
$separator
);
}
2024-12-20 17:43:10 +01:00
2024-12-20 17:52:30 +01:00
private static function formatTitleLink ( $article , $stockInfo , $separator )
{
return sprintf (
'<a href="%s" target="_blank"><span style="color:%s; font-weight: bold;"> %s</span></a>%s' ,
$stockInfo [ 'permalink' ],
$stockInfo [ 'color' ],
$article -> Titolo ,
$separator
);
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
private static function formatPublicationInfo ( $article , $separator )
{
return sprintf (
'Pubb:%s%s%s%s%s (%s)%s' ,
formatDateToItalian ( $article -> DataPubblicazione ),
$separator ,
$article -> DescrizioneCollana ,
$separator ,
$article -> DescrizioneStatoProdotto ,
$article -> DescrizioneFormato ,
$separator
);
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
private static function formatStockInfo ( $article , $stockInfo , $separator )
{
return sprintf (
'[Qta = <span>%s</span>]%s[%s]%s[In Stock = <span style="color:%s; font-weight: bold;">%s</span>]%s' ,
$article -> QtaDisponibile ,
$separator ,
showprice ( $stockInfo [ 'price' ]),
$separator ,
$stockInfo [ 'color' ],
$stockInfo [ 'quantity' ],
$separator
);
}
2024-09-05 17:16:56 +02:00
2024-12-20 17:52:30 +01:00
private static function formatPreorderActions ( $article , $preorderInfo , $stockInfo , $separator )
{
$baseUrl = $article -> permalink . '/apimacro/public/aggiornapreorder/' . $article -> IdArticolo ;
2024-12-20 17:43:10 +01:00
2025-01-15 20:50:45 +01:00
if ( ! $preorderInfo [ 'active' ] || $stockInfo [ 'quantity' ] < MyConfig :: $qtaMinima ) {
2024-12-20 17:52:30 +01:00
return sprintf (
'<a href="%s/1/" target="_blank">Imposta in PRE-ORDINE!</a>%s' ,
$baseUrl ,
$separator
);
2024-09-05 17:16:56 +02:00
}
2024-12-20 17:52:30 +01:00
return sprintf (
'<a href="%s/-1/" target="_blank">Impostalo Non Disponibile</a>%s' ,
$baseUrl ,
$separator
);
2024-09-05 17:16:56 +02:00
}
2024-12-20 17:52:30 +01:00
private static function formatUpdateDateLink ( $article , $separator )
{
return sprintf (
'<a href="%s/apimacro/public/aggiornadatapubblicazione/%s/" target="_blank">Aggiorna Data Pubb</a>%s' ,
$article -> permalink ,
$article -> IdArticolo ,
$separator
);
}
private static function formatPreorderStatus ( $preorderDate )
{
$status = ' <span style="color:green">PREORDINE ATTIVO!</span>' ;
if ( $preorderDate ) {
$status .= sprintf ( ' <span>Data PreOrdine: %s</span>' , $preorderDate );
}
return $status ;
}
private static function findInsideProduct ( $product , $field )
{
// Implementation needed - this was referenced but not shown in original code
return $product [ $field ] ? ? null ;
}
2024-09-05 17:16:56 +02:00
}
2025-01-15 20:50:45 +01:00
function getRigaArticoloByArt ( $article , $index , $separator )
{
2024-12-20 17:52:30 +01:00
return ArticleFormatter :: getArticleRow ( $article , $index , $separator );
}
2024-12-20 17:43:10 +01:00
2024-09-05 17:16:56 +02:00
function showCartolibri ()
{
$articles = getArticoliCartolibro ();
$sep = ' | ' ;
2024-09-05 17:21:07 +02:00
echo " PROVA: " ;
2024-09-05 17:20:32 +02:00
2024-09-05 17:16:56 +02:00
$ind = 1 ;
2024-09-05 17:21:07 +02:00
foreach ( $articles as $article ) {
2024-09-05 17:16:56 +02:00
2024-09-05 17:50:54 +02:00
if ( true ) {
2024-09-05 23:44:33 +02:00
// updateArticoloFromGM($article->IdArticolo);
2024-09-05 17:50:54 +02:00
}
2024-09-05 17:16:56 +02:00
$riga = getRigaArticoloByArt ( $article , $ind , $sep );
echo $riga ;
2024-09-05 17:50:54 +02:00
2024-09-05 17:16:56 +02:00
$ind ++ ;
}
}
2024-12-20 17:52:30 +01:00
2024-12-12 20:03:24 +01:00
function showRiviste ()
{
$articles = getArticoliRiviste ();
$sep = ' | ' ;
echo " PROVA: " ;
$ind = 1 ;
foreach ( $articles as $article ) {
if ( true ) {
// updateArticoloFromGM($article->IdArticolo);
}
$riga = getRigaArticoloByArt ( $article , $ind , $sep );
echo $riga ;
$ind ++ ;
}
}
2024-05-21 00:44:43 +02:00
function libriInPrevendita ()
{
2024-05-21 01:03:36 +02:00
try {
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
2024-05-21 00:44:43 +02:00
})
2024-05-21 01:03:36 +02:00
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
})
-> leftJoin ( DB :: raw ( '(SELECT g.IdTipologia, g.Descrizione as DescrizioneTipologia FROM T_WEB_Tipologie g JOIN (SELECT IdTipologia, MAX(DataOra) as data1 from T_WEB_Tipologie GROUP BY IdTipologia) h ON g.IdTipologia = h.IdTipologia AND g.DataOra = h.data1 ) i' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipologia' , '=' , 'i.IdTipologia' );
})
-> leftJoin ( DB :: raw ( '(SELECT l.IdTipoFormato, l.Descrizione as DescrizioneFormato FROM T_WEB_TipiFormato l JOIN (SELECT IdTipoFormato, MAX(DataOra) as data1 from T_WEB_TipiFormato GROUP BY IdTipoFormato) m ON l.IdTipoFormato = m.IdTipoFormato AND l.DataOra = m.data1 ) n' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipoFormato' , '=' , 'n.IdTipoFormato' );
})
-> leftJoin ( DB :: raw ( '(SELECT o.Codice, o.QtaDisponibile FROM T_WEB_Disponibile o JOIN (SELECT Codice, MAX(DataOra) as data1 from T_WEB_Disponibile GROUP BY Codice) p ON o.Codice = p.Codice AND o.DataOra = p.data1 ) q' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'q.Codice' );
})
2024-12-20 12:39:17 +01:00
-> leftJoin ( DB :: raw ( ' (
SELECT v . IdCollana , v . Descrizione as DescrizioneCollana
FROM T_WEB_Collane v
INNER JOIN (
SELECT IdCollana , MAX ( ID ) as MaxID
FROM T_WEB_Collane
GROUP BY IdCollana
) x ON v . IdCollana = x . IdCollana AND v . ID = x . MaxID
) y ' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdCollana' , '=' , 'y.IdCollana' );
2024-12-18 08:20:00 +01:00
})
2024-05-21 00:48:38 +02:00
2024-05-21 01:03:36 +02:00
-> where ( 'DescrizioneStatoProdotto' , 'In prevendita' )
-> where ( DB :: raw ( 'CONVERT(INT, QtaDisponibile)' ), '<' , 0 )
2024-06-13 13:42:59 +02:00
// ->where('DescrizioneFormato', 'brossura')
2024-06-13 13:30:51 +02:00
// ->where('DescrizioneTipologia', 'Libri')
2024-06-13 13:48:31 +02:00
-> where ( DB :: raw ( 'DATEDIFF(day, \'1970-01-01\', DataPubblicazione)' ), '>' , 1 )
2024-05-21 01:03:36 +02:00
-> orderBy ( 'DataPubblicazione' , 'desc' )
-> get ();
2024-09-05 17:16:56 +02:00
2024-05-21 01:03:36 +02:00
$sep = ' | ' ;
2024-05-21 00:44:43 +02:00
2024-05-21 01:03:36 +02:00
$ind = 1 ;
foreach ( $articles as $article ) {
// $titolo = rtrim(str_ireplace('USATO', '', $article->Titolo));
2024-05-21 00:44:43 +02:00
2024-09-05 17:16:56 +02:00
$riga = getRigaArticoloByArt ( $article , $ind , $sep );
echo $riga ;
2024-05-21 00:44:43 +02:00
2024-05-21 01:03:36 +02:00
$ind ++ ;
}
} catch ( Exception $e ) {
echo $e -> getMessage ();
2024-05-21 00:44:43 +02:00
}
2024-05-21 00:48:38 +02:00
return true ;
2024-05-21 00:44:43 +02:00
}
2024-06-17 14:41:58 +02:00
2024-06-17 15:30:06 +02:00
function setProductFromGM ( $article , $initlog , ProductLogger & $passproductLogger )
2024-06-17 14:41:58 +02:00
{
if ( $initlog ) {
2024-06-19 18:40:07 +02:00
$productLogger = new ProductLogger ( null , '' );
2024-06-17 14:41:58 +02:00
} else {
$productLogger = $passproductLogger ;
}
$preorder = true ;
2024-06-17 15:21:54 +02:00
try {
2024-06-17 14:41:58 +02:00
$productsku = Product :: where ( 'sku' , $article -> IdArticolo ) -> first ();
//if(Gm_product::where('id_gm',$article->IdArticolo)->doesntExist())
if ( $productsku -> count () == 0 ) {
$titolo = null ;
$formato = null ;
$prodotti = null ;
$prodotti = new ModelsProduct ();
2024-06-19 17:59:31 +02:00
$titolo = $article -> Titolo ;
echo $titolo . ' ' ;
2024-06-17 14:41:58 +02:00
switch ( $article -> DescrizioneTipologia ) {
case 'Libri' :
2024-09-03 12:20:48 +02:00
case 'Cartolibro' :
2024-12-12 20:03:24 +01:00
case 'Rivista' :
2024-06-17 14:41:58 +02:00
$prodotti = $prodotti -> where ( 'name' , $titolo ) -> get ();
$id = 0 ;
2024-12-19 15:15:06 +01:00
try {
if ( ! is_null ( $prodotti ) && $prodotti -> count () > 0 ) {
echo " ... cicla prodotti ... " ;
foreach ( $prodotti as $prodotto ) {
if ( strtolower ( $prodotto -> name ) === strtolower ( $titolo )) {
$found_key = array_search ( 'Autore libro' , array_column ( $prodotto -> attributes , 'name' ));
if ( array_diff ( $prodotto -> attributes [ $found_key ] -> options , $article -> authors ) === array_diff ( $article -> authors , $prodotto -> attributes [ $found_key ] -> options )) {
$id = $prodotto -> id ;
$variations = Variation :: all ( $prodotto -> id );
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 ;
}
2024-06-17 14:41:58 +02:00
}
}
}
}
}
2024-12-19 15:15:06 +01:00
} catch ( \Exception $e ) {
$productLogger -> addLog ( 'server_issues' , $article -> IdArticolo . ' - ' . $article -> Titolo . " \n " . $e -> getMessage () . " \n " );
echo " Errore: " . $e -> getMessage ();
2024-06-17 14:41:58 +02:00
}
2024-12-19 15:15:06 +01:00
2024-06-21 15:27:18 +02:00
$datepubbl = DateTime :: createFromFormat ( 'Y-m-d H:i:s.u' , $article -> DataPubblicazione );
2024-08-23 00:33:17 +02:00
$datepubbl_ts = " " ;
$datepubblstr = " " ;
2024-06-21 15:27:18 +02:00
if ( $datepubbl !== false ) {
$datepubbl_ts = $datepubbl -> getTimestamp ();
$datepubblstr = $datepubbl -> format ( 'd/m/Y' );
}
2024-06-17 14:41:58 +02:00
$data1 = [
'regular_price' => $article -> PrezzoIvato ,
'sku' => $article -> IdArticolo ,
'sale_price' => $article -> PrezzoIvatoScontatoCampagna ,
'date_on_sale_from' => $article -> DataInizioCampagna ,
'date_on_sale_to' => $article -> DataFineCampagna ,
'manage_stock' => true ,
'stock_quantity' => $article -> stock ,
'purchasable' => false ,
'attributes' => [
[
//'id' => 1,
'id' => 6 ,
'option' => 'Nuovo'
]
],
'meta_data' => [
2024-08-23 00:33:17 +02:00
$article -> Ean13 ? [
2024-06-17 14:41:58 +02:00
'key' => 'ISBN' ,
'value' => $article -> Ean13
2024-08-23 00:33:17 +02:00
] : [],
$article -> Misure ? [
2024-06-17 14:41:58 +02:00
'key' => 'misure' ,
'value' => $article -> Misure
2024-08-23 00:33:17 +02:00
] : [],
$article -> DescrizioneFormato ? [
2024-06-17 14:41:58 +02:00
'key' => 'formato' ,
'value' => $article -> DescrizioneFormato
2024-08-23 00:33:17 +02:00
] : [],
$article -> Pagine ? [
2024-06-17 14:41:58 +02:00
'key' => 'pagine' ,
'value' => $article -> Pagine
2024-08-23 00:33:17 +02:00
] : [],
$article -> Edizione ? [
2024-06-17 14:41:58 +02:00
'key' => 'edizione' ,
'value' => $article -> Edizione
2024-08-23 00:33:17 +02:00
] : [],
$article -> Ristampa ? [
2024-06-17 14:41:58 +02:00
'key' => 'ristampa' ,
2024-12-18 08:56:53 +01:00
'value' => $article -> Ristampa
2024-08-23 00:33:17 +02:00
] : [],
$datepubbl_ts ? [
2024-06-21 13:19:35 +02:00
'key' => 'DataPubblicazione' ,
2024-12-18 08:56:53 +01:00
'value' => $datepubbl_ts
2024-08-23 00:33:17 +02:00
] : [],
$datepubblstr ? [
2024-06-21 15:27:18 +02:00
'key' => 'DataPubbStr' ,
2024-12-18 08:56:53 +01:00
'value' => $datepubblstr
2024-08-23 00:33:17 +02:00
] : [],
2024-06-17 14:41:58 +02:00
]
];
2024-12-19 15:15:06 +01:00
echo " ... compila i campi... " ;
2024-06-17 14:41:58 +02:00
if ( $id == 0 ) {
$versione = 'Nuova versione' ;
$category = Category :: where ( 'name' , $article -> argomento );
if ( $category -> count () > 0 ) {
$categoria = $category -> first ();
$categoriaid = $categoria [ 'id' ];
} else {
$categoriaid = 0 ;
}
$data = [
'name' => $article -> Titolo ,
'type' => 'variable' ,
2024-12-18 08:56:53 +01:00
'short_description' => $article -> Sottotitolo ,
2024-06-17 14:41:58 +02:00
'categories' => [
[ 'id' => $categoriaid ]
],
'status' => 'draft' ,
//'description' => 'Simple product full description.',
//'short_description' => 'Simple product short description.',
'attributes' => [
[
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
],
[
//'id' => 5,
'id' => 7 ,
'visible' => true ,
'options' =>
2024-12-18 08:56:53 +01:00
$article -> authors
2024-06-17 14:41:58 +02:00
],
[
//'id' => 2,
'id' => 8 ,
'visible' => true ,
'options' => [
$article -> editore
]
],
[
//'id' => 7,
'id' => 9 ,
'visible' => true ,
'options' => [
$article -> DescrizioneTipologia
]
]
],
'default_attributes' => [
[
//'id' => 1,
'id' => 6 ,
'option' => 'Nuovo'
]
],
];
2024-12-19 15:15:06 +01:00
echo " ... crea prodotto... " . $data ;
2024-06-17 14:41:58 +02:00
$product = Product :: create ( $data );
$idprodotto = $product [ 'id' ];
2024-12-19 15:15:06 +01:00
echo " ... crea vaziazione " ;
2024-06-17 14:41:58 +02:00
$variation = Variation :: create ( $idprodotto , $data1 );
//dd($variation);
} else {
$versione = " Aggiunta versione " ;
$product = Product :: find ( $id );
$old_attributes = $product [ 'attributes' ];
$attributes = [];
foreach ( $old_attributes as $old_attribute ) {
if ( $old_attribute -> id <> 6 ) {
$attributes [] = [
'id' => $old_attribute -> id ,
'variation' => $old_attribute -> variation ,
'visible' => $old_attribute -> visible ,
'options' => $old_attribute -> options
];
}
}
2024-12-18 08:56:53 +01:00
$attributes [] = [
2024-06-17 14:41:58 +02:00
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
];
//dd($attributes);
$data = [
'attributes' => $attributes
];
Product :: update ( $id , $data );
$variation = Variation :: create ( $id , $data1 );
}
$productLogger -> addLog ( 'inserted' , $article -> Titolo . ' - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . ' - ' . $versione . ' - ' . $variation [ 'permalink' ] . " \n " );
$productLogger -> setAggiornato ( true );
break ;
case 'E-book' :
if ( $article -> DescrizioneFormato === 'Epub' ) {
$titolo = rtrim ( str_ireplace ( 'EPUB' , '' , $article -> Titolo ));
$formato = 'Epub' ;
} elseif ( $article -> DescrizioneFormato === 'Pdf' ) {
$titolo = rtrim ( str_ireplace ( 'PDF' , '' , $article -> Titolo ));
$formato = 'PDF' ;
} elseif ( $article -> DescrizioneFormato === 'Mobi' ) {
$titolo = rtrim ( str_ireplace ( 'MOBI' , '' , $article -> Titolo ));
$formato = 'Mobi' ;
} else {
$productLogger -> addLog ( 'not_inserted' , $article -> Titolo . ' - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . " \n " );
$productLogger -> setAggiornato ( true );
break ;
}
$titolo = rtrim ( $titolo );
$titolo = rtrim ( str_ireplace ( 'EBOOK' , '' , $titolo ));
$titolo = rtrim ( $titolo );
$titolo = rtrim ( str_ireplace ( '_' , '' , $titolo ));
$titolo = rtrim ( $titolo );
$titolo = rtrim ( $titolo , '-' );
$titolo = rtrim ( $titolo );
$titolo = rtrim ( $titolo , '_' );
$titolo = rtrim ( $titolo );
$prodotti = $prodotti -> where ( 'name' , $titolo ) -> get ();
$id = 0 ;
if ( ! is_null ( $prodotti ) && $prodotti -> count () > 0 ) {
foreach ( $prodotti as $prodotto ) {
if ( strtolower ( $prodotto -> name ) === strtolower ( $titolo )) {
$found_key = array_search ( 'Autore libro' , array_column ( $prodotto -> attributes , 'name' ));
if ( array_diff ( $prodotto -> attributes [ $found_key ] -> options , $article -> authors ) === array_diff ( $article -> authors , $prodotto -> attributes [ $found_key ] -> options )) {
$id = $prodotto -> id ;
$variations = Variation :: all ( $prodotto -> id );
2024-12-18 08:56:53 +01:00
foreach ( $variations as $variation ) {
2024-06-17 14:41:58 +02:00
$found_key_version = array_search ( 'Versione' , array_column ( $variation -> attributes , 'name' ));
if ( $variation -> attributes [ $found_key_version ] -> option == $formato ) {
$id = 0 ;
}
}
}
}
}
}
$data1 = [
'regular_price' => $article -> PrezzoIvato ,
'sku' => $article -> IdArticolo ,
'sale_price' => $article -> PrezzoIvatoScontatoCampagna ,
'date_on_sale_from' => $article -> DataInizioCampagna ,
'date_on_sale_to' => $article -> DataFineCampagna ,
//'manage_stock' => true,
//'stock_quantity' => $article->stock,
'purchasable' => 'false' ,
'attributes' => [
[
'id' => 6 ,
'option' => $formato
]
],
'meta_data' => [
[
'key' => 'ISBN' ,
'value' => $article -> Ean13
],
[
'key' => 'misure' ,
'value' => $article -> Misure
],
[
'key' => 'formato' ,
'value' => $article -> DescrizioneFormato
],
[
'key' => 'pagine' ,
'value' => $article -> Pagine
],
[
'key' => 'edizione' ,
'value' => $article -> Edizione
],
]
];
if ( $id == 0 ) {
$versione = 'Nuova versione' ;
$category = Category :: where ( 'name' , $article -> argomento );
if ( $category -> count () > 0 ) {
$categoria = $category -> first ();
$categoriaid = $categoria [ 'id' ];
} else {
$categoriaid = 0 ;
}
$data = [
'name' => $titolo ,
'type' => 'variable' ,
2024-12-18 08:56:53 +01:00
'short_description' => $article -> Sottotitolo ,
2024-06-17 14:41:58 +02:00
'categories' => [
[ 'id' => $categoriaid ]
],
'status' => 'draft' ,
'attributes' => [
[
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
],
[
//'id' => 5,
'id' => 7 ,
'visible' => true ,
'options' =>
2024-12-18 08:56:53 +01:00
$article -> authors
2024-06-17 14:41:58 +02:00
],
[
//'id' => 2,
'id' => 8 ,
'visible' => true ,
'options' => [
$article -> editore
]
],
[
//'id' => 7,
'id' => 9 ,
'visible' => true ,
'options' => [
$article -> DescrizioneTipologia
]
]
],
'default_attributes' => [
[
//'id' => 1,
'id' => 6 ,
'option' => 'Nuovo'
]
],
];
$product = Product :: create ( $data );
$idprodotto = $product [ 'id' ];
$variation = Variation :: create ( $idprodotto , $data1 );
} else {
$versione = " Aggiunta versione " ;
$product = Product :: find ( $id );
$old_attributes = $product [ 'attributes' ];
$attributes = [];
foreach ( $old_attributes as $old_attribute ) {
if ( $old_attribute -> id <> 6 ) {
$attributes [] = [
'id' => $old_attribute -> id ,
'variation' => $old_attribute -> variation ,
'visible' => $old_attribute -> visible ,
'options' => $old_attribute -> options
];
}
}
2024-12-18 08:56:53 +01:00
$attributes [] = [
2024-06-17 14:41:58 +02:00
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
];
//dd($attributes);
$data = [
'attributes' => $attributes
];
Product :: update ( $id , $data );
$variation = Variation :: create ( $id , $data1 );
}
$productLogger -> addLog ( 'inserted' , $article -> Titolo . ' - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . ' - ' . $versione . ' - ' . $variation [ 'permalink' ] . " \n " );
$productLogger -> setAggiornato ( true );
break ;
case 'Dvd' :
$titolo = rtrim ( $article -> Titolo );
$titolo = rtrim ( str_ireplace ( 'DVD' , '' , $titolo ));
$titolo = rtrim ( $titolo );
$titolo = rtrim ( str_ireplace ( '_' , '' , $titolo ));
$titolo = rtrim ( $titolo );
$titolo = rtrim ( $titolo , '-' );
$titolo = rtrim ( $titolo );
$titolo = rtrim ( $titolo , '_' );
$titolo = rtrim ( $titolo );
$prodotti = $prodotti -> where ( 'name' , $titolo ) -> get ();
$id = 0 ;
if ( ! is_null ( $prodotti ) && $prodotti -> count () > 0 ) {
foreach ( $prodotti as $prodotto ) {
if ( strtolower ( $prodotto -> name ) === strtolower ( $titolo )) {
$found_key = array_search ( 'Autore libro' , array_column ( $prodotto -> attributes , 'name' ));
if ( array_diff ( $prodotto -> attributes [ $found_key ] -> options , $article -> authors ) === array_diff ( $article -> authors , $prodotto -> attributes [ $found_key ] -> options )) {
$id = $prodotto -> id ;
$variations = Variation :: all ( $prodotto -> id );
2024-12-18 08:56:53 +01:00
foreach ( $variations as $variation ) {
2024-06-17 14:41:58 +02:00
$found_key_version = array_search ( 'Versione' , array_column ( $variation -> attributes , 'name' ));
if ( $variation -> attributes [ $found_key_version ] -> option == 'DVD' ) {
$id = 0 ;
}
}
}
}
}
}
$data1 = [
'regular_price' => $article -> PrezzoIvato ,
'sku' => $article -> IdArticolo ,
'sale_price' => $article -> PrezzoIvatoScontatoCampagna ,
'date_on_sale_from' => $article -> DataInizioCampagna ,
'date_on_sale_to' => $article -> DataFineCampagna ,
'manage_stock' => true ,
'stock_quantity' => $article -> stock ,
'purchasable' => false ,
'attributes' => [
[
'id' => 6 ,
'option' => 'DVD'
]
],
'meta_data' => [
[
'key' => 'ISBN' ,
'value' => $article -> Ean13
],
[
'key' => 'misure' ,
'value' => $article -> Misure
],
[
'key' => 'formato' ,
'value' => $article -> DescrizioneFormato
],
[
'key' => 'pagine' ,
'value' => $article -> Pagine
],
[
'key' => 'edizione' ,
'value' => $article -> Edizione
],
]
];
if ( $id == 0 ) {
$versione = 'Nuova versione' ;
$category = Category :: where ( 'name' , $article -> argomento );
if ( $category -> count () > 0 ) {
$categoria = $category -> first ();
$categoriaid = $categoria [ 'id' ];
} else {
$categoriaid = 0 ;
}
$data = [
'name' => $article -> Titolo ,
'type' => 'variable' ,
2024-12-18 08:56:53 +01:00
'short_description' => $article -> Sottotitolo ,
2024-06-17 14:41:58 +02:00
'categories' => [
[ 'id' => $categoriaid ]
],
'status' => 'draft' ,
//'description' => 'Simple product full description.',
//'short_description' => 'Simple product short description.',
'attributes' => [
[
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
],
[
//'id' => 5,
'id' => 7 ,
'visible' => true ,
'options' =>
2024-12-18 08:56:53 +01:00
$article -> authors
2024-06-17 14:41:58 +02:00
],
[
//'id' => 2,
'id' => 8 ,
'visible' => true ,
'options' => [
$article -> editore
]
],
[
//'id' => 7,
'id' => 9 ,
'visible' => true ,
'options' => [
$article -> DescrizioneTipologia
]
]
],
'default_attributes' => [
[
//'id' => 1,
'id' => 6 ,
'option' => 'Nuovo'
]
],
];
$product = Product :: create ( $data );
$idprodotto = $product [ 'id' ];
$variation = Variation :: create ( $idprodotto , $data1 );
} else {
$versione = " Aggiunta versione " ;
$product = Product :: find ( $id );
$old_attributes = $product [ 'attributes' ];
$attributes = [];
foreach ( $old_attributes as $old_attribute ) {
if ( $old_attribute -> id <> 6 ) {
$attributes [] = [
'id' => $old_attribute -> id ,
'variation' => $old_attribute -> variation ,
'visible' => $old_attribute -> visible ,
'options' => $old_attribute -> options
];
}
}
2024-12-18 08:56:53 +01:00
$attributes [] = [
2024-06-17 14:41:58 +02:00
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
];
//dd($attributes);
$data = [
'attributes' => $attributes
];
Product :: update ( $id , $data );
$variation = Variation :: create ( $id , $data1 );
}
$productLogger -> addLog ( 'inserted' , $article -> Titolo . ' - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . ' - ' . $versione . ' - ' . $variation [ 'permalink' ] . " \n " );
$productLogger -> setAggiornato ( true );
break ;
case 'Video Streaming' :
case 'Video On Demand' :
if ( $article -> DescrizioneFormato === 'Streaming' ) {
$titolo = rtrim ( $article -> Titolo , 'STR' );
$titolo = rtrim ( str_ireplace ( 'streaming' , '' , $titolo ));
$formato = 'Streaming' ;
} elseif ( $article -> DescrizioneFormato === 'Download' ) {
$titolo = rtrim ( $article -> Titolo , 'VOD' );
$titolo = rtrim ( str_ireplace ( 'download' , '' , $titolo ));
$formato = 'Download' ;
} else {
$productLogger -> addLog ( 'not_inserted' , $article -> Titolo . ' - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . " \n " );
$productLogger -> setAggiornato ( true );
break ;
}
$titolo = rtrim ( $titolo );
$titolo = rtrim ( str_ireplace ( '_' , '' , $titolo ));
$titolo = rtrim ( $titolo );
$titolo = rtrim ( $titolo , '-' );
$titolo = rtrim ( $titolo );
$titolo = rtrim ( $titolo , '_' );
$titolo = rtrim ( $titolo );
$prodotti = $prodotti -> where ( 'name' , $titolo ) -> get ();
$id = 0 ;
if ( ! is_null ( $prodotti ) && $prodotti -> count () > 0 ) {
foreach ( $prodotti as $prodotto ) {
if ( strtolower ( $prodotto -> name ) === strtolower ( $titolo )) {
$found_key = array_search ( 'Autore libro' , array_column ( $prodotto -> attributes , 'name' ));
if ( array_diff ( $prodotto -> attributes [ $found_key ] -> options , $article -> authors ) === array_diff ( $article -> authors , $prodotto -> attributes [ $found_key ] -> options )) {
$id = $prodotto -> id ;
$variations = Variation :: all ( $prodotto -> id );
2024-12-18 08:56:53 +01:00
foreach ( $variations as $variation ) {
2024-06-17 14:41:58 +02:00
$found_key_version = array_search ( 'Versione' , array_column ( $variation -> attributes , 'name' ));
if ( $variation -> attributes [ $found_key_version ] -> option == $formato ) {
$id = 0 ;
}
}
}
}
}
}
$data1 = [
'regular_price' => $article -> PrezzoIvato ,
'sku' => $article -> IdArticolo ,
'sale_price' => $article -> PrezzoIvatoScontatoCampagna ,
'date_on_sale_from' => $article -> DataInizioCampagna ,
'date_on_sale_to' => $article -> DataFineCampagna ,
//'manage_stock' => true,
//'stock_quantity' => $article->stock,
'purchasable' => false ,
'attributes' => [
[
'id' => 6 ,
'option' => $formato
]
],
'meta_data' => [
[
'key' => 'ISBN' ,
'value' => $article -> Ean13
],
[
'key' => 'misure' ,
'value' => $article -> Misure
],
[
'key' => 'formato' ,
'value' => $article -> DescrizioneFormato
],
[
'key' => 'pagine' ,
'value' => $article -> Pagine
],
[
'key' => 'edizione' ,
'value' => $article -> Edizione
],
]
];
if ( $id == 0 ) {
$versione = 'Nuova versione' ;
$category = Category :: where ( 'name' , $article -> argomento );
if ( $category -> count () > 0 ) {
$categoria = $category -> first ();
$categoriaid = $categoria [ 'id' ];
} else {
$categoriaid = 0 ;
}
$data = [
'name' => $titolo ,
'type' => 'variable' ,
2024-12-18 08:56:53 +01:00
'short_description' => $article -> Sottotitolo ,
2024-06-17 14:41:58 +02:00
'categories' => [
[ 'id' => $categoriaid ]
],
'status' => 'draft' ,
'attributes' => [
[
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
],
[
//'id' => 5,
'id' => 7 ,
'visible' => true ,
'options' =>
2024-12-18 08:56:53 +01:00
$article -> authors
2024-06-17 14:41:58 +02:00
],
[
//'id' => 2,
'id' => 8 ,
'visible' => true ,
'options' => [
$article -> editore
]
],
[
//'id' => 7,
'id' => 9 ,
'visible' => true ,
'options' => [
$article -> DescrizioneTipologia
]
]
],
'default_attributes' => [
[
//'id' => 1,
'id' => 6 ,
'option' => 'Nuovo'
]
],
];
$product = Product :: create ( $data );
$idprodotto = $product [ 'id' ];
$variation = Variation :: create ( $idprodotto , $data1 );
} else {
$versione = " Aggiunta versione " ;
$product = Product :: find ( $id );
$old_attributes = $product [ 'attributes' ];
$attributes = [];
foreach ( $old_attributes as $old_attribute ) {
if ( $old_attribute -> id <> 6 ) {
$attributes [] = [
'id' => $old_attribute -> id ,
'variation' => $old_attribute -> variation ,
'visible' => $old_attribute -> visible ,
'options' => $old_attribute -> options
];
}
}
2024-12-18 08:56:53 +01:00
$attributes [] = [
2024-06-17 14:41:58 +02:00
//'id' => 1,
'id' => 6 ,
'position' => 0 ,
'visible' => true ,
'variation' => true ,
'options' => [
'Nuovo' ,
'Usato' ,
'PDF' ,
'Epub' ,
'Mobi' ,
'DVD' ,
'Streaming' ,
'Download'
]
];
//dd($attributes);
$data = [
'attributes' => $attributes
];
Product :: update ( $id , $data );
$variation = Variation :: create ( $id , $data1 );
}
$productLogger -> addLog ( 'inserted' , $article -> Titolo . ' - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . ' - ' . $versione . ' - ' . $variation [ 'permalink' ] . " \n " );
$productLogger -> setAggiornato ( true );
break ;
}
} else {
2024-11-27 12:38:26 +01:00
// ESISTE GIA' IL LIBRO
2024-12-18 08:56:53 +01:00
2024-12-19 15:15:06 +01:00
echo " Esiste già il libro... " ;
2024-06-17 14:41:58 +02:00
$data1 = [
'regular_price' => $article -> PrezzoIvato ,
'sale_price' => $article -> PrezzoIvatoScontatoCampagna ,
'date_on_sale_from' => $article -> DataInizioCampagna ,
'date_on_sale_to' => $article -> DataFineCampagna ,
'stock_quantity' => $article -> stock ,
];
$idprodotto = $productsku [ 'parent_id' ];
if ( $idprodotto > 0 ) {
$variation = Variation :: update ( $idprodotto , $productsku [ 'id' ], $data1 );
$productLogger -> addLog ( 'updated' , $article -> Titolo . ' - [Quantità: ' . $data1 [ 'stock_quantity' ] . '] - ' . $article -> DescrizioneTipologia . ' - ' . $article -> DescrizioneFormato . ' - Articolo aggiornato - ' . $variation [ 'permalink' ] . " \n " );
$productLogger -> setAggiornato ( true );
}
}
if ( $preorder ) {
// Controlla se è in preordine
$inprevendita = isArticleInPrevendita ( $article -> IdArticolo , true );
if ( $inprevendita ) {
2024-12-19 15:15:06 +01:00
echo " ...imposta in prevendita ! " ;
2024-06-17 15:38:36 +02:00
setPreOrder ( $article -> IdArticolo , " 1 " , false );
2024-06-19 19:09:40 +02:00
$productLogger -> addLog ( 'pre_order' , $article -> titolo . ' [' . $article -> IdArticolo . '] Impostato IN PREVENDITA !' . " \n " );
2024-07-08 12:12:24 +02:00
} else {
2024-12-19 15:15:06 +01:00
echo " ...disabilita la prevendita ! " ;
2024-07-08 12:12:24 +02:00
setPreOrder ( $article -> IdArticolo , " 0 " , false );
$productLogger -> addLog ( 'mettilo in Vendita (no pre-order)' , $article -> titolo . ' [' . $article -> IdArticolo . '] Impostato IN VENDITA !' . " \n " );
2024-06-17 14:41:58 +02:00
}
}
2024-12-19 15:15:06 +01:00
echo " ...FINE ! " ;
2024-06-17 14:41:58 +02:00
} catch ( \Exception $e ) {
2024-08-23 00:22:56 +02:00
$productLogger -> addLog ( 'server_issues' , $article -> IdArticolo . ' - ' . $article -> Titolo . " \n " . $e -> getMessage () . " \n " );
2024-06-20 09:22:18 +02:00
$productLogger -> setAggiornato ( true );
2024-06-17 14:41:58 +02:00
}
}
2024-06-19 18:19:17 +02:00
function getArticoloById ( $idarticolo )
{
2024-06-18 09:46:45 +02:00
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
})
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
})
-> leftJoin ( DB :: raw ( '(SELECT g.IdTipologia, g.Descrizione as DescrizioneTipologia FROM T_WEB_Tipologie g JOIN (SELECT IdTipologia, MAX(DataOra) as data1 from T_WEB_Tipologie GROUP BY IdTipologia) h ON g.IdTipologia = h.IdTipologia AND g.DataOra = h.data1 ) i' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipologia' , '=' , 'i.IdTipologia' );
})
-> leftJoin ( DB :: raw ( '(SELECT l.IdTipoFormato, l.Descrizione as DescrizioneFormato FROM T_WEB_TipiFormato l JOIN (SELECT IdTipoFormato, MAX(DataOra) as data1 from T_WEB_TipiFormato GROUP BY IdTipoFormato) m ON l.IdTipoFormato = m.IdTipoFormato AND l.DataOra = m.data1 ) n' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipoFormato' , '=' , 'n.IdTipoFormato' );
})
-> where ( 'T_WEB_Articoli.IdArticolo' , $idarticolo )
/*
-> leftJoin ( DB :: raw ( '(SELECT o.Codice, o.QtaDisponibile FROM T_WEB_Disponibile o JOIN (SELECT Codice, MAX(DataOra) as data1 from T_WEB_Disponibile GROUP BY Codice) p ON o.Codice = p.Codice AND o.DataOra = p.data1 ) q' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'q.Codice' );
})
*/
//->where('T_WEB_Articoli.DataOra','>',$settingora->value)
-> where ( function ( $query ) {
$query -> where ( 'DescrizioneStatoProdotto' , 'In commercio' )
-> orWhere ( 'DescrizioneStatoProdotto' , 'In prevendita' )
-> orWhere ( 'DescrizioneStatoProdotto' , 'Prossima uscita' );
})
//->where('DescrizioneTipologia','Video Streaming')
-> orderBy ( 'dataOra' , 'desc' )
-> get ();
// se $articles è un array
if ( count ( $articles ) > 0 ) {
$article = $articles [ 0 ];
} else {
$article = null ;
}
return $article ;
}
2024-09-05 17:16:56 +02:00
function getArticoliCartolibro ()
{
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
})
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
})
-> leftJoin ( DB :: raw ( '(SELECT g.IdTipologia, g.Descrizione as DescrizioneTipologia FROM T_WEB_Tipologie g JOIN (SELECT IdTipologia, MAX(DataOra) as data1 from T_WEB_Tipologie GROUP BY IdTipologia) h ON g.IdTipologia = h.IdTipologia AND g.DataOra = h.data1 ) i' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipologia' , '=' , 'i.IdTipologia' );
})
-> leftJoin ( DB :: raw ( '(SELECT l.IdTipoFormato, l.Descrizione as DescrizioneFormato FROM T_WEB_TipiFormato l JOIN (SELECT IdTipoFormato, MAX(DataOra) as data1 from T_WEB_TipiFormato GROUP BY IdTipoFormato) m ON l.IdTipoFormato = m.IdTipoFormato AND l.DataOra = m.data1 ) n' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipoFormato' , '=' , 'n.IdTipoFormato' );
})
2024-09-05 17:25:29 +02:00
-> where ( 'DescrizioneStatoProdotto' , 'In commercio' )
2024-09-05 17:16:56 +02:00
-> where ( 'DescrizioneTipologia' , 'Cartolibro' )
2024-09-05 17:25:29 +02:00
-> orderBy ( 'Titolo' )
2024-09-05 17:16:56 +02:00
-> get ();
2024-09-05 17:25:29 +02:00
2024-09-05 17:43:21 +02:00
echo " Trovati " . $articles -> count () . " articoli <br> " ;
2024-09-05 17:25:29 +02:00
2024-09-05 17:16:56 +02:00
return $articles ;
}
2024-06-17 14:41:58 +02:00
2024-12-12 20:03:24 +01:00
function getArticoliRiviste ()
{
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
})
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
})
-> leftJoin ( DB :: raw ( '(SELECT g.IdTipologia, g.Descrizione as DescrizioneTipologia FROM T_WEB_Tipologie g JOIN (SELECT IdTipologia, MAX(DataOra) as data1 from T_WEB_Tipologie GROUP BY IdTipologia) h ON g.IdTipologia = h.IdTipologia AND g.DataOra = h.data1 ) i' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipologia' , '=' , 'i.IdTipologia' );
})
-> leftJoin ( DB :: raw ( '(SELECT l.IdTipoFormato, l.Descrizione as DescrizioneFormato FROM T_WEB_TipiFormato l JOIN (SELECT IdTipoFormato, MAX(DataOra) as data1 from T_WEB_TipiFormato GROUP BY IdTipoFormato) m ON l.IdTipoFormato = m.IdTipoFormato AND l.DataOra = m.data1 ) n' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipoFormato' , '=' , 'n.IdTipoFormato' );
})
-> where ( 'DescrizioneStatoProdotto' , 'In commercio' )
-> where ( 'DescrizioneTipologia' , 'Rivista' )
-> orderBy ( 'Titolo' )
-> get ();
echo " Trovati " . $articles -> count () . " riviste <br> " ;
return $articles ;
}
2024-06-17 15:09:49 +02:00
function updateArticoloFromGM ( $idarticolo )
{
2024-06-19 18:40:07 +02:00
$productLogger = new ProductLogger ( null , '' );
2024-06-17 14:41:58 +02:00
2024-06-17 15:25:32 +02:00
try {
2024-06-17 15:24:48 +02:00
$articles = Article :: join ( DB :: raw ( '(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'b.IdArticolo' )
-> on ( 'T_WEB_Articoli.DataOra' , '=' , 'b.data' );
2024-06-17 14:41:58 +02:00
})
2024-06-17 15:24:48 +02:00
-> leftJoin ( DB :: raw ( '(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdStatoProdotto' , '=' , 'f.IdStatoProdotto' );
})
-> leftJoin ( DB :: raw ( '(SELECT g.IdTipologia, g.Descrizione as DescrizioneTipologia FROM T_WEB_Tipologie g JOIN (SELECT IdTipologia, MAX(DataOra) as data1 from T_WEB_Tipologie GROUP BY IdTipologia) h ON g.IdTipologia = h.IdTipologia AND g.DataOra = h.data1 ) i' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipologia' , '=' , 'i.IdTipologia' );
})
-> leftJoin ( DB :: raw ( '(SELECT l.IdTipoFormato, l.Descrizione as DescrizioneFormato FROM T_WEB_TipiFormato l JOIN (SELECT IdTipoFormato, MAX(DataOra) as data1 from T_WEB_TipiFormato GROUP BY IdTipoFormato) m ON l.IdTipoFormato = m.IdTipoFormato AND l.DataOra = m.data1 ) n' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdTipoFormato' , '=' , 'n.IdTipoFormato' );
})
2024-06-17 15:26:21 +02:00
-> where ( 'T_WEB_Articoli.IdArticolo' , $idarticolo )
2024-06-17 15:25:32 +02:00
/*
2024-06-17 15:24:48 +02:00
-> leftJoin ( DB :: raw ( '(SELECT o.Codice, o.QtaDisponibile FROM T_WEB_Disponibile o JOIN (SELECT Codice, MAX(DataOra) as data1 from T_WEB_Disponibile GROUP BY Codice) p ON o.Codice = p.Codice AND o.DataOra = p.data1 ) q' ), function ( $join ) {
$join -> on ( 'T_WEB_Articoli.IdArticolo' , '=' , 'q.Codice' );
})
*/
//->where('T_WEB_Articoli.DataOra','>',$settingora->value)
-> where ( function ( $query ) {
$query -> where ( 'DescrizioneStatoProdotto' , 'In commercio' )
-> orWhere ( 'DescrizioneStatoProdotto' , 'In prevendita' )
-> orWhere ( 'DescrizioneStatoProdotto' , 'Prossima uscita' );
})
//->where('DescrizioneTipologia','Video Streaming')
-> orderBy ( 'dataOra' , 'desc' )
-> get ();
2024-06-17 14:41:58 +02:00
2024-06-17 15:27:42 +02:00
// se $articles è un array
if ( count ( $articles ) > 0 ) {
2024-06-17 15:25:32 +02:00
$article = $articles [ 0 ];
} else {
$article = null ;
}
2024-06-17 14:41:58 +02:00
2024-06-17 15:25:32 +02:00
if ( $article ) {
2024-06-17 15:30:06 +02:00
$str = " Articolo: " ;
$str .= getarraystr ( $article );
2024-06-18 10:13:49 +02:00
$str .= " setProductFromGM: " ;
2024-06-17 15:25:32 +02:00
setProductFromGM ( $article , false , $productLogger );
2024-06-17 14:52:04 +02:00
2024-06-17 15:25:32 +02:00
$str .= $productLogger -> concatenateLogs ();
2024-06-17 15:21:54 +02:00
2024-06-17 15:25:32 +02:00
return $str ;
} else {
return " Articolo non trovato " ;
}
} catch ( \Exception $e ) {
return " Errore updateArticoloFromGM: " . $e -> getMessage ();
2024-06-17 15:09:49 +02:00
}
}
2024-07-11 14:40:33 +02:00
2024-07-11 15:53:35 +02:00
function getClienteByIdInternet_Ordine ( $idInternet )
2024-07-11 14:43:20 +02:00
{
try {
2024-07-11 15:53:35 +02:00
$clienteinGM = Clientegm :: where ( 'IdInternet' , $idInternet ) -> first ();
} catch ( \Exception $e ) {
return null ;
}
return $clienteinGM ;
}
function getClienteByIdCodClienteInternet ( $codClienteInternet )
{
try {
$clienteinGM = Clientegm :: where ( 'codClienteInternet' , $codClienteInternet ) -> first ();
2024-07-11 14:43:20 +02:00
} catch ( \Exception $e ) {
2024-07-11 15:10:13 +02:00
return null ;
2024-07-11 14:40:33 +02:00
}
return $clienteinGM ;
}
2024-07-11 16:24:21 +02:00
2024-08-12 10:44:54 +02:00
function getOrderByIdInternet ( $idInternet )
{
try {
2024-08-12 11:14:26 +02:00
$ordergm = Orderdetail :: where ( 'IdInternet' , $idInternet ) -> first ();
2024-08-12 10:44:54 +02:00
return $ordergm ;
} catch ( \Exception $e ) {
return null ;
}
}
2024-07-18 15:04:18 +02:00
function getClienti ()
{
2024-07-11 16:24:21 +02:00
try {
$clienti = Clientegm :: all ();
dd ( $clienti );
} catch ( \Exception $e ) {
return null ;
}
2024-07-18 15:04:18 +02:00
}
2024-08-13 15:22:21 +02:00
function getvalstr ( $mystr , $value , $separato = false )
{
$my = '' ;
if ( $mystr ) {
$my = " " . $mystr . " : " . $value ;
} else {
2024-12-19 11:14:00 +01:00
if ( $value ) {
$my = $value ;
if ( ! $separato ) {
$my = " " . $value ;
}
2024-08-13 15:22:21 +02:00
}
}
if ( $separato ) {
$my = '[' . $my . '] ' ;
}
return $my ;
}