1409 lines
56 KiB
PHP
1409 lines
56 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
use App\Orderdetail;
|
|
use App\Services\ProductLogger;
|
|
use Codexshaper\WooCommerce\Facades\Order;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
define('QTA_IN_PREVENDITA', 10000);
|
|
|
|
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 setPreOrderByIdArticolo($idarticolo, $aggiornapreordine, $debug)
|
|
{
|
|
return setPreOrder($idarticolo, $aggiornapreordine, $debug);
|
|
}
|
|
|
|
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>";
|
|
}
|
|
|
|
if ($aggiornapreordine === '1') {
|
|
$data = [];
|
|
|
|
$datenow = date('Y-m-d');
|
|
|
|
$idprodotto = $product['parent_id'];
|
|
if ($idprodotto > 0) {
|
|
|
|
if ($debug)
|
|
echo "Variazioni: " . $product['parent_id'] . "<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', $datenow);
|
|
updateValueByKey($data['meta_data'], '_wpro_date_label_variable', '');
|
|
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', '');
|
|
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 ($debug)
|
|
echo "Il prodotto non esiste";
|
|
}
|
|
} 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 showOrdini()
|
|
{
|
|
$str = "";
|
|
|
|
|
|
try {
|
|
|
|
// $str = Schema::getColumnListing('Orderdetails');
|
|
|
|
$orders = Orderdetail::orderBy('DataOra', 'desc')
|
|
->take(20)
|
|
->get();
|
|
|
|
// Show the fields of the orders
|
|
foreach ($orders as $order) {
|
|
// $product = Product::where('sku', $order->CodArticoloGM)->first();
|
|
|
|
$str .= getvalstr("", $order->Codice) . " ";
|
|
$str .= getvalstr("", $order->DataOra);
|
|
$str .= getvalstr("IdInternet", $order->IdInternet, true) . " ";
|
|
$str .= getvalstr("", $order->CodArticoloGM, true);
|
|
$str .= getvalstr("Qta", $order->Qta);
|
|
$str .= getvalstr("Prezzo", $order->PrezzoLordo);
|
|
if ($order->PercSconto)
|
|
$str .= getvalstr("Sconto", $order->PercSconto);
|
|
if ($order->Descrizione)
|
|
$str .= getvalstr("Descr", $order->Descrizione);
|
|
|
|
//$str .= $product;
|
|
// $str .= $product;
|
|
$str .= '<br>';
|
|
}
|
|
} catch (\Exception $e) {
|
|
return "Errore: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
function showDettOrdini()
|
|
{
|
|
$str = "Ordini Woocommerce:" . PHP_EOL;
|
|
|
|
try {
|
|
$orders = Order::all();
|
|
|
|
// Show the fields of the orders
|
|
foreach ($orders as $order) {
|
|
$str .= "Ordine: ";
|
|
$str .= getvalstr("Id", $order->id);
|
|
//$str .= getvalstr("DataOra", $order->DataOra);
|
|
//$str .= getvalstr("Totale", $order->Totale);
|
|
}
|
|
} catch (\Exception $e) {
|
|
return "Errore showDettOrdini: " . $e->getMessage();
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
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']);
|
|
|
|
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 .
|
|
' Data Pubblicazione:' . date('d-m-Y', strtotime($article->DataPubblicazione)) . $sep .
|
|
$article->DescrizioneStatoProdotto . ' (' . $article->DescrizioneFormato . ')' . $sep .
|
|
'[Qta = <span style="">' . $article->QtaDisponibile . '</span>]' . $sep .
|
|
'[In Stock = <span style="color:' . $colore . '; font-weight: bold;">' . $qtyinstock . '</span>]' . $sep;
|
|
|
|
if ($qtyinstock < 0) {
|
|
$myview .= '<a href="' . $article->permalink . '/apimacro/public/aggiornapreorder/' . $article->IdArticolo . '/1/" target="_blank">Imposta in PRE-ORDINE!</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);
|
|
$productLogger->init();
|
|
} 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;
|
|
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) {
|
|
setPreOrder($article->IdArticolo, true, false);
|
|
$productLogger->addLog('pre_order', ' SEtTATO IN PREVENDITA ! <br>');
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
$productLogger->addLog('server_issues', $article->IdArticolo . ' - ' . $article->Titolo . "\n");
|
|
}
|
|
}
|
|
|
|
|
|
function updateArticoloFromGM($idarticolo)
|
|
{
|
|
$productLogger = new ProductLogger("");
|
|
|
|
$articles = Article::where('IdArticolo', $idarticolo)
|
|
->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.IdArgomento, g.Descrizione as DescrizioneArgomentoProdotto FROM T_WEB_Argomenti g JOIN (SELECT IdArgomento, MAX(DataOra) as data1 from T_WEB_Argomenti GROUP BY IdArgomento) h ON g.IdArgomento = h.IdArgomento AND g.DataOra = h.data1 ) i'), function ($join) {
|
|
$join->on('T_WEB_Articoli.ListaArgomenti', '=', 'i.IdArgomento');
|
|
})
|
|
|
|
->orderBy('dataOra', 'desc')
|
|
->get();
|
|
|
|
if ($articles->count() > 0) {
|
|
$article = $articles[0];
|
|
} else {
|
|
$article = null;
|
|
}
|
|
|
|
if ($article) {
|
|
setProductFromGM($article, false, $productLogger);
|
|
|
|
$str = "Concatena: ";
|
|
$str .= getarraystr($article);
|
|
|
|
$str .= $productLogger->concatenateLogs();
|
|
|
|
return $str;
|
|
} else {
|
|
return "Articolo non trovato";
|
|
}
|
|
|
|
}
|