2062 lines
79 KiB
PHP
2062 lines
79 KiB
PHP
<?php
|
|
|
|
use Carbon\Carbon;
|
|
use Codexshaper\WooCommerce\Facades\Product;
|
|
use Illuminate\Console\Command;
|
|
use App\Setting;
|
|
use App\Article;
|
|
use App\Clientegm;
|
|
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;
|
|
|
|
use App\Orderdetail;
|
|
use App\Services\ProductLogger;
|
|
use App\Order as AppOrder;
|
|
use App\OrderdetailWeb;
|
|
use App\OrderWeb as AppOrderWeb;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
use Illuminate\Support\Facades\Request;
|
|
|
|
|
|
define('QTA_IN_PREVENDITA', 10000);
|
|
define('QTA_MINIMA_PER_PREVENDITA', 9000);
|
|
|
|
setlocale(LC_TIME, 'it_IT.UTF-8');
|
|
|
|
function showarray($array)
|
|
{
|
|
echo '<pre>' . json_encode($array, JSON_PRETTY_PRINT) . '</pre>';
|
|
};
|
|
|
|
function getarraystr($array)
|
|
{
|
|
return '<pre>' . json_encode($array, JSON_PRETTY_PRINT) . '</pre>';
|
|
};
|
|
|
|
function isKeyPresent($array, $key)
|
|
{
|
|
foreach ($array as $item) {
|
|
if (isset($item->key) && $item->key === $key) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function getValueByKey($array, $key)
|
|
{
|
|
foreach ($array as $item) {
|
|
if (isset($item->key) && $item->key === $key) {
|
|
return $item->value;
|
|
}
|
|
}
|
|
return null; // If key is not found
|
|
}
|
|
|
|
// Funzione per aggiornare il valore di un certo key in un array di oggetti
|
|
function updateValueByKey(&$array, $key, $newValue)
|
|
{
|
|
foreach ($array as &$item) {
|
|
if (is_object($item) && property_exists($item, 'key') && $item->key === $key) {
|
|
$item->value = $newValue;
|
|
return; // Se trova il key, termina il loop
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
function updateValueByKeyArr(&$array, $key, $newValue)
|
|
{
|
|
foreach ($array as &$item) {
|
|
if ($item['key'] === $key) {
|
|
$item['value'] = $newValue;
|
|
break; // Se trova il key, termina il loop
|
|
}
|
|
}
|
|
|
|
$array[$key] = $newValue;
|
|
}
|
|
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
if ($debug) {
|
|
echo "Product: " . $sku;
|
|
showarray($product);
|
|
}
|
|
|
|
$campoPreOrder = '_wpro_variable_is_preorder';
|
|
|
|
if ($product) {
|
|
$titolo = $product['name'];
|
|
|
|
if ($debug)
|
|
echo "Prodotto trovato: " . $titolo . " StockQty = " . $product['stock_quantity'] . "<br>";
|
|
|
|
$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>";
|
|
}
|
|
|
|
$idprodotto = $product['parent_id'];
|
|
|
|
if ($aggiornapreordine === '1') {
|
|
$data = [];
|
|
|
|
$article = getArticoloById($sku);
|
|
|
|
echo $article->titolo . " DataPubblicazione: " . $article->DataPubblicazione . "<br>";
|
|
|
|
$datepubblstr = "";
|
|
$datepubbllabel = "";
|
|
$label_prenotalo_con_data = "";
|
|
|
|
if ($article->DataPubblicazione) {
|
|
$datepubbl = DateTime::createFromFormat('Y-m-d H:i:s.u', $article->DataPubblicazione);
|
|
|
|
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>";
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
$data['stock_quantity'] = QTA_IN_PREVENDITA;
|
|
|
|
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');
|
|
updateValueByKey($data['meta_data'], '_pre_order_date', $datepubblstr);
|
|
updateValueByKey($data['meta_data'], '_wpro_date_label_variable', $label_prenotalo_con_data);
|
|
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');
|
|
updateValueByKey($data['meta_data'], '_wpro_date_variable', $datepubblstr);
|
|
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);
|
|
|
|
if ($variation) {
|
|
if ($debug)
|
|
echo "Aggiornato Preorder: [ParentId=" . $idprodotto . '] ProdId= ' . $product['id'] . ' ' . $variation['name'] . "<br>";
|
|
}
|
|
}
|
|
} else if ($aggiornapreordine === '-1') {
|
|
|
|
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>";
|
|
}
|
|
}
|
|
} 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>";
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if ($debug)
|
|
echo "Il prodotto non esiste";
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "Errore: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
function isArticleInPrevendita($id, $checkqtanegativa)
|
|
{
|
|
return loadArticleByIdArticle($id, true);
|
|
}
|
|
|
|
|
|
function loadArticleByIdArticle($id, $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.IdArticolo', $id)
|
|
->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 di ' . $id . ' :' . PHP_EOL;
|
|
$ris .= getarraystr($articles); // Converte solo i dati specificati in JSON
|
|
|
|
try {
|
|
$product = Product::where('sku', $id)->first();
|
|
|
|
$ris .= 'Product:' . PHP_EOL;
|
|
$ris .= getarraystr($product);
|
|
} catch (\Exception $e) {
|
|
$ris .= "!!! Errore loadArticleByIdArticle Product: " . $e->getMessage();
|
|
}
|
|
|
|
return $ris;
|
|
} catch (\Exception $e) {
|
|
|
|
return "Errore loadArticleByIdArticle: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
function showTest()
|
|
{
|
|
$codarticolo = "16670";
|
|
|
|
$mystr = '*** TEST: codarticolo: ' . $codarticolo;
|
|
if ($codarticolo) {
|
|
try {
|
|
$product = Product::where('sku', $codarticolo)->first();
|
|
} catch (\Exception $e) {
|
|
return "Errore: " . $e->getMessage();
|
|
}
|
|
|
|
// $mystr .= getarraystr($product);
|
|
|
|
}
|
|
return $mystr;
|
|
|
|
}
|
|
function showOrdini()
|
|
{
|
|
$str = "";
|
|
|
|
|
|
try {
|
|
|
|
// $str = Schema::getColumnListing('Orderdetails');
|
|
|
|
$orders = Orderdetail::orderBy('DataOra', 'desc')
|
|
->take(5)
|
|
->get();
|
|
|
|
$sep = "";
|
|
|
|
// dd($orders);
|
|
|
|
$baseUrl = Request::root(); // URL di base (dominio)
|
|
|
|
// Show the fields of the orders
|
|
foreach ($orders as $order) {
|
|
$product = Product::where('sku', $order->CodArticoloGM)->first();
|
|
|
|
dd($product);
|
|
// $product = null;
|
|
|
|
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) . " ";
|
|
$str .= getvalstr("Cod Cliente", $order->CodClienteInternet, true);
|
|
$str .= getvalstr("Articolo", $order->CodArticoloGM, true);
|
|
$str .= getvalstr("IdSito", $order->IdSito, true);
|
|
$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);
|
|
|
|
$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;
|
|
|
|
// $str .= getarraystr($product) . "<br>";
|
|
// $str .= $product;
|
|
$str .= '<br>';
|
|
}
|
|
} catch (\Exception $e) {
|
|
return "Errore: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function showOrdiniWeb()
|
|
{
|
|
$str = "";
|
|
|
|
try {
|
|
|
|
// $str = Schema::getColumnListing('Orderdetails');
|
|
|
|
$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) {
|
|
$product = Product::where('sku', $order->CodArticoloGM)->first();
|
|
|
|
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) . " ";
|
|
$str .= getvalstr("Cod Cliente", $order->CodClienteInternet, true);
|
|
$str .= getvalstr("Articolo", $order->CodArticoloGM, true);
|
|
$str .= getvalstr("Prezzo", $order->PrezzoLordo);
|
|
$str .= getvalstr("IdSito", $order->IdSito, true);
|
|
$str .= getvalstr("Quantità", $order->Qta);
|
|
if ($order->PercSconto)
|
|
$str .= getvalstr("Sconto", $order->PercSconto);
|
|
if ($order->Descrizione)
|
|
$str .= getvalstr("Descr", $order->Descrizione);
|
|
|
|
// $str .= ' <a href="' . $baseUrl . '/setordine/' . $order->IdInternet . '/del/" target="_blank">ELIMINA!</a>' . $sep;
|
|
$str .= ' <a href="' . $baseUrl . '/setordine/' . $order->IdInternet . '/idsito/" target="_blank">IMPOSTA IDSITO FDV</a>' . $sep;
|
|
|
|
// $str .= getarraystr($product) . "<br>";
|
|
// $str .= $product;
|
|
$str .= '<br>';
|
|
}
|
|
} catch (\Exception $e) {
|
|
return "Errore: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function getStructTable($tableName)
|
|
{
|
|
$str = '';
|
|
|
|
$columns = Schema::getColumnListing($tableName);
|
|
|
|
$str .= '<br><span style="font-weight: bold;">Tabella: ' . $tableName . '</span><br>';
|
|
|
|
$str .= '<pre>';
|
|
|
|
// 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 = [];
|
|
foreach ($types as $type) {
|
|
$columnInfo[$type->column_name] = [
|
|
'data_type' => $type->data_type,
|
|
'length' => $type->character_maximum_length
|
|
];
|
|
}
|
|
|
|
// Stampa la struttura della tabella con i tipi di dati e lunghezza dei campi
|
|
foreach ($columns as $column) {
|
|
$str .= ' ' . $column . " - " . $columnInfo[$column]['data_type'] . " (" . $columnInfo[$column]['length'] . ")" . "<br>";
|
|
}
|
|
|
|
$str .= '</pre>';
|
|
|
|
return $str;
|
|
}
|
|
|
|
function getAllTables()
|
|
{
|
|
$tables = DB::select("SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE'");
|
|
|
|
$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) {
|
|
$str .= getStructTable($table) . '<br>';
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function setOrdine($idinternet, $mode)
|
|
{
|
|
try {
|
|
|
|
$str = "setOrdine: mode =" . $mode . ' idinternet=' . $idinternet;
|
|
|
|
// $str .= getAllTablesStr();
|
|
|
|
$str .= getStructTable('T_WOO_TestateOrdini');
|
|
|
|
$ordine = Orderdetail::where('IdInternet', $idinternet)->first();
|
|
|
|
$ordergm = AppOrder::where('IdInternet', $idinternet)->first();
|
|
|
|
if ($ordergm) {
|
|
$str .= getarraystr($ordergm) . "<br>";
|
|
// $ordergm = $ordergms[0];
|
|
// $str .= getarraystr($ordergm) . "<br>";
|
|
}
|
|
|
|
if ($ordine) {
|
|
|
|
if ($ordine)
|
|
$str .= getarraystr($ordine) . "<br>";
|
|
|
|
$prodotto = Product::where('sku', $ordine["CodArticoloGM"])->first();
|
|
|
|
if ($prodotto)
|
|
$str .= getarraystr($prodotto) . "<br>";
|
|
|
|
if ($mode === 'del' && $ordine) {
|
|
$str .= "... Cancellazione in CORSO ...";
|
|
// delete record $ordine
|
|
$deletedCount = Orderdetail::where('IdInternet', $idinternet)->delete();
|
|
$str .= "<br><span style='color: red;'>Numero di record eliminati: " . $deletedCount . "</span>";
|
|
}
|
|
if ($mode === 'idsito' && $ordine) {
|
|
$str .= "... CAMBIA ID SITO ...";
|
|
|
|
// Update field IdSito to "7"
|
|
$updatedCount = Orderdetail::where('IdInternet', $idinternet)
|
|
->update([
|
|
'IdSito' => "7"
|
|
]);
|
|
|
|
$str .= "<br><span style='color: red;'>record Aggiornati: " . $updatedCount . "</span>";
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
$str .= "Errore: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function showRecordOrder($orders)
|
|
{
|
|
|
|
try {
|
|
$str = '';
|
|
|
|
// Show the fields of the orders
|
|
foreach ($orders as $order) {
|
|
$str .= getvalstr("IdInternet", $order->IdInternet, true) . " ";
|
|
$str .= getvalstr("CodCliente", $order->CodClienteInternet, true);
|
|
$str .= getvalstr("IdSito", $order->IdSito, true);
|
|
$str .= getvalstr("Note", $order->Note, true);
|
|
$str .= getvalstr("Totale", $order->Totale, true);
|
|
$str .= getvalstr("DataOra", $order->DataOra, true);
|
|
$str .= getvalstr("DataSpedizione", $order->DataSpedizione, true);
|
|
$str .= '<br>';
|
|
}
|
|
} 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');
|
|
|
|
$str .= showRecordOrder($orders);
|
|
} catch (\Exception $e) {
|
|
return "Errore showDettOrdini: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function showDettSingleOrdine($idordine)
|
|
{
|
|
$str = "Ordini Woocommerce:" . PHP_EOL . '<br>';
|
|
|
|
try {
|
|
// sort DataOra desc
|
|
$orders = AppOrder::where('IdInternet', $idordine)->get();
|
|
|
|
$str .= showRecordOrder($orders);
|
|
} 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');
|
|
|
|
$str .= showRecordOrder($orders);
|
|
} catch (\Exception $e) {
|
|
return "Errore showDettOrdini: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function showDettSingleOrdineWeb($idordine)
|
|
{
|
|
try {
|
|
|
|
$str = "Ordini T_WEB_TestateOrdini:" . PHP_EOL . '<br>';
|
|
|
|
$orders = AppOrderWeb::where('IdInternet', $idordine)->get();
|
|
|
|
$str .= showRecordOrder($orders);
|
|
} catch (\Exception $e) {
|
|
return "Errore showDettOrdini: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function showprice($prezzo)
|
|
{
|
|
return ' € ' . number_format($prezzo, 2);
|
|
}
|
|
|
|
function libriInPrevendita()
|
|
{
|
|
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 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');
|
|
})
|
|
|
|
->where('DescrizioneStatoProdotto', 'In prevendita')
|
|
->where(DB::raw('CONVERT(INT, QtaDisponibile)'), '<', 0)
|
|
// ->where('DescrizioneFormato', 'brossura')
|
|
// ->where('DescrizioneTipologia', 'Libri')
|
|
->where(DB::raw('DATEDIFF(day, \'1970-01-01\', DataPubblicazione)'), '>', 1)
|
|
->orderBy('DataPubblicazione', 'desc')
|
|
->get();
|
|
$sep = ' | ';
|
|
|
|
$ind = 1;
|
|
foreach ($articles as $article) {
|
|
// $titolo = rtrim(str_ireplace('USATO', '', $article->Titolo));
|
|
|
|
$mydatestr = $article->DataPubblicazione;
|
|
|
|
$sku = $article->IdArticolo;
|
|
|
|
$prodotto = Product::where('sku', $sku)->first();
|
|
|
|
$qtyinstock = intval($prodotto['stock_quantity']);
|
|
$prezzo = $prodotto['sale_price'];
|
|
if (!$prezzo) {
|
|
$prezzo = $prodotto['price'];
|
|
}
|
|
|
|
if ($qtyinstock <= 0) {
|
|
$colore = 'red';
|
|
} else {
|
|
$colore = 'green';
|
|
}
|
|
|
|
|
|
// echo '[' . $ind . ']' . $sep . $mydatestr . $sep . $article->IdArticolo . $sep . $article->Titolo . $sep . $article->DescrizioneStatoProdotto . $sep . $article->DescrizioneFormato . ' [Quantita = ' . $article->QtaDisponibile . ']';
|
|
$myview = '[' . $ind . ']' . $sep .
|
|
'<a href="' . $article->permalink . '?id=' . $article->IdArticolo . '" target="_blank">' . $article->IdArticolo . '</a>' . $sep .
|
|
'<a href="' . $prodotto['permalink'] . '" target="_blank"><span style="color:' . $colore . '; font-weight: bold;"> ' . $article->Titolo . '</span></a>' . $sep .
|
|
' Pubb:' . formatDateToItalian($article->DataPubblicazione) . $sep .
|
|
$article->DescrizioneStatoProdotto . ' (' . $article->DescrizioneFormato . ')' . $sep .
|
|
'[Qta = <span style="">' . $article->QtaDisponibile . '</span>]' . $sep .
|
|
' [' . showprice($prezzo) . ' ]' . $sep .
|
|
'[In Stock = <span style="color:' . $colore . '; font-weight: bold;">' . $qtyinstock . '</span>]' . $sep;
|
|
|
|
if ($qtyinstock < QTA_MINIMA_PER_PREVENDITA) {
|
|
$myview .= '<a href="' . $article->permalink . '/apimacro/public/aggiornapreorder/' . $article->IdArticolo . '/1/" target="_blank">Imposta in PRE-ORDINE!</a>' . $sep;
|
|
} else {
|
|
$myview .= '<a href="' . $article->permalink . '/apimacro/public/aggiornapreorder/' . $article->IdArticolo . '/-1/" target="_blank">Impostalo Non Disponibile</a>' . $sep;
|
|
}
|
|
$myview .= '<a href="' . $article->permalink . '/apimacro/public/aggiornadatapubblicazione/' . $article->IdArticolo . '/" target="_blank">Aggiorna Data Pubb</a>' . $sep;
|
|
|
|
echo $myview;
|
|
|
|
if ($prodotto) {
|
|
|
|
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>';
|
|
}
|
|
|
|
$ind++;
|
|
}
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
|
|
{
|
|
if ($initlog) {
|
|
$productLogger = new ProductLogger(null, '');
|
|
} else {
|
|
$productLogger = $passproductLogger;
|
|
}
|
|
|
|
$preorder = true;
|
|
|
|
try {
|
|
$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;
|
|
echo $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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$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');
|
|
}
|
|
|
|
$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
|
|
],
|
|
[
|
|
'key' => 'DataPubblicazione',
|
|
'value' => $datepubbl_ts
|
|
],
|
|
[
|
|
'key' => 'DataPubbStr',
|
|
'value' => $datepubblstr
|
|
],
|
|
|
|
]
|
|
];
|
|
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) {
|
|
setPreOrder($article->IdArticolo, "1", false);
|
|
$productLogger->addLog('pre_order', $article->titolo . ' [' . $article->IdArticolo . '] Impostato IN PREVENDITA !' . "\n");
|
|
} else {
|
|
setPreOrder($article->IdArticolo, "0", false);
|
|
$productLogger->addLog('mettilo in Vendita (no pre-order)', $article->titolo . ' [' . $article->IdArticolo . '] Impostato IN VENDITA !' . "\n");
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
$productLogger->addLog('server_issues', $article->IdArticolo . ' - ' . $article->Titolo . "\n");
|
|
$productLogger->setAggiornato(true);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
function updateArticoloFromGM($idarticolo)
|
|
{
|
|
$productLogger = new ProductLogger(null, '');
|
|
|
|
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 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;
|
|
}
|
|
|
|
if ($article) {
|
|
$str = "Articolo: ";
|
|
$str .= getarraystr($article);
|
|
|
|
$str .= "setProductFromGM: ";
|
|
setProductFromGM($article, false, $productLogger);
|
|
|
|
|
|
$str .= $productLogger->concatenateLogs();
|
|
|
|
return $str;
|
|
} else {
|
|
return "Articolo non trovato";
|
|
}
|
|
} catch (\Exception $e) {
|
|
return "Errore updateArticoloFromGM: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
function getClienteByIdInternet_Ordine($idInternet)
|
|
{
|
|
|
|
try {
|
|
$clienteinGM = Clientegm::where('IdInternet', $idInternet)->first();
|
|
} catch (\Exception $e) {
|
|
return null;
|
|
}
|
|
|
|
return $clienteinGM;
|
|
}
|
|
|
|
function getClienteByIdCodClienteInternet($codClienteInternet)
|
|
{
|
|
|
|
try {
|
|
$clienteinGM = Clientegm::where('codClienteInternet', $codClienteInternet)->first();
|
|
} catch (\Exception $e) {
|
|
return null;
|
|
}
|
|
|
|
return $clienteinGM;
|
|
}
|
|
|
|
function getOrderByIdInternet($idInternet)
|
|
{
|
|
|
|
try {
|
|
$ordergm = Orderdetail::where('IdInternet', $idInternet)->first();
|
|
|
|
return $ordergm;
|
|
} catch (\Exception $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function getClienti()
|
|
{
|
|
try {
|
|
$clienti = Clientegm::all();
|
|
|
|
dd($clienti);
|
|
} catch (\Exception $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function getvalstr($mystr, $value, $separato = false)
|
|
{
|
|
$my = '';
|
|
if ($mystr) {
|
|
$my = " " . $mystr . ": " . $value;
|
|
} else {
|
|
$my = $value;
|
|
if (!$separato) {
|
|
$my = " " . $value;
|
|
}
|
|
}
|
|
|
|
if ($separato) {
|
|
$my = '[' . $my . '] ';
|
|
}
|
|
|
|
return $my;
|
|
}
|
|
|