- corretto gruppomacro catalogo, info prodotti, estrazione dati da amazon corretto.
This commit is contained in:
@@ -277,7 +277,7 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
if (item.order.idProduct) {
|
if (item.order.idProduct) {
|
||||||
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : { ...item.order.idProduct.idProductInfo };
|
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : { ...item.order.idProduct.idProductInfo };
|
||||||
item.order.idProduct.productInfo.unitstr = tools.getUnitsMeasure(item.order.idProduct.productInfo.unit, true);
|
item.order.idProduct.productInfo.unitstr = tools.getUnitsMeasure(item.order.idProduct.productInfo.unit, true);
|
||||||
item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
|
// item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
|
||||||
}
|
}
|
||||||
const myid = item.order._id;
|
const myid = item.order._id;
|
||||||
// console.log('ID ORD', order.numorder, myid, order.user.name);
|
// console.log('ID ORD', order.numorder, myid, order.user.name);
|
||||||
|
|||||||
@@ -293,7 +293,6 @@ const productSchema = new Schema({
|
|||||||
],
|
],
|
||||||
price_acquistato: {
|
price_acquistato: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
|
||||||
},
|
},
|
||||||
after_price: {
|
after_price: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -1379,15 +1378,13 @@ module.exports.resetImageNotFound = async function () {
|
|||||||
module.exports.removeProductInfoWithoutDateUpdatedFromGM = async function (idapp) {
|
module.exports.removeProductInfoWithoutDateUpdatedFromGM = async function (idapp) {
|
||||||
const Product = this;
|
const Product = this;
|
||||||
|
|
||||||
const globalTables = require('../tools/globalTables');
|
|
||||||
|
|
||||||
let mylog;
|
let mylog;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const arrproduct = await Product.find({ idapp, 'productInfo.date_updated_fromGM': { $exists: false } });
|
const arrproduct = await Product.find({ idapp, 'productInfo.date_updated_fromGM': { $exists: false } });
|
||||||
|
|
||||||
if (arrproduct.length > 0 && arrproduct.length < 1000) {
|
if (arrproduct.length > 0 && arrproduct.length < 1000) {
|
||||||
mylog = `Rimuovo ${arrproduct.length} productInfo senza date_updated_fromGM !!`
|
mylog = `Rimuovo ${arrproduct.length} product senza date_updated_fromGM !!`
|
||||||
console.log(mylog);
|
console.log(mylog);
|
||||||
|
|
||||||
for (const product of arrproduct) {
|
for (const product of arrproduct) {
|
||||||
@@ -1406,3 +1403,31 @@ module.exports.removeProductInfoWithoutDateUpdatedFromGM = async function (idapp
|
|||||||
|
|
||||||
return mylog;
|
return mylog;
|
||||||
};
|
};
|
||||||
|
module.exports.HideProductInfoWithoutDateUpdatedFromGM = async function (idapp) {
|
||||||
|
const Product = this;
|
||||||
|
|
||||||
|
let mylog;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const arrproduct = await Product.find({ idapp, 'productInfo.date_updated_fromGM': { $exists: false } });
|
||||||
|
|
||||||
|
if (arrproduct.length > 0 && arrproduct.length < 1000) {
|
||||||
|
mylog = `Nascondo ${arrproduct.length} product senza date_updated_fromGM !!`
|
||||||
|
console.log(mylog);
|
||||||
|
|
||||||
|
for (const product of arrproduct) {
|
||||||
|
await Product.updateOne(
|
||||||
|
{ _id: product._id },
|
||||||
|
{ $unset: { date_updated_fromGM: true } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mylog;
|
||||||
|
} catch (error) {
|
||||||
|
mylog += 'Error Hide productInfo without date_updated_fromGM:' + error;
|
||||||
|
console.error(mylog);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mylog;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
|
const Product = require('./product');
|
||||||
|
|
||||||
// Definizione dello schema
|
// Definizione dello schema
|
||||||
const articoliFatturatiSchema = new mongoose.Schema({
|
const articoliFatturatiSchema = new mongoose.Schema({
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ PrimaCopiaDaSpedire - int ()
|
|||||||
|
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
|
const Product = require('./product');
|
||||||
|
|
||||||
// Definizione dello schema
|
// Definizione dello schema
|
||||||
const ordiniSchema = new mongoose.Schema({
|
const ordiniSchema = new mongoose.Schema({
|
||||||
Codice: {
|
Codice: {
|
||||||
|
|||||||
@@ -443,11 +443,8 @@ class Macro {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
if (Array.isArray(recproducts)) {
|
if (Array.isArray(recproducts)) {
|
||||||
if (recproducts.length > 10 && lavoromassivo && options.rimuovieventualiCancellati) {
|
if (recproducts.length > 10 && lavoromassivo && options.rimuovieventualiCancellati) {
|
||||||
// disattiva dalla tabella productInfo tutti i campi date_updated_fromGM
|
// disattiva dalla tabella product tutti i campi date_updated_fromGM
|
||||||
const result = await Product.updateMany(
|
const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
|
||||||
{ idapp: options.idapp },
|
|
||||||
{ $unset: { 'productInfo.date_updated_fromGM': null } }
|
|
||||||
);
|
|
||||||
let quanti_rimossi = result.modifiedCount;
|
let quanti_rimossi = result.modifiedCount;
|
||||||
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||||
rimuoviTabellePerIniziare = true;
|
rimuoviTabellePerIniziare = true;
|
||||||
@@ -476,7 +473,7 @@ class Macro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const recproduct of recproducts) {
|
for (const recproduct of recproducts) {
|
||||||
await this.elaboraProdotto(recproduct, opt);
|
await this.elaboraProdotto(recproduct, opt, recproducts.length === 1);
|
||||||
|
|
||||||
const sku = recproduct.IdArticolo;
|
const sku = recproduct.IdArticolo;
|
||||||
|
|
||||||
@@ -496,7 +493,7 @@ class Macro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rimuoviTabellePerIniziare && options.rimuovieventualiCancellati) {
|
if (rimuoviTabellePerIniziare && options.rimuovieventualiCancellati) {
|
||||||
await ProductInfo.removeProductInfoWithoutDateUpdatedFromGM(options.idapp);
|
await Product.HideProductInfoWithoutDateUpdatedFromGM(options.idapp);
|
||||||
}
|
}
|
||||||
if (myjob) await myjob.terminateJob();
|
if (myjob) await myjob.terminateJob();
|
||||||
}
|
}
|
||||||
@@ -621,55 +618,87 @@ class Macro {
|
|||||||
/**
|
/**
|
||||||
* Elabora un singolo prodotto.
|
* Elabora un singolo prodotto.
|
||||||
*/
|
*/
|
||||||
async elaboraProdotto(productInput, options) {
|
async elaboraProdotto(productInput, options, forzacaricamento = false) {
|
||||||
let isnuovo = false,
|
let isnuovo = false,
|
||||||
setta = false,
|
setta = false,
|
||||||
importa = true;
|
importa = true;
|
||||||
|
|
||||||
let product = { ...productInput, deleted: false };
|
let product = { ...productInput, deleted: false };
|
||||||
|
|
||||||
if (options.inputdaGM) product = await this.convertiDaCampiGMACampoFDV_ProductInfo(options.idapp, product);
|
try {
|
||||||
|
if (options.inputdaGM) product = await this.convertiDaCampiGMACampoFDV_ProductInfo(options.idapp, product);
|
||||||
|
|
||||||
if (!product.title || !product.sku) importa = false;
|
if (!product.title || !product.sku) importa = false;
|
||||||
|
|
||||||
if (importa) {
|
if (importa) {
|
||||||
product.productInfo = this.preparaProductInfo(product);
|
if (this.localoptions?.importadaFDV) {
|
||||||
|
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
|
||||||
|
if (recrankingisbn) {
|
||||||
|
this.aggiornaCampiDaIsbn(product, recrankingisbn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.localoptions?.importadaFDV) {
|
if (!product.hasOwnProperty('active')) {
|
||||||
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
|
product.active = true;
|
||||||
if (recrankingisbn) {
|
}
|
||||||
this.aggiornaCampiDaIsbn(product, recrankingisbn);
|
|
||||||
|
//Aggiorna il campo product
|
||||||
|
let risprod = await Product.findOneAndUpdate(
|
||||||
|
{ isbn: product.isbn },
|
||||||
|
{ $set: product },
|
||||||
|
{ new: true, upsert: false, returnOriginal: false }
|
||||||
|
).lean();
|
||||||
|
|
||||||
|
product.productInfo = this.preparaProductInfo(product);
|
||||||
|
await this.gestisciCategorie(product);
|
||||||
|
await this.gestisciAutori(product);
|
||||||
|
await this.gestisciEditore(product);
|
||||||
|
await this.gestisciCollana(product);
|
||||||
|
|
||||||
|
// Se non lo trovo allora lo salvo come nuovo.
|
||||||
|
const dataFutura = new Date(product.productInfo.date_pub) > new Date(); // è da pubblicare ?
|
||||||
|
if (!risprod && (forzacaricamento || product.stockQty > 0 || dataFutura)) {
|
||||||
|
await Product.create(product);
|
||||||
|
risprod = await Product.findOne({ isbn: product.isbn }).lean();
|
||||||
|
} else {
|
||||||
|
risprod = await Product.findOne({ isbn: product.isbn }).lean();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (risprod) {
|
||||||
|
this.queryprod = { _id: risprod._id };
|
||||||
|
|
||||||
|
await this.gestisciGasOrdine(product);
|
||||||
|
await this.gestisciVariazioni(product, options);
|
||||||
|
|
||||||
|
|
||||||
|
const imagefile = await this.aggiornaImmagineSeNecessario(risprod, forzacaricamento || dataFutura);
|
||||||
|
if (imagefile) {
|
||||||
|
product.productInfo.imagefile = imagefile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// aggiorna productInfo
|
||||||
|
let risprodInfo = await Product.findOneAndUpdate(
|
||||||
|
{ isbn: product.isbn },
|
||||||
|
{ $set: { productInfo: product.productInfo } },
|
||||||
|
{ new: true, upsert: false, returnOriginal: false }
|
||||||
|
).lean();
|
||||||
|
|
||||||
|
// prodotto risprodInfo trovato ?
|
||||||
|
if (risprodInfo) {
|
||||||
|
// console.log('Prodotto trovato:', product.productInfo.name, product.productInfo.code);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
'Prodotto non trovato:',
|
||||||
|
product.productInfo.name,
|
||||||
|
product.productInfo.code + 'qta=' + product.stockQty
|
||||||
|
);
|
||||||
|
options.errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
if (!product.hasOwnProperty('active')) {
|
console.error('Errore nel gestire il prodotto:', e);
|
||||||
product.active = true;
|
options.errors++;
|
||||||
}
|
|
||||||
|
|
||||||
await this.gestisciCategorie(product);
|
|
||||||
await this.gestisciAutori(product);
|
|
||||||
await this.gestisciEditore(product);
|
|
||||||
await this.gestisciCollana(product);
|
|
||||||
|
|
||||||
const risrecInfo = await Product.findOneAndUpdate(
|
|
||||||
{ code: productInfo.code },
|
|
||||||
{ $set: productInfo },
|
|
||||||
{ new: true, upsert: true, returnOriginal: false }
|
|
||||||
).lean();
|
|
||||||
|
|
||||||
if (risrecInfo) {
|
|
||||||
product.idProductInfo = risrecInfo._id;
|
|
||||||
this.queryprod = { idProductInfo: product.idProductInfo };
|
|
||||||
|
|
||||||
const aggiornatoimg = await this.aggiornaImmagineSeNecessario(risrecInfo);
|
|
||||||
if (!aggiornatoimg?.delete) {
|
|
||||||
await this.gestisciGasOrdine(product, risrecInfo);
|
|
||||||
await this.gestisciVariazioni(product, risrecInfo, options);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error('Errore ProductInfo:', product.code);
|
|
||||||
options.errors++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,10 +750,14 @@ class Macro {
|
|||||||
img3: product.img3 || undefined,
|
img3: product.img3 || undefined,
|
||||||
img4: product.img4 || undefined,
|
img4: product.img4 || undefined,
|
||||||
checkout_link: product.checkout_link || undefined,
|
checkout_link: product.checkout_link || undefined,
|
||||||
idStatoProdotto: product.productInfo.idStatoProdotto || undefined,
|
idStatoProdotto: product.idStatoProdotto || undefined,
|
||||||
date_pub: product.date_pub || undefined,
|
date_pub: product.date_pub || undefined,
|
||||||
sottotitolo: product.sottotitolo || undefined,
|
sottotitolo: product.sottotitolo || undefined,
|
||||||
...(product.date_updated_fromGM ? { date_updated_fromGM: product.date_updated_fromGM } : {}),
|
...(product.date_updated_fromGM ? { date_updated_fromGM: product.date_updated_fromGM } : {}),
|
||||||
|
...(product.link_macro ? { link_macro: product.link_macro } : {}),
|
||||||
|
...(product.descrizione_completa_macro
|
||||||
|
? { descrizione_completa_macro: product.descrizione_completa_macro }
|
||||||
|
: {}),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Errore preparaProductInfo :', e);
|
console.error('Errore preparaProductInfo :', e);
|
||||||
@@ -807,10 +840,10 @@ class Macro {
|
|||||||
// Controlla se il Titolo esiste nella tabella temporanea
|
// Controlla se il Titolo esiste nella tabella temporanea
|
||||||
|
|
||||||
let titolo = productGM.Titolo;
|
let titolo = productGM.Titolo;
|
||||||
|
|
||||||
const tabdescr = await ImportaDescr.findOne({ code: productGM.Ean13 }).lean();
|
const tabdescr = await ImportaDescr.findOne({ code: productGM.Ean13 }).lean();
|
||||||
if (tabdescr?.title) {
|
if (tabdescr?.title) {
|
||||||
titolo = tabdescr.title
|
titolo = tabdescr.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
const recproduct = {
|
const recproduct = {
|
||||||
@@ -842,10 +875,18 @@ class Macro {
|
|||||||
// addtocart_link: '',
|
// addtocart_link: '',
|
||||||
stockQty: productGM.QtaDisponibile || undefined,
|
stockQty: productGM.QtaDisponibile || undefined,
|
||||||
date_pub: productGM.DataPubblicazione ? tools.getDateFromISOString(productGM.DataPubblicazione) : null,
|
date_pub: productGM.DataPubblicazione ? tools.getDateFromISOString(productGM.DataPubblicazione) : null,
|
||||||
sottotitolo: productGM.Sottotitolo,
|
|
||||||
productTypes: [shared_consts.PRODUCTTYPE.PRODUCT],
|
productTypes: [shared_consts.PRODUCTTYPE.PRODUCT],
|
||||||
date_updated_fromGM: new Date(),
|
date_updated_fromGM: new Date(),
|
||||||
idStorehouses: [recstorehouse._id],
|
idStorehouses: [recstorehouse._id],
|
||||||
|
...(tabdescr?.descrizione ? { descrizione_breve_macro: tools.getvalueByJsonText(tabdescr?.descrizione) } : {}),
|
||||||
|
...(tabdescr?.descrizione_completa
|
||||||
|
? { descrizione_completa_macro: tools.getvalueByJsonText(tabdescr?.descrizione_completa) }
|
||||||
|
: {}),
|
||||||
|
...(tabdescr?.sottotitolo
|
||||||
|
? { sottotitolo: tools.getvalueByJsonText(tabdescr?.sottotitolo) }
|
||||||
|
: { sottotitolo: productGM.Sottotitolo }),
|
||||||
|
// ...(tabdescr?.titolo ? { name: tools.getvalueByJsonText(tabdescr?.titolo) } : {}),
|
||||||
|
...(tabdescr?.url ? { link_macro: tools.getvalueByJsonText(tabdescr?.url) } : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
let vers = 0;
|
let vers = 0;
|
||||||
@@ -878,7 +919,6 @@ class Macro {
|
|||||||
await nuovaCategoria.save();
|
await nuovaCategoria.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!reccateg?.idArgomento && product.DescrArgomento) {
|
if (!reccateg?.idArgomento && product.DescrArgomento) {
|
||||||
// Se non c'è l'argomento, allora lo cerco nel DB
|
// Se non c'è l'argomento, allora lo cerco nel DB
|
||||||
const recarg = await T_Web_Argomenti.findOne({ Descrizione: product.DescrArgomento }).lean();
|
const recarg = await T_Web_Argomenti.findOne({ Descrizione: product.DescrArgomento }).lean();
|
||||||
@@ -888,9 +928,10 @@ class Macro {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||||
if (myriscat) product.productInfo.idCatProds.push(myriscat);
|
if (myriscat) {
|
||||||
|
product.productInfo.idCatProds.push(myriscat);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (product.categories) {
|
if (product.categories) {
|
||||||
// const arrcat = product.categories.trim().split(',');
|
// const arrcat = product.categories.trim().split(',');
|
||||||
@@ -908,7 +949,9 @@ class Macro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||||
if (myriscat) product.productInfo.idCatProds.push(myriscat);
|
if (myriscat) {
|
||||||
|
product.productInfo.idCatProds.push(myriscat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1007,7 +1050,8 @@ class Macro {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (recpublisher?._id || nuovoEditore?._id) product.productInfo.idPublisher = recpublisher?._id || nuovoEditore._id;
|
if (recpublisher?._id || nuovoEditore?._id)
|
||||||
|
product.productInfo.idPublisher = recpublisher?._id || nuovoEditore._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1035,13 +1079,13 @@ class Macro {
|
|||||||
/**
|
/**
|
||||||
* Aggiorna l'immagine se necessario.
|
* Aggiorna l'immagine se necessario.
|
||||||
*/
|
*/
|
||||||
async aggiornaImmagineSeNecessario(product) {
|
async aggiornaImmagineSeNecessario(product, forzacaricamento) {
|
||||||
const { prodInfo, aggiornatoimg } = await tools.downloadImgIfMissing(product);
|
const { imagefile, aggiornatoimg } = await tools.downloadImgIfMissing(product, forzacaricamento);
|
||||||
if (aggiornatoimg) {
|
if (aggiornatoimg) {
|
||||||
await Product.findOneAndUpdate({ _id: product._id }, { $set: { productInfo: prodInfo } });
|
return imagefile;
|
||||||
}
|
}
|
||||||
|
|
||||||
return aggiornatoimg;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1079,21 +1123,19 @@ class Macro {
|
|||||||
} else {
|
} else {
|
||||||
arrvariazioni.push(nuovaVariazione);
|
arrvariazioni.push(nuovaVariazione);
|
||||||
}
|
}
|
||||||
|
// rimuovi le variazioni senza versione
|
||||||
|
arrvariazioni = arrvariazioni.filter((v) => v.versione);
|
||||||
return arrvariazioni.sort((a, b) => a.versione - b.versione);
|
return arrvariazioni.sort((a, b) => a.versione - b.versione);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Gestisce le variazioni del prodotto.
|
* Gestisce le variazioni del prodotto.
|
||||||
*/
|
*/
|
||||||
async gestisciVariazioni(product, risrecInfo, options) {
|
async gestisciVariazioni(product, options) {
|
||||||
const recold = await Product.findOne(this.queryprod).lean();
|
const recold = await Product.findOne(this.queryprod).lean();
|
||||||
const variazione = this.preparaVariazione(product);
|
const variazione = this.preparaVariazione(product);
|
||||||
|
|
||||||
const myproduct = {
|
const myproduct = {
|
||||||
...product,
|
...product,
|
||||||
...(!product.isbn ? [{ isbn: risrecInfo.code }] : []),
|
|
||||||
...(!product.maxbookableGASQty && risrecInfo.maxbookableGASQty
|
|
||||||
? [{ maxbookableGASQty: risrecInfo.maxbookableGASQty }]
|
|
||||||
: []),
|
|
||||||
idapp: this.idapp,
|
idapp: this.idapp,
|
||||||
arrvariazioni: [variazione],
|
arrvariazioni: [variazione],
|
||||||
};
|
};
|
||||||
@@ -1101,7 +1143,7 @@ class Macro {
|
|||||||
let risultupdate = null;
|
let risultupdate = null;
|
||||||
|
|
||||||
if (recold) {
|
if (recold) {
|
||||||
const arrvariazioni = this.aggiornaVariazioni(recold.arrvariazioni, variazione);
|
let arrvariazioni = this.aggiornaVariazioni(recold.arrvariazioni, variazione);
|
||||||
const updatedDoc = await Product.findOneAndUpdate(
|
const updatedDoc = await Product.findOneAndUpdate(
|
||||||
this.queryprod,
|
this.queryprod,
|
||||||
{ $set: { arrvariazioni } },
|
{ $set: { arrvariazioni } },
|
||||||
@@ -1121,10 +1163,6 @@ class Macro {
|
|||||||
options.idRecUpdated = wasUpserted ? updatedDoc.lastErrorObject.upserted : updatedDoc.value._id;
|
options.idRecUpdated = wasUpserted ? updatedDoc.lastErrorObject.upserted : updatedDoc.value._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recold.isbn !== risrecInfo.code) {
|
|
||||||
product.isbn = risrecInfo.code;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!recold || this.isModified(recold, myproduct) || !this.recProductExist) {
|
if (!recold || this.isModified(recold, myproduct) || !this.recProductExist) {
|
||||||
const updatedDoc = await Product.findOneAndUpdate(
|
const updatedDoc = await Product.findOneAndUpdate(
|
||||||
@@ -1172,10 +1210,10 @@ class Macro {
|
|||||||
async getStat() {
|
async getStat() {
|
||||||
let mystr = '';
|
let mystr = '';
|
||||||
|
|
||||||
const ris = await ProductInfo.countDocuments({
|
const ris = await Product.countDocuments({
|
||||||
$or: [{ date_updated_fromGM: { $exists: false } }, { date_updated_fromGM: null }],
|
$or: [{ date_updated_fromGM: { $exists: false } }, { date_updated_fromGM: null }],
|
||||||
});
|
});
|
||||||
mystr += `${ris} ProductInfo non aggiornati da GM, quindi da cancellare ! \n`;
|
mystr += `${ris} Product non aggiornati da GM, quindi da nascondere ! \n`;
|
||||||
|
|
||||||
return mystr;
|
return mystr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class AmazonBookScraper {
|
|||||||
});
|
});
|
||||||
return { html: data, url };
|
return { html: data, url };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Errore fetching isbn10 ${isbn10} (ISBN:${isbn}) (tentativo ${attempt}):`, err.message);
|
console.error(`Errore fetching ${url} per isbn10 ${isbn10} (ISBN:${isbn}) (tentativo ${attempt}):`, err.message);
|
||||||
|
|
||||||
if (attempt < retryLimit) {
|
if (attempt < retryLimit) {
|
||||||
console.log(`Riprovo tra ${delay / 1000} secondi...`);
|
console.log(`Riprovo tra ${delay / 1000} secondi...`);
|
||||||
@@ -699,7 +699,7 @@ class AmazonBookScraper {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Prendi solo quelli che non sono ancora stati scraped !
|
// Prendi solo quelli che non sono ancora stati scraped !
|
||||||
const products = await Product.aggregate([
|
const query = [
|
||||||
// Filtro di base sui campi idapp, isbn, scraped, e scraped_error
|
// Filtro di base sui campi idapp, isbn, scraped, e scraped_error
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
@@ -711,25 +711,9 @@ class AmazonBookScraper {
|
|||||||
*/
|
*/
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Popoliamo il campo idProductInfo
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: 'productinfos', // Nome della collezione per 'idProductInfo'
|
|
||||||
localField: 'idProductInfo', // Campo del documento corrente (Product)
|
|
||||||
foreignField: '_id', // Campo di riferimento in ProductInfo
|
|
||||||
as: 'idProductInfo', // Campo in cui verranno inseriti i dati popolati
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// De-strutturiamo l'array idProductInfo, se è un array
|
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$idProductInfo',
|
|
||||||
preserveNullAndEmptyArrays: true, // Mantieni i documenti anche se idProductInfo è null o vuoto
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
'idProductInfo.idStatoProdotto': { $in: [1, 4, 34, 45, 46] }, // Condizione su idStatoProdotto
|
'productInfo.idStatoProdotto': { $in: [1, 4, 34, 45, 46] }, // Condizione su idStatoProdotto
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Proiettiamo solo i campi necessari
|
// Proiettiamo solo i campi necessari
|
||||||
@@ -741,17 +725,18 @@ class AmazonBookScraper {
|
|||||||
title: 1,
|
title: 1,
|
||||||
sottotitolo: 1,
|
sottotitolo: 1,
|
||||||
arrvariazioni: 1,
|
arrvariazioni: 1,
|
||||||
'idProductInfo._id': 1,
|
'productInfo.date_pub': 1,
|
||||||
'idProductInfo.date_pub': 1,
|
'productInfo.name': 1,
|
||||||
'idProductInfo.name': 1,
|
'productInfo.sottotitolo': 1,
|
||||||
'idProductInfo.sottotitolo': 1,
|
'productInfo.idStatoProdotto': 1,
|
||||||
'idProductInfo.idStatoProdotto': 1,
|
'productInfo.link_macro': 1,
|
||||||
'idProductInfo.link_macro': 1,
|
'productInfo.imagefile': 1,
|
||||||
'idProductInfo.imagefile': 1,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// A questo punto, puoi aggiungere altre operazioni di aggregazione se necessario (e.g., ordinamento)
|
// A questo punto, puoi aggiungere altre operazioni di aggregazione se necessario (e.g., ordinamento)
|
||||||
]);
|
];
|
||||||
|
|
||||||
|
const products = await Product.aggregate(query);
|
||||||
|
|
||||||
// console.log(products);
|
// console.log(products);
|
||||||
|
|
||||||
|
|||||||
@@ -974,20 +974,6 @@ async function completaSettaggioProduct_AndProductInfo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rec.hasOwnProperty('old_code')) {
|
|
||||||
const old_code = rec['old_code'];
|
|
||||||
let oldrec = await ProductInfo.findOne({ code: old_code }).lean();
|
|
||||||
if (oldrec) {
|
|
||||||
const precid = productInfo._id;
|
|
||||||
const preccode = productInfo.code;
|
|
||||||
|
|
||||||
productInfo = oldrec;
|
|
||||||
if (precid) productInfo._id = precid;
|
|
||||||
else delete productInfo._id;
|
|
||||||
|
|
||||||
productInfo.code = preccode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rec.hasOwnProperty('productTypes')) {
|
if (rec.hasOwnProperty('productTypes')) {
|
||||||
productInfo.productTypes = productInfo.productTypes;
|
productInfo.productTypes = productInfo.productTypes;
|
||||||
} else {
|
} else {
|
||||||
@@ -1291,7 +1277,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Update ProductInfo, non crea nuovi record !
|
// Update ProductInfo, non crea nuovi record !
|
||||||
let risrecInfo = await ProductInfo.findOneAndUpdate(
|
let risrecInfo = await Product.findOneAndUpdate(
|
||||||
{ code: productInfo.code },
|
{ code: productInfo.code },
|
||||||
{ $set: productInfo },
|
{ $set: productInfo },
|
||||||
{ new: true, upsert: false }
|
{ new: true, upsert: false }
|
||||||
@@ -1413,7 +1399,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
if (risrecInfo) {
|
if (risrecInfo) {
|
||||||
productImported.productInfo = risrecInfo._id;
|
productImported.productInfo = risrecInfo._id;
|
||||||
|
|
||||||
recnewInfo = await ProductInfo.findOne({ code: productInfo.code }).lean();
|
recnewInfo = await Product.findOne({ code: product.code }).lean();
|
||||||
|
|
||||||
if (risrecInfo._id) {
|
if (risrecInfo._id) {
|
||||||
// Record existed, so it was updated
|
// Record existed, so it was updated
|
||||||
@@ -1564,22 +1550,20 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
|
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
|
||||||
}
|
}
|
||||||
|
|
||||||
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
|
let esisteindb = await Product.findOne({ code: productInfo.code }).lean();
|
||||||
|
|
||||||
// Update ProductInfo
|
// Update Product
|
||||||
let risrecInfo = await ProductInfo.findOneAndUpdate(
|
let risrecInfo = await Product.findOneAndUpdate(
|
||||||
{ code: productInfo.code },
|
{ code: product.code },
|
||||||
{ $set: productInfo },
|
{ $set: product },
|
||||||
{ new: true, upsert: true }
|
{ new: true, upsert: true }
|
||||||
);
|
);
|
||||||
if (risrecInfo) {
|
if (risrecInfo) {
|
||||||
product.idProductInfo = risrecInfo._id;
|
recnewInfo = await Product.findOne({ code: product.code }).lean();
|
||||||
|
|
||||||
recnewInfo = await ProductInfo.findOne({ code: productInfo.code }).lean();
|
|
||||||
|
|
||||||
if (risrecInfo._id) {
|
if (risrecInfo._id) {
|
||||||
// Record existed, so it was updated
|
// Record existed, so it was updated
|
||||||
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo);
|
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo.productInfo);
|
||||||
if (arrfieldchange && arrfieldchange.length > 0) {
|
if (arrfieldchange && arrfieldchange.length > 0) {
|
||||||
// updated++;
|
// updated++;
|
||||||
console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange);
|
console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange);
|
||||||
|
|||||||
@@ -386,7 +386,10 @@ router.post('/search-books', authenticate, async (req, res) => {
|
|||||||
for (const book of books) {
|
for (const book of books) {
|
||||||
let trovatoISBN = false;
|
let trovatoISBN = false;
|
||||||
let trovato = false;
|
let trovato = false;
|
||||||
|
let productfind = null;
|
||||||
|
|
||||||
for (let field of book) {
|
for (let field of book) {
|
||||||
|
|
||||||
field = field.trim();
|
field = field.trim();
|
||||||
let valido = typeof field === 'string' && field.length > 4 && field.length < 50;
|
let valido = typeof field === 'string' && field.length > 4 && field.length < 50;
|
||||||
if (valido) {
|
if (valido) {
|
||||||
@@ -400,7 +403,7 @@ router.post('/search-books', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
// Priorità se lo trovo per ISBN:
|
// Priorità se lo trovo per ISBN:
|
||||||
if (productInfoarrISBN.length === 1) {
|
if (productInfoarrISBN.length === 1) {
|
||||||
productInfo = productInfoarrISBN[0];
|
productfind = productInfoarrISBN[0];
|
||||||
trovatoISBN = true;
|
trovatoISBN = true;
|
||||||
trovato = true;
|
trovato = true;
|
||||||
}
|
}
|
||||||
@@ -412,12 +415,12 @@ router.post('/search-books', authenticate, async (req, res) => {
|
|||||||
'productInfo.name': field,
|
'productInfo.name': field,
|
||||||
}).exec();
|
}).exec();
|
||||||
if (productarrTitle.length === 1) {
|
if (productarrTitle.length === 1) {
|
||||||
productInfo = productarrTitle[0];
|
productfind = productarrTitle[0];
|
||||||
trovato = true;
|
trovato = true;
|
||||||
} else {
|
} else {
|
||||||
if (productarrTitle.length > 1) {
|
if (productarrTitle.length > 1) {
|
||||||
// Prendi l'Ultimo !
|
// Prendi l'Ultimo !
|
||||||
productInfo = productarrTitle[productarrTitle.length - 1];
|
productfind = productarrTitle[productarrTitle.length - 1];
|
||||||
trovato = true;
|
trovato = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,12 +431,12 @@ router.post('/search-books', authenticate, async (req, res) => {
|
|||||||
'productInfo.name': new RegExp(`.*${escapeRegExp(tools.removeAccents(field.toUpperCase()))}.*`, 'i'),
|
'productInfo.name': new RegExp(`.*${escapeRegExp(tools.removeAccents(field.toUpperCase()))}.*`, 'i'),
|
||||||
}).exec();
|
}).exec();
|
||||||
if (productarrTitle.length === 1) {
|
if (productarrTitle.length === 1) {
|
||||||
productInfo = productarrTitle[0];
|
productfind = productarrTitle[0];
|
||||||
trovato = true;
|
trovato = true;
|
||||||
} else {
|
} else {
|
||||||
if (productarrTitle.length > 1) {
|
if (productarrTitle.length > 1) {
|
||||||
// Prendi l'Ultimo !
|
// Prendi l'Ultimo !
|
||||||
productInfo = productarrTitle[productarrTitle.length - 1];
|
productfind = productarrTitle[productarrTitle.length - 1];
|
||||||
trovato = true;
|
trovato = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,8 +447,8 @@ router.post('/search-books', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (trovato) {
|
if (trovato) {
|
||||||
if (productInfo) {
|
if (productfind) {
|
||||||
product = await Product.findOne({ idProductInfo: productInfo._id }).exec();
|
product = await Product.findOne({ _id: productfind._id }).exec();
|
||||||
if (product) {
|
if (product) {
|
||||||
const existingResult = results.find((r) => r._id.toString() === product._id.toString());
|
const existingResult = results.find((r) => r._id.toString() === product._id.toString());
|
||||||
if (!existingResult) {
|
if (!existingResult) {
|
||||||
|
|||||||
@@ -751,7 +751,7 @@ connectToDatabase(connectionUrl, options)
|
|||||||
|
|
||||||
// ⏱️ Timeout globale per la connessione TCP
|
// ⏱️ Timeout globale per la connessione TCP
|
||||||
server.setTimeout(timeoutMs, () => {
|
server.setTimeout(timeoutMs, () => {
|
||||||
console.log(`TCP timeout su server: ${hostname}:${port}`);
|
console.log(`TCP timeout su server: ${hostname}:${port} ${website}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ⏱️ Timeout per singola richiesta HTTP
|
// ⏱️ Timeout per singola richiesta HTTP
|
||||||
|
|||||||
@@ -1767,7 +1767,8 @@ module.exports = {
|
|||||||
|
|
||||||
if (idapp === 0) idapp = '13';
|
if (idapp === 0) idapp = '13';
|
||||||
|
|
||||||
if (idapp === '13') { // this.RISO
|
if (idapp === '13') {
|
||||||
|
// this.RISO
|
||||||
queryadmins = { username: 'surya1977', idapp };
|
queryadmins = { username: 'surya1977', idapp };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5782,7 +5783,12 @@ module.exports = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// let dir = this.getdirByIdApp(idapp) + dirmain + '/' + this.getDirUpload();
|
// let dir = this.getdirByIdApp(idapp) + dirmain + '/' + this.getDirUpload();
|
||||||
let dir = this.getdirByIdApp(idapp) + '/' + this.getDirUpload() + shared_consts.getDirectoryImgByTable(table, username) + dirmain;
|
let dir =
|
||||||
|
this.getdirByIdApp(idapp) +
|
||||||
|
'/' +
|
||||||
|
this.getDirUpload() +
|
||||||
|
shared_consts.getDirectoryImgByTable(table, username) +
|
||||||
|
dirmain;
|
||||||
|
|
||||||
img = dir + img;
|
img = dir + img;
|
||||||
|
|
||||||
@@ -5844,7 +5850,6 @@ module.exports = {
|
|||||||
//}
|
//}
|
||||||
if (myurl.startsWith('http://127.0.0.1')) {
|
if (myurl.startsWith('http://127.0.0.1')) {
|
||||||
//myurl = myurl.replace('http://127.0.0.1:8084/', 'https://riso.app/')
|
//myurl = myurl.replace('http://127.0.0.1:8084/', 'https://riso.app/')
|
||||||
|
|
||||||
// Se è in locale allora metti una foto finta...
|
// Se è in locale allora metti una foto finta...
|
||||||
// myurl =
|
// myurl =
|
||||||
// 'https://images.unsplash.com/photo-1464047736614-af63643285bf?q=80&w=2874&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D';
|
// 'https://images.unsplash.com/photo-1464047736614-af63643285bf?q=80&w=2874&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D';
|
||||||
@@ -5940,7 +5945,7 @@ module.exports = {
|
|||||||
return mydate2;
|
return mydate2;
|
||||||
},
|
},
|
||||||
|
|
||||||
async downloadImgIfMissing(product) {
|
async downloadImgIfMissing(product, forzacaricamento = false) {
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -5950,40 +5955,37 @@ module.exports = {
|
|||||||
dirmain = server_constants.DIR_PUBLIC_LOCALE;
|
dirmain = server_constants.DIR_PUBLIC_LOCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (true) {
|
|
||||||
const prova = await this.isFileExistsAsync('prova');
|
|
||||||
console.log('PROVA:', prova);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
const vecchiomodo = false;
|
const vecchiomodo = false;
|
||||||
|
|
||||||
|
let imagefile = product.productInfo.imagefile;
|
||||||
|
|
||||||
if (product.productInfo.image_link && vecchiomodo) {
|
if (product.productInfo.image_link && vecchiomodo) {
|
||||||
const relativeimg = product.productInfo.image_link.split('/').pop();
|
const relativeimg = product.productInfo.image_link.split('/').pop();
|
||||||
const img =
|
const img =
|
||||||
this.getdirByIdApp(product.productInfo.idapp) +
|
this.getdirByIdApp(product.idapp) +
|
||||||
dirmain +
|
dirmain +
|
||||||
server_constants.DIR_UPLOAD +
|
server_constants.DIR_UPLOAD +
|
||||||
'/products/' +
|
'/products/' +
|
||||||
product.productInfo.image_link.split('/').pop();
|
product.productInfo.image_link.split('/').pop();
|
||||||
const savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
const savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||||
|
|
||||||
let scaricaimg = !product.productInfo.imagefile || !(await this.isFileExistsAsync(savePath));
|
let scaricaimg = !imagefile || !(await this.isFileExistsAsync(savePath));
|
||||||
|
|
||||||
if (!product.productInfo.imagefile && (await this.isFileExistsAsync(savePath))) {
|
if (!imagefile && (await this.isFileExistsAsync(savePath))) {
|
||||||
// esiste il file, ma sul DB non è corretto
|
// esiste il file, ma sul DB non è corretto
|
||||||
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
||||||
|
|
||||||
if (stats.size > 0) {
|
if (stats.size > 0) {
|
||||||
// Controlla se la dimensione del file è maggiore di zero
|
// Controlla se la dimensione del file è maggiore di zero
|
||||||
// Esiste il file ed è non vuoto, ma sul DB non è corretto
|
// Esiste il file ed è non vuoto, ma sul DB non è corretto
|
||||||
product.productInfo.imagefile = relativeimg;
|
imagefile = relativeimg;
|
||||||
return { prodInfo: product.productInfo, aggiornatoimg: true };
|
return { imagefile, aggiornatoimg: true };
|
||||||
} else {
|
} else {
|
||||||
scaricaimg = true;
|
scaricaimg = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.productInfo.imagefile && (await this.isFileExistsAsync(savePath))) {
|
if (imagefile && (await this.isFileExistsAsync(savePath))) {
|
||||||
// esiste il file, ma sul DB non è corretto
|
// esiste il file, ma sul DB non è corretto
|
||||||
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
||||||
|
|
||||||
@@ -5995,7 +5997,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (scaricaimg && vecchiomodo) {
|
if (scaricaimg && vecchiomodo) {
|
||||||
// Download image from the URL productInfo.image_link
|
// Download image from the URL productInfo.image_link
|
||||||
product.productInfo.imagefile = relativeimg;
|
imagefile = relativeimg;
|
||||||
|
|
||||||
const downloader = new ImageDownloader();
|
const downloader = new ImageDownloader();
|
||||||
|
|
||||||
@@ -6014,19 +6016,19 @@ module.exports = {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
return { prodInfo: product.productInfo, aggiornatoimg: aggiornatoimg.ris };
|
return { imagefile, aggiornatoimg: aggiornatoimg.ris };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileesistente = false;
|
let fileesistente = false;
|
||||||
if (product.productInfo.imagefile && product.productInfo.imagefile !== 'noimg.jpg') {
|
if (imagefile && imagefile !== 'noimg.jpg') {
|
||||||
// controlla se esiste il file
|
// controlla se esiste il file
|
||||||
const img =
|
const img =
|
||||||
this.getdirByIdApp(product.productInfo.idapp) +
|
this.getdirByIdApp(product.idapp) +
|
||||||
dirmain +
|
dirmain +
|
||||||
server_constants.DIR_UPLOAD +
|
server_constants.DIR_UPLOAD +
|
||||||
'/products/' +
|
'/products/' +
|
||||||
product.productInfo.imagefile.split('/').pop();
|
imagefile.split('/').pop();
|
||||||
const filecompleto = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
const filecompleto = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||||
|
|
||||||
// Se non esiste lo scarico !
|
// Se non esiste lo scarico !
|
||||||
@@ -6034,21 +6036,22 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!vecchiomodo && (!product.productInfo.image_link || !fileesistente)) {
|
if (!vecchiomodo && (!product.productInfo.image_link || !fileesistente)) {
|
||||||
let scarica_da_sito = !product.productInfo.imagefile || product.productInfo.imagefile === 'noimg.jpg';
|
let scarica_da_sito = !imagefile || imagefile === 'noimg.jpg';
|
||||||
|
|
||||||
if (!scarica_da_sito && product.productInfo.imagefile) {
|
if (!scarica_da_sito && imagefile) {
|
||||||
scarica_da_sito = !fileesistente; // Se non esiste lo scarico !
|
scarica_da_sito = !fileesistente; // Se non esiste lo scarico !
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scarica_da_sito && !product.productInfo.image_not_found) {
|
if ((scarica_da_sito && !product.productInfo.image_not_found) || forzacaricamento) {
|
||||||
// date and time
|
// date and time
|
||||||
product.productInfo.imagefile = 'img_' + new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
imagefile =
|
||||||
|
'img_' + new Date().toISOString().replace(/T/, '').replace(/\..+/, '').replace(/:/, '').replace(/./, '');
|
||||||
const img =
|
const img =
|
||||||
this.getdirByIdApp(product.productInfo.idapp) +
|
this.getdirByIdApp(product.idapp) +
|
||||||
dirmain +
|
dirmain +
|
||||||
server_constants.DIR_UPLOAD +
|
server_constants.DIR_UPLOAD +
|
||||||
'/products/' +
|
'/products/' +
|
||||||
product.productInfo.imagefile.split('/').pop();
|
imagefile.split('/').pop();
|
||||||
let savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
let savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||||
|
|
||||||
let link = 'https://www.gruppomacro.com/copertine.php?id_gm=' + product.productInfo.sku;
|
let link = 'https://www.gruppomacro.com/copertine.php?id_gm=' + product.productInfo.sku;
|
||||||
@@ -6084,19 +6087,19 @@ module.exports = {
|
|||||||
if (aggiornatoimg?.filepath) {
|
if (aggiornatoimg?.filepath) {
|
||||||
const filenamebase = path.basename(aggiornatoimg.filepath);
|
const filenamebase = path.basename(aggiornatoimg.filepath);
|
||||||
// const img = '/upload/products/' + filenamebase;
|
// const img = '/upload/products/' + filenamebase;
|
||||||
product.productInfo.imagefile = filenamebase;
|
imagefile = filenamebase;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { prodInfo: product.productInfo, aggiornatoimg: aggiornatoimg.ris };
|
return { imagefile, aggiornatoimg: aggiornatoimg.ris };
|
||||||
} else {
|
} else {
|
||||||
return { prodInfo: null, aggiornatoimg: false };
|
return { imagefile: null, aggiornatoimg: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('downloadImgIfMissing', e.message);
|
console.error('downloadImgIfMissing', e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { prodInfo: null, aggiornatoimg: false };
|
return { imagefile: null, aggiornatoimg: false };
|
||||||
},
|
},
|
||||||
|
|
||||||
removeAccents(mystr) {
|
removeAccents(mystr) {
|
||||||
@@ -6220,4 +6223,12 @@ module.exports = {
|
|||||||
return mydate;
|
return mydate;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getvalueByJsonText(valore) {
|
||||||
|
if (valore && valore['#text']) {
|
||||||
|
if (valore['#text']) return valore['#text'];
|
||||||
|
else return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user