- aggiornamento Cataloghi
- Gestione delle versioni del prodotto ("Nuovi","Usati","Epub", ecc..)
This commit is contained in:
@@ -44,6 +44,17 @@ const elemText = new Schema(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const catalogo = new Schema(
|
||||||
|
{
|
||||||
|
//++AddCATALOGO_FIELDS
|
||||||
|
productTypes: [{ type: Number }],
|
||||||
|
excludeproductTypes: [{ type: Number }],
|
||||||
|
// formato: [{ type: String, default: '' }],
|
||||||
|
// categoria: [{ type: String, default: '' }],
|
||||||
|
// Editore: [{ type: String, default: '' }],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const MyElemSchema = new Schema({
|
const MyElemSchema = new Schema({
|
||||||
_id: {
|
_id: {
|
||||||
type: ObjectId,
|
type: ObjectId,
|
||||||
@@ -164,6 +175,7 @@ const MyElemSchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
listcards: [myCard],
|
listcards: [myCard],
|
||||||
|
catalogo: catalogo,
|
||||||
list: [
|
list: [
|
||||||
{
|
{
|
||||||
imagefile: {
|
imagefile: {
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ const productSchema = new Schema({
|
|||||||
active: {
|
active: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
versione: {
|
arrversioni: [{
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
}],
|
||||||
status: { //publish
|
status: { //publish
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ const productInfoSchema = new Schema({
|
|||||||
checkout_link: {
|
checkout_link: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
versioneGM: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
img2: {
|
img2: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -114,9 +117,9 @@ const productInfoSchema = new Schema({
|
|||||||
date_publishing: {
|
date_publishing: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
productType: {
|
productTypes: [{
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
}],
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -215,6 +218,51 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
module.exports.getProductByCode = function (idapp, code) {
|
module.exports.getProductByCode = function (idapp, code) {
|
||||||
return productInfo.findAllIdApp(idapp, code);
|
return productInfo.findAllIdApp(idapp, code);
|
||||||
}
|
}
|
||||||
|
module.exports.correggiProductTypes = async function() {
|
||||||
|
const ProductInfo = this;
|
||||||
|
const bulkOps = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Fase di aggregazione
|
||||||
|
const cursor = ProductInfo.aggregate([
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
_id: 1,
|
||||||
|
productType: 1,
|
||||||
|
productTypes: [{ $ifNull: ['$productType', 10] }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).cursor({ batchSize: 1000 }).exec();
|
||||||
|
|
||||||
|
// Itera attraverso ogni documento utilizzando il cursore
|
||||||
|
for await (const doc of cursor) {
|
||||||
|
bulkOps.push({
|
||||||
|
updateOne: {
|
||||||
|
filter: { _id: doc._id },
|
||||||
|
update: {
|
||||||
|
$set: { productTypes: doc.productTypes },
|
||||||
|
$unset: { productType: "" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Scrivi i batch di operazioni ogni 1000 documenti
|
||||||
|
if (bulkOps.length === 1000) {
|
||||||
|
await ProductInfo.bulkWrite(bulkOps);
|
||||||
|
bulkOps.length = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scrivi eventuali operazioni rimanenti
|
||||||
|
if (bulkOps.length > 0) {
|
||||||
|
await ProductInfo.bulkWrite(bulkOps);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('ProductInfo.productType converted to productTypes array and saved');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error converting ProductInfo.productType:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.createIndexes((err) => {
|
module.exports.createIndexes((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@@ -119,10 +119,10 @@ async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arr
|
|||||||
productInfo.code = preccode;
|
productInfo.code = preccode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rec.hasOwnProperty('productType')) {
|
if (rec.hasOwnProperty('productTypes')) {
|
||||||
productInfo.productType = rec.hasOwnProperty('productType');
|
productInfo.productTypes = productInfo.productTypes;
|
||||||
} else {
|
} else {
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.PRODUCT;
|
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
|
||||||
}
|
}
|
||||||
|
|
||||||
return { product, productInfo };
|
return { product, productInfo };
|
||||||
@@ -339,6 +339,11 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
importa = false;
|
importa = false;
|
||||||
|
|
||||||
if (importa) {
|
if (importa) {
|
||||||
|
let versGM = product.Versione ? product.Versione : '';
|
||||||
|
|
||||||
|
// split versioneGM in array with separated ","
|
||||||
|
let arrversGM = versGM.split(",").map(x => x.trim());
|
||||||
|
|
||||||
let productInfo = {
|
let productInfo = {
|
||||||
idapp: product.idapp,
|
idapp: product.idapp,
|
||||||
code: product.isbn,
|
code: product.isbn,
|
||||||
@@ -361,41 +366,53 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let versione = 0;
|
let versione = 0;
|
||||||
|
let arrversioni = [];
|
||||||
|
|
||||||
|
productInfo.productTypes = [];
|
||||||
|
// console.log('indprod', indprod, 'arrversGM', arrversGM, 'versione', product.Versione);
|
||||||
|
|
||||||
|
for (let i = 0; i < arrversGM.length; i++) {
|
||||||
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
|
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
|
||||||
if (product.Versione === 'Nuovo')
|
if (arrversGM[i] === 'Nuovo')
|
||||||
versione = shared_consts.VERSIONE.NUOVO
|
versione = shared_consts.VERSIONE.NUOVO
|
||||||
else if (product.Versione === 'Usato')
|
else if (arrversGM[i] === 'Usato')
|
||||||
versione = shared_consts.VERSIONE.USATO;
|
versione = shared_consts.VERSIONE.USATO;
|
||||||
else if (product.Versione === 'Download')
|
else if (arrversGM[i] === 'Download')
|
||||||
versione = shared_consts.VERSIONE.DOWNLOAD;
|
versione = shared_consts.VERSIONE.DOWNLOAD;
|
||||||
else if (product.Versione === 'DVD')
|
else if (arrversGM[i] === 'DVD')
|
||||||
versione = shared_consts.VERSIONE.DVD;
|
versione = shared_consts.VERSIONE.DVD;
|
||||||
else if (product.Versione === 'Epub')
|
else if (arrversGM[i] === 'Epub')
|
||||||
versione = shared_consts.VERSIONE.EPUB;
|
versione = shared_consts.VERSIONE.EPUB;
|
||||||
else if (product.Versione === 'Mobi')
|
else if (arrversGM[i] === 'Mobi')
|
||||||
versione = shared_consts.VERSIONE.MOBI;
|
versione = shared_consts.VERSIONE.MOBI;
|
||||||
else if (product.Versione === 'PDF')
|
else if (arrversGM[i] === 'PDF')
|
||||||
versione = shared_consts.VERSIONE.PDF;
|
versione = shared_consts.VERSIONE.PDF;
|
||||||
else if (product.Versione === 'Streaming')
|
else if (arrversGM[i] === 'Streaming')
|
||||||
versione = shared_consts.VERSIONE.STREAMING;
|
versione = shared_consts.VERSIONE.STREAMING;
|
||||||
else
|
|
||||||
versione = 100;
|
arrversioni.push(versione);
|
||||||
|
|
||||||
if (versione === shared_consts.VERSIONE.DOWNLOAD)
|
if (versione === shared_consts.VERSIONE.DOWNLOAD)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.DOWNLOAD;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.DOWNLOAD);
|
||||||
else if (versione === shared_consts.VERSIONE.DVD)
|
else if (versione === shared_consts.VERSIONE.DVD)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.DVD;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.DVD);
|
||||||
else if (versione === shared_consts.VERSIONE.EPUB)
|
else if (versione === shared_consts.VERSIONE.EPUB)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.EPUB;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.EPUB);
|
||||||
else if (versione === shared_consts.VERSIONE.MOBI)
|
else if (versione === shared_consts.VERSIONE.MOBI)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.MOBI;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.MOBI);
|
||||||
else if (versione === shared_consts.VERSIONE.PDF)
|
else if (versione === shared_consts.VERSIONE.PDF)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.PDF;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.PDF);
|
||||||
else if (versione === shared_consts.VERSIONE.STREAMING)
|
else if (versione === shared_consts.VERSIONE.STREAMING)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.STREAMING;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.STREAMING);
|
||||||
else
|
else if (versione === shared_consts.VERSIONE.USATO)
|
||||||
productInfo.productType = shared_consts.PRODUCTTYPE.LIBRO;
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.USATO);
|
||||||
|
else if (versione === shared_consts.VERSIONE.NUOVO)
|
||||||
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.NUOVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (productInfo.productTypes.length === 0) {
|
||||||
|
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.LIBRO);
|
||||||
|
}*/
|
||||||
|
|
||||||
if (product.Data)
|
if (product.Data)
|
||||||
productInfo.date_publishing = new Date(product.Data * 1000);
|
productInfo.date_publishing = new Date(product.Data * 1000);
|
||||||
@@ -604,7 +621,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cerca l'indice della versione in arrvariazioni
|
// cerca l'indice della versione in arrvariazioni
|
||||||
let ind = arrvariazioni.findIndex(x => x.versione === versione);
|
let ind = arrvariazioni.findIndex(x => arrversioni.includes(x.versione));
|
||||||
let nuovaVariazione = ind < 0;
|
let nuovaVariazione = ind < 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -615,7 +632,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
variazione.active = true; // ++ ??
|
variazione.active = true; // ++ ??
|
||||||
variazione.versione = versione;
|
variazione.arrversioni = arrversioni;
|
||||||
variazione.status = product.Stato ? product.Stato : null;
|
variazione.status = product.Stato ? product.Stato : null;
|
||||||
variazione.price = product.price ? parseFloat(tools.convertPriceEurToValue(product.price)) : null;
|
variazione.price = product.price ? parseFloat(tools.convertPriceEurToValue(product.price)) : null;
|
||||||
variazione.sale_price = product.sale_price ? parseFloat(tools.convertPriceEurToValue(product.sale_price)) : null;
|
variazione.sale_price = product.sale_price ? parseFloat(tools.convertPriceEurToValue(product.sale_price)) : null;
|
||||||
@@ -770,7 +787,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
img: 'upload/products/' + product.code + '.jpg',
|
img: 'upload/products/' + product.code + '.jpg',
|
||||||
weight: product.weight,
|
weight: product.weight,
|
||||||
unit: tools.getIdUnitsByText(product.unit),
|
unit: tools.getIdUnitsByText(product.unit),
|
||||||
productType: shared_consts.PRODUCTTYPE.PRODUCT,
|
productTypes: shared_consts.PRODUCTTYPE.PRODUCT,
|
||||||
}
|
}
|
||||||
|
|
||||||
let reccateg = null;
|
let reccateg = null;
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ const { authenticate, authenticate_noerror } = require('../middleware/authentica
|
|||||||
const Cart = require('../models/cart');
|
const Cart = require('../models/cart');
|
||||||
const CartClass = require('../modules/Cart');
|
const CartClass = require('../modules/Cart');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
const ProductInfo = require('../models/productInfo');
|
||||||
const CatProd = require('../models/catprod');
|
const CatProd = require('../models/catprod');
|
||||||
const SubCatProd = require('../models/subcatprod');
|
const SubCatProd = require('../models/subcatprod');
|
||||||
const ProductInfo = require('../models/productInfo');
|
|
||||||
const Order = require('../models/order');
|
const Order = require('../models/order');
|
||||||
const OrdersCart = require('../models/orderscart');
|
const OrdersCart = require('../models/orderscart');
|
||||||
const Variant = require('../models/variant');
|
const Variant = require('../models/variant');
|
||||||
@@ -1623,6 +1623,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
await Circuit.createCircuitIfNotExist(req, idapp, recprov.prov);
|
await Circuit.createCircuitIfNotExist(req, idapp, recprov.prov);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'correggiProductTypes') {
|
||||||
|
|
||||||
|
await ProductInfo.correggiProductTypes();
|
||||||
|
|
||||||
} else if (mydata.dbop === 'correggiCircuitiANull') {
|
} else if (mydata.dbop === 'correggiCircuitiANull') {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1091,6 +1091,16 @@ module.exports = {
|
|||||||
AUDIOLIBRO: 22,
|
AUDIOLIBRO: 22,
|
||||||
VIDEO: 23,
|
VIDEO: 23,
|
||||||
CARTE: 25,
|
CARTE: 25,
|
||||||
|
// -----------
|
||||||
|
NUOVO: 101,
|
||||||
|
USATO: 102,
|
||||||
|
DOWNLOAD: 103,
|
||||||
|
DVD: 104,
|
||||||
|
EPUB: 105,
|
||||||
|
MOBI: 106,
|
||||||
|
PDF: 107,
|
||||||
|
STREAMING: 108,
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
|
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
|
||||||
|
|||||||
Reference in New Issue
Block a user