2024-05-19 13:06:17 +02:00
< ? php
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 ;
use App\Mylog ;
use Codexshaper\WooCommerce\Models\Product as ModelsProduct ;
use Codexshaper\WooCommerce\Facades\Variation ;
use Codexshaper\WooCommerce\Facades\Category ;
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
2024-06-13 09:04:07 +02:00
use App\Orderdetail ;
2024-06-17 14:41:58 +02:00
use App\Services\ProductLogger ;
2024-05-22 14:29:58 +02:00
use Codexshaper\WooCommerce\Facades\Order ;
2024-06-13 09:13:17 +02:00
use Illuminate\Support\Facades\Schema ;
2024-05-20 01:23:47 +02:00
2024-06-15 16:29:05 +02:00
define ( 'QTA_IN_PREVENDITA' , 10000 );
2024-06-18 09:27:55 +02:00
define ( 'QTA_MINIMA_PER_PREVENDITA' , 9000 );
2024-06-15 16:29:05 +02:00
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-05-21 01:18:26 +02:00
function getarraystr ( $array )
{
return '<pre>' . json_encode ( $array , JSON_PRETTY_PRINT ) . '</pre>' ;
};
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
function setPreOrderByIdArticolo ( $idarticolo , $aggiornapreordine , $debug )
{
return setPreOrder ( $idarticolo , $aggiornapreordine , $debug );
}
2024-06-18 10:03:19 +02:00
function formatDateToItalian ( $date_string , $input_format = 'Y-m-d H:i:s.u' ) {
// 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-05-20 01:23:47 +02:00
function setPreOrder ( $sku , $aggiornapreordine , $debug )
{
try {
// Aggiorna Preorder
$product = Product :: where ( 'sku' , $sku ) -> first ();
// get the article by product
// $article = Article::where('IdArticolo', $idarticolo)->first();
// showarray($article);
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-05-20 01:23:47 +02:00
$campoPreOrder = '_wpro_variable_is_preorder' ;
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-18 09:58:01 +02:00
echo " DataPubblicazione: " . $article -> DataPubblicazione . " <br> " ;
2024-06-18 09:59:13 +02:00
$datepubbl = DateTime :: createFromFormat ( 'Y-m-d H:i:s.u' , $article -> DataPubblicazione );
2024-06-18 09:33:44 +02:00
2024-06-18 09:49:25 +02:00
$datepubblstr = $datepubbl -> format ( 'Y-m-d' );
2024-06-18 10:04:24 +02:00
$datepubbllabel = formatDateToItalian ( $article -> DataPubblicazione );
2024-06-18 09:49:25 +02:00
2024-06-18 10:03:19 +02:00
$label_prenotalo_con_data = 'Prenotalo per riceverlo entro il ' . $datepubbllabel ;
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 ;
}
}
2024-06-15 16:29:05 +02:00
$data [ 'stock_quantity' ] = QTA_IN_PREVENDITA ;
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-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-05-20 01:23:47 +02:00
}
} else {
if ( $debug )
echo " Il prodotto non esiste " ;
}
} 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-05-22 14:29:58 +02:00
function showOrdini ()
{
2024-06-13 09:31:34 +02:00
$str = " " ;
2024-05-22 14:29:58 +02:00
2024-06-13 09:04:07 +02:00
try {
2024-06-13 09:18:45 +02:00
// $str = Schema::getColumnListing('Orderdetails');
2024-06-13 09:13:17 +02:00
2024-06-13 09:18:45 +02:00
$orders = Orderdetail :: orderBy ( 'DataOra' , 'desc' )
2024-06-13 10:02:29 +02:00
-> take ( 20 )
2024-06-13 09:08:18 +02:00
-> get ();
2024-06-13 09:04:07 +02:00
// Show the fields of the orders
foreach ( $orders as $order ) {
2024-06-13 10:08:53 +02:00
// $product = Product::where('sku', $order->CodArticoloGM)->first();
2024-06-13 13:37:52 +02:00
2024-06-13 09:28:10 +02:00
$str .= getvalstr ( " " , $order -> Codice ) . " " ;
2024-06-13 09:31:34 +02:00
$str .= getvalstr ( " " , $order -> DataOra );
2024-06-13 13:37:52 +02:00
$str .= getvalstr ( " IdInternet " , $order -> IdInternet , true ) . " " ;
2024-06-13 09:25:54 +02:00
$str .= getvalstr ( " " , $order -> CodArticoloGM , true );
2024-06-13 09:22:17 +02:00
$str .= getvalstr ( " Qta " , $order -> Qta );
$str .= getvalstr ( " Prezzo " , $order -> PrezzoLordo );
2024-06-13 09:31:34 +02:00
if ( $order -> PercSconto )
$str .= getvalstr ( " Sconto " , $order -> PercSconto );
if ( $order -> Descrizione )
$str .= getvalstr ( " Descr " , $order -> Descrizione );
2024-06-13 09:59:24 +02:00
2024-06-13 10:05:23 +02:00
//$str .= $product;
2024-06-13 10:08:26 +02:00
// $str .= $product;
2024-06-13 09:10:36 +02:00
$str .= '<br>' ;
2024-06-13 09:20:47 +02:00
}
2024-06-13 09:04:07 +02:00
} catch ( \Exception $e ) {
return " Errore: " . $e -> getMessage ();
}
return $str ;
}
2024-06-13 12:46:33 +02:00
function showDettOrdini ()
2024-06-13 09:04:07 +02:00
{
2024-06-18 09:13:43 +02:00
$str = " Ordini Woocommerce: " . PHP_EOL . '<br>' ;
2024-06-13 09:04:07 +02:00
2024-06-13 08:57:58 +02:00
try {
2024-06-15 17:17:46 +02:00
$orders = Order :: all ();
2024-06-13 08:57:58 +02:00
// Show the fields of the orders
foreach ( $orders as $order ) {
$str .= " Ordine: " ;
$str .= getvalstr ( " Id " , $order -> id );
2024-06-13 09:00:40 +02:00
//$str .= getvalstr("DataOra", $order->DataOra);
//$str .= getvalstr("Totale", $order->Totale);
2024-06-18 09:13:43 +02:00
$str .= getvalstr ( " IdInternet " , $order -> IdInternet , true ) . " " ;
$str .= getvalstr ( " " , $order -> CodClienteInternet , true );
$str .= '<br>' ;
2024-06-15 18:29:22 +02:00
}
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-06-17 16:01:10 +02:00
return ' € ' . number_format ( $prezzo , 2 );
2024-06-17 16:00:43 +02:00
}
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-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 ();
$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-05-21 01:03:36 +02:00
$mydatestr = $article -> DataPubblicazione ;
2024-05-21 00:44:43 +02:00
2024-05-21 01:03:36 +02:00
$sku = $article -> IdArticolo ;
2024-05-21 00:44:43 +02:00
2024-06-13 14:41:27 +02:00
$prodotto = Product :: where ( 'sku' , $sku ) -> first ();
2024-06-13 14:48:57 +02:00
$qtyinstock = intval ( $prodotto [ 'stock_quantity' ]);
2024-06-17 15:58:00 +02:00
$prezzo = $prodotto [ 'sale_price' ];
if ( ! $prezzo ) {
$prezzo = $prodotto [ 'price' ];
}
2024-06-13 14:48:57 +02:00
if ( $qtyinstock <= 0 ) {
2024-06-13 13:37:52 +02:00
$colore = 'red' ;
2024-06-13 14:46:49 +02:00
} else {
2024-06-13 13:37:52 +02:00
$colore = 'green' ;
}
2024-06-13 14:46:49 +02:00
2024-06-13 13:37:52 +02:00
2024-05-21 01:03:36 +02:00
// echo '[' . $ind . ']' . $sep . $mydatestr . $sep . $article->IdArticolo . $sep . $article->Titolo . $sep . $article->DescrizioneStatoProdotto . $sep . $article->DescrizioneFormato . ' [Quantita = ' . $article->QtaDisponibile . ']';
2024-06-13 14:46:49 +02:00
$myview = '[' . $ind . ']' . $sep .
'<a href="' . $article -> permalink . '?id=' . $article -> IdArticolo . '" target="_blank">' . $article -> IdArticolo . '</a>' . $sep .
2024-06-13 14:59:09 +02:00
'<a href="' . $prodotto [ 'permalink' ] . '" target="_blank"><span style="color:' . $colore . '; font-weight: bold;"> ' . $article -> Titolo . '</span></a>' . $sep .
2024-06-17 16:03:27 +02:00
' Pubb:' . date ( 'd-m-Y' , strtotime ( $article -> DataPubblicazione )) . $sep .
2024-06-13 13:37:52 +02:00
$article -> DescrizioneStatoProdotto . ' (' . $article -> DescrizioneFormato . ')' . $sep .
2024-06-13 14:46:49 +02:00
'[Qta = <span style="">' . $article -> QtaDisponibile . '</span>]' . $sep .
2024-06-17 16:00:43 +02:00
' [' . showprice ( $prezzo ) . ' ]' . $sep .
2024-06-13 14:48:57 +02:00
'[In Stock = <span style="color:' . $colore . '; font-weight: bold;">' . $qtyinstock . '</span>]' . $sep ;
2024-06-13 14:46:49 +02:00
2024-06-18 09:27:55 +02:00
if ( $qtyinstock < QTA_MINIMA_PER_PREVENDITA ) {
2024-06-13 14:54:40 +02:00
$myview .= '<a href="' . $article -> permalink . '/apimacro/public/aggiornapreorder/' . $article -> IdArticolo . '/1/" target="_blank">Imposta in PRE-ORDINE!</a>' . $sep ;
2024-06-18 09:13:43 +02:00
} else {
$myview .= '<a href="' . $article -> permalink . '/apimacro/public/aggiornapreorder/' . $article -> IdArticolo . '/-1/" target="_blank">Impostalo Non Disponibile</a>' . $sep ;
2024-06-13 14:46:49 +02:00
}
echo $myview ;
2024-06-13 13:37:52 +02:00
2024-05-21 01:03:36 +02:00
if ( $prodotto ) {
2024-05-21 00:44:43 +02:00
2024-05-21 01:03:36 +02:00
if ( isset ( $prodotto [ '_wpro_variable_is_preorder' ])) {
echo '<br><span style="color:red">PREORDINE: ' . $prodotto [ '_wpro_variable_is_preorder' ] . '</span>' ;
}
if ( isset ( $prodotto [ '_wpro_label_variable' ])) {
echo 'Etichetta: ' . $prodotto [ '_wpro_label_variable' ];
}
if ( isset ( $prodotto [ '_wpro_date_variable' ])) {
echo 'Data Preordine: ' . $prodotto [ '_wpro_date_variable' ];
}
echo '<br>' ;
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 ) {
$productLogger = new ProductLogger ( null );
} 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 ();
$titolo = $article -> Titolo ;
switch ( $article -> DescrizioneTipologia ) {
case 'Libri' :
$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 );
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 ;
}
}
}
}
}
}
$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' => [
[
'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
],
[
'key' => 'ristampa' ,
'value' => $article -> Ristampa
],
]
];
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' ,
'short_description' => $article -> Sottotitolo ,
'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' =>
$article -> authors
],
[
//'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 );
//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
];
}
}
$attributes [] = [
//'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 );
foreach ( $variations as $variation ) {
$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' ,
'short_description' => $article -> Sottotitolo ,
'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' =>
$article -> authors
],
[
//'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
];
}
}
$attributes [] = [
//'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 );
foreach ( $variations as $variation ) {
$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' ,
'short_description' => $article -> Sottotitolo ,
'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' =>
$article -> authors
],
[
//'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
];
}
}
$attributes [] = [
//'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 );
foreach ( $variations as $variation ) {
$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' ,
'short_description' => $article -> Sottotitolo ,
'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' =>
$article -> authors
],
[
//'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
];
}
}
$attributes [] = [
//'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 {
$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-06-17 15:38:36 +02:00
setPreOrder ( $article -> IdArticolo , " 1 " , false );
2024-06-17 14:41:58 +02:00
$productLogger -> addLog ( 'pre_order' , ' SEtTATO IN PREVENDITA ! <br>' );
}
}
} catch ( \Exception $e ) {
2024-06-17 15:09:49 +02:00
$productLogger -> addLog ( 'server_issues' , $article -> IdArticolo . ' - ' . $article -> Titolo . " \n " );
2024-06-17 14:41:58 +02:00
}
}
2024-06-18 09:46:45 +02:00
function getArticoloById ( $idarticolo ) {
$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-06-17 14:41:58 +02:00
2024-06-17 15:09:49 +02:00
function updateArticoloFromGM ( $idarticolo )
{
2024-06-17 14:41:58 +02:00
$productLogger = new ProductLogger ( " " );
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 );
$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
}
}