- aggiornato catalogo lista con filtri per editori e grafico
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -1894,6 +1894,7 @@ function load(req, res, version) {
|
||||
let storehouses = Storehouse.findAllIdApp(idapp);
|
||||
let providers = Provider.findAllIdApp(idapp);
|
||||
let catprods = Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA);
|
||||
let catprtotali = CatProd.getCatProdWithTitleCount(idapp);
|
||||
let collane = Collana.findAllIdApp(idapp);
|
||||
let catalogs = Catalog.findAllIdApp(idapp);
|
||||
let catprods_gas = Product.getArrCatProds(idapp, shared_consts.PROD.GAS);
|
||||
@@ -2010,6 +2011,7 @@ function load(req, res, version) {
|
||||
myschedas,
|
||||
collane,
|
||||
catalogs,
|
||||
catprtotali,
|
||||
]).then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
let myuser = req.user;
|
||||
@@ -2107,6 +2109,7 @@ function load(req, res, version) {
|
||||
myschedas: arrdata[51],
|
||||
collane: arrdata[52],
|
||||
catalogs: arrdata[53],
|
||||
catprtotali: arrdata[54],
|
||||
});
|
||||
|
||||
const prova = 1;
|
||||
|
||||
Reference in New Issue
Block a user