diff --git a/app/Console/Commands/ProductUpdateGm.php b/app/Console/Commands/ProductUpdateGm.php
index e4785fe3..3367e428 100644
--- a/app/Console/Commands/ProductUpdateGm.php
+++ b/app/Console/Commands/ProductUpdateGm.php
@@ -11,10 +11,8 @@ use App\Mylog;
use Codexshaper\WooCommerce\Models\Product as ModelsProduct;
use Codexshaper\WooCommerce\Facades\Variation;
use Codexshaper\WooCommerce\Facades\Category;
-use Illuminate\Support\Facades\Log;
-use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\DB;
-
+use App\Services\ProductLogger;
class ProductUpdateGm extends Command
{
@@ -50,10 +48,8 @@ class ProductUpdateGm extends Command
public function handle()
{
- $aggiornato = false;
set_time_limit(0);
ini_set("memory_limit", "512M");
- $ora_update = Carbon::now();
$settingora = Setting::where('key', 'update_products')->first();
$fromtime = str_replace('-', '', $settingora->value);
@@ -87,983 +83,13 @@ class ProductUpdateGm extends Command
->orderBy('Titolo')
->get();
-
- Log::channel('updateproducts')->notice('Inizio da ' . $settingora->value . "\n");
- $loginizio = 'Inizio da ' . $settingora->value . "\n";
- $logfine = 'Fino a ' . $ora_update . "\n";
- $log = ' PRODOTTI INSERITI' . "\n";
- $log1 = 'EVENTUALI PRODOTTI NON INSERITI' . "\n";
- $log2 = 'PRODOTTI AGGIORNATI' . "\n";
- $log3 = 'PRODOTTI NON INSERITI PER PROBLEMI SERVER' . "\n";
- $log4 = 'PRODOTTI IN PREVENDITA' . "\n";
-
- $preorder = true;
+ $productLogger = new ProductLogger($settingora->value);
foreach ($articles as $article) {
- 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);
- }
- $log .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . ' - ' . $versione . ' - ' . $variation['permalink'] . "\n";
- $aggiornato = 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 {
- $log1 .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . "\n";
- $aggiornato = 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);
- }
-
- $log .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . ' - ' . $versione . ' - ' . $variation['permalink'] . "\n";
- $aggiornato = 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);
- }
-
- $log .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . ' - ' . $versione . ' - ' . $variation['permalink'] . "\n";
- $aggiornato = 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 {
- $log1 .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . "\n";
- $aggiornato = 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);
- }
- $log .= $article->Titolo . ' - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . ' - ' . $versione . ' - ' . $variation['permalink'] . "\n";
- $aggiornato = 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);
-
- $log2 .= $article->Titolo . ' - [Quantità: ' . $data1['stock_quantity'] . '] - ' . $article->DescrizioneTipologia . ' - ' . $article->DescrizioneFormato . ' - Articolo aggiornato - ' . $variation['permalink'] . "\n";
- $aggiornato = true;
- }
- }
-
- if ($preorder) {
- // Controlla se è in preordine
- $inprevendita = isArticleInPrevendita($article->IdArticolo, true);
- if ($inprevendita) {
- setPreOrder($article->IdArticolo, true, false);
- $log4 .= ' SEtTATO IN PREVENDITA !
';
- }
- }
-
- } catch (\Exception $e) {
- $log3 .= $article->IdArticolo . ' - ' . $article->Titolo . "\n";
- }
- }
- $settingora->value = $ora_update;
- $settingora->save();
- if ($aggiornato) {
- Log::channel('updateproducts')->notice($log . $log2 . $log1 . $log3 . $log4);
- Log::channel('updateproducts')->notice('Fino a ' . $ora_update . "\n");
- Mail::raw($loginizio . $log . $log2 . $log1 . $log3 . $log4 . $logfine, function ($message) {
- $message->to(Mylog::getEmail());
- $message->subject(Mylog::getSubjectEmail("Inserim. nuovi prodotti"));
- });
+ setProductFromGM($article, true, $productLogger);
}
+
+ $productLogger->setLogandSendEmail();
+
}
}
diff --git a/app/CustomFuncPao.php b/app/CustomFuncPao.php
index 68b34e77..a86973d7 100644
--- a/app/CustomFuncPao.php
+++ b/app/CustomFuncPao.php
@@ -15,6 +15,7 @@ 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;
@@ -402,3 +403,993 @@ function libriInPrevendita()
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 !
');
+ }
+ }
+ } 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();
+
+ foreach ($articles as $article) {
+ setProductFromGM($article, false, $productLogger);
+ }
+
+ $productLogger->setLogandSendEmail();
+
+
+}
\ No newline at end of file
diff --git a/app/Services/ProductLogger.php b/app/Services/ProductLogger.php
new file mode 100644
index 00000000..c3facc72
--- /dev/null
+++ b/app/Services/ProductLogger.php
@@ -0,0 +1,88 @@
+settingOra = $settingOraValue;
+ }
+
+ public function init()
+ {
+ $oraUpdate = Carbon::now();
+ $this->logs['start'] = 'Inizio da ' . $this->settingOra . "\n";
+ $this->logs['end'] = 'Fino a ' . $oraUpdate->toDateTimeString() . "\n";
+ $this->logs['inserted'] = 'PRODOTTI INSERITI' . "\n";
+ $this->logs['not_inserted'] = 'EVENTUALI PRODOTTI NON INSERITI' . "\n";
+ $this->logs['updated'] = 'PRODOTTI AGGIORNATI' . "\n";
+ $this->logs['server_issues'] = 'PRODOTTI NON INSERITI PER PROBLEMI SERVER' . "\n";
+ $this->logs['pre_order'] = 'PRODOTTI IN PREVENDITA' . "\n";
+ $this->logs['custom'] = ""; // for custom log messages
+ }
+
+ public function updateSettingOra($newOra)
+ {
+ $this->settingOra = $newOra;
+ }
+
+ public function setLogandSendEmail() {
+ $ora_update = Carbon::now();
+
+ if ($this->settingOra) {
+ $this->settingOra->value = $ora_update;
+ $this->settingOra->save();
+ }
+ if ($this->aggiornato) {
+ Log::channel('updateproducts')->notice($this->concatenateLogs());
+ Mail::raw($this->concatenateLogs(), function ($message) {
+ $titolo = "Inserim. nuovi prodotti";
+ if (!$this->settingOra) {
+ $titolo = "Inserim. prodotto:";
+ }
+ $message->to(Mylog::getEmail());
+ $message->subject(Mylog::getSubjectEmail($titolo));
+ });
+ }
+
+ }
+
+ public function addLog($type, $message)
+ {
+ if (isset($this->logs[$type])) {
+ $this->logs[$type] .= $message . "\n";
+ }
+ }
+
+ public function getLogs()
+ {
+ return $this->logs;
+ }
+
+ public function concatenateLogs()
+ {
+ return implode("", $this->logs);
+ }
+
+ public function setAggiornato($aggiornato) {
+ $this->aggiornato = $aggiornato;
+ }
+
+ public function getAggiornato() {
+ return $this->aggiornato;
+ }
+}
+
diff --git a/resources/views/mylinkspao.blade.php b/resources/views/mylinkspao.blade.php
index 5d74a94f..e79afabc 100644
--- a/resources/views/mylinkspao.blade.php
+++ b/resources/views/mylinkspao.blade.php
@@ -46,6 +46,7 @@
+
diff --git a/routes/web.php b/routes/web.php
index 3d364f5b..6ef49d99 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -6185,6 +6185,8 @@ Route::get('/handle-article-action-pao/{id}/{action}', function ($id, $action) {
if ($action == 'search') {
// Logica di ricerca dell'articolo
return loadArticleByIdArticle($id);
+ } elseif ($action == 'updateArtFromGM') {
+ return updateArticoloFromGM($id);
} elseif ($action == 'inprevendita') {
return libriInPrevendita();
} elseif ($action == 'showOrdini') {