- aggiornato catalogo lista con filtri per editori e grafico

This commit is contained in:
Surya Paolo
2025-02-13 21:14:51 +01:00
parent d77f9381e5
commit f8de205cf6
6 changed files with 60 additions and 17 deletions

View File

@@ -64,7 +64,7 @@ async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr
if (product.ListaArgomenti) {
idArgomentoNum = parseInt(product.ListaArgomenti);
productInfo = { ...recproductInfoAttuale, IdArgomento: idArgomentoNum };
productInfo = { ...recproductInfoAttuale, idArgomento: idArgomentoNum };
} else {
productInfo = { ...recproductInfoAttuale };
}
@@ -78,26 +78,26 @@ async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr
return productInfo;
}
async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
async function findOrCreateCatProd(idapp, idArgomento, DescrArgomento) {
let reccatprod = null;
if (IdArgomento) {
reccatprod = await CatProd.findOne({ idapp, IdArgomento }).lean();
if (idArgomento) {
reccatprod = await CatProd.findOne({ idapp, idArgomento }).lean();
}
if (!reccatprod) {
reccatprod = await CatProd.findOne({ idapp, name: DescrArgomento }).lean();
if (reccatprod) {
if (IdArgomento) {
if (idArgomento) {
await CatProd.findOneAndUpdate(
{ _id: reccatprod._id },
{ $set: { IdArgomento } },
{ $set: { idArgomento } },
{ new: true, upsert: false }
);
}
} else {
if (IdArgomento) {
if (idArgomento) {
try {
reccatprod = new CatProd({ idapp, IdArgomento, name: DescrArgomento });
reccatprod = new CatProd({ idapp, idArgomento, name: DescrArgomento });
await reccatprod.save();
} catch (e) {
console.error('Errore nella creazione di CatProd:', e);
@@ -112,8 +112,8 @@ async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
function updateProductInfoCatProds(productInfo, reccatprod) {
if (productInfo) {
const isChanged = !productInfo.idCatProds || productInfo.idCatProds.length !== 1 ||
productInfo.idCatProds[0] !== reccatprod._id;
const isChanged = (!productInfo.idCatProds || productInfo.idCatProds.length < 1) ||
(productInfo.idCatProds[0].toString() !== reccatprod._id.toString());
if (isChanged) {
productInfo.idCatProds = [reccatprod._id];
@@ -843,7 +843,7 @@ router.post('/import', authenticate, async (req, res) => {
let imported = 0;
let errors = 0;
const ripopola = false; // SETTARE su TRUE
const ripopola = true; // SETTARE su TRUE
if (ripopola) {
dataObjects = null;
@@ -1143,6 +1143,12 @@ router.post('/import', authenticate, async (req, res) => {
checkout_link: product.checkout_link ? product.checkout_link : '',
}
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
if (esisteindb) {
productInfo.idCatProds = esisteindb.idCatProds;
productInfo.idSubCatProds = esisteindb.idSubCatProds;
}
let versione = 0;
if (indprod % 100 === 0)
@@ -1196,8 +1202,6 @@ router.post('/import', authenticate, async (req, res) => {
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
if (recrankingisbn && recrankingisbn.DescrArgomento) {
productInfo.idCatProds = []; // Azzera
if (tools.isArray(recrankingisbn.ListaArgomenti) && recrankingisbn.ListaArgomenti.length > 1) {
console.log('ListaArgomenti STA RITORNANDO UN ARRAY !!!! ', recrankingisbn.ListaArgomenti);
}
@@ -1342,7 +1346,7 @@ router.post('/import', authenticate, async (req, res) => {
product.active = true;
}
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
if (risrecInfo) {