This commit is contained in:
paoloar77
2024-12-19 15:15:06 +01:00
parent 1554f7845c
commit cadd052cb0

View File

@@ -1154,23 +1154,31 @@ function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
$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;
try {
if (!is_null($prodotti) && $prodotti->count() > 0) {
echo "... cicla prodotti ...";
foreach ($prodotti as $prodotto) {
if (strtolower($prodotto->name) === strtolower($titolo)) {
$found_key = array_search('Autore libro', array_column($prodotto->attributes, 'name'));
if (array_diff($prodotto->attributes[$found_key]->options, $article->authors) === array_diff($article->authors, $prodotto->attributes[$found_key]->options)) {
$id = $prodotto->id;
$variations = Variation::all($prodotto->id);
foreach ($variations as $variation) {
$found_key_version = array_search('Versione', array_column($variation->attributes, 'name'));
if ($variation->attributes[$found_key_version]->option == 'Nuovo') {
$id = 0;
}
}
}
}
}
}
} catch (\Exception $e) {
$productLogger->addLog('server_issues', $article->IdArticolo . ' - ' . $article->Titolo . "\n" . $e->getMessage() . "\n");
echo "Errore: " . $e->getMessage();
}
$datepubbl = DateTime::createFromFormat('Y-m-d H:i:s.u', $article->DataPubblicazione);
$datepubbl_ts = "";
@@ -1236,6 +1244,8 @@ function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
]
];
echo "... compila i campi...";
if ($id == 0) {
$versione = 'Nuova versione';
$category = Category::where('name', $article->argomento);
@@ -1328,10 +1338,14 @@ function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
];
echo "... crea prodotto..." . $data;
$product = Product::create($data);
$idprodotto = $product['id'];
echo "... crea vaziazione";
$variation = Variation::create($idprodotto, $data1);
//dd($variation);
@@ -2081,6 +2095,8 @@ function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
} else {
// ESISTE GIA' IL LIBRO
echo "Esiste già il libro...";
$data1 = [
'regular_price' => $article->PrezzoIvato,
@@ -2103,13 +2119,17 @@ function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
// Controlla se è in preordine
$inprevendita = isArticleInPrevendita($article->IdArticolo, true);
if ($inprevendita) {
echo "...imposta in prevendita !";
setPreOrder($article->IdArticolo, "1", false);
$productLogger->addLog('pre_order', $article->titolo . ' [' . $article->IdArticolo . '] Impostato IN PREVENDITA !' . "\n");
} else {
echo "...disabilita la prevendita !";
setPreOrder($article->IdArticolo, "0", false);
$productLogger->addLog('mettilo in Vendita (no pre-order)', $article->titolo . ' [' . $article->IdArticolo . '] Impostato IN VENDITA !' . "\n");
}
}
echo " ...FINE !";
} catch (\Exception $e) {
$productLogger->addLog('server_issues', $article->IdArticolo . ' - ' . $article->Titolo . "\n" . $e->getMessage() . "\n");
$productLogger->setAggiornato(true);