- Catalogo: Aggiunta di Schede

This commit is contained in:
Surya Paolo
2024-10-31 23:23:06 +01:00
parent b6f73019fe
commit 2ea6468100
123 changed files with 3382 additions and 3595327 deletions

View File

@@ -131,7 +131,7 @@ export const useProducts = defineStore('Products', {
// Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato
if (idGasOrdine) {
arrcat = state.catprods_gas.filter((rec: ICatProd) => {
arrcat = state.catprods_gas.filter((rec: ICatProd) => {
const arrprod = state.products.filter((prod: IProduct) => {
if (prod.idGasordine === idGasOrdine && prod.productInfo.idCatProds?.includes(rec._id)) {
return true
@@ -140,12 +140,12 @@ export const useProducts = defineStore('Products', {
})
return arrprod.length > 0 ? true : false
})
} else {
return []
}
return arrcat
},
@@ -155,9 +155,9 @@ export const useProducts = defineStore('Products', {
// Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato
if (idGasOrdine) {
arrcat = state.subcatprods.filter((rec: ISubCatProd) => {
arrcat = state.subcatprods.filter((rec: ISubCatProd) => {
const arrprod = state.products.filter((prod: IProduct) => {
if (prod.idGasordine === idGasOrdine
if (prod.idGasordine === idGasOrdine
&& prod.productInfo.idSubCatProds?.includes(rec._id)
&& prod.productInfo.idCatProds?.includes(idCatProd)
) {
@@ -167,7 +167,7 @@ export const useProducts = defineStore('Products', {
})
return arrprod.length > 0 ? true : false
})
} else {
return []
}
@@ -473,7 +473,7 @@ export const useProducts = defineStore('Products', {
this.products = [...arrprod]
},*/
async getProductById (id: string): Promise<IProduct> {
async getProductById(id: string): Promise<IProduct> {
let prod = null
if (!this.products) {
// Se non lo carico all'avvio, allora fai la chiamata al server
@@ -481,7 +481,7 @@ export const useProducts = defineStore('Products', {
} else {
prod = this.products.find((prod: IProduct) => prod._id === id)
}
return prod ? prod : getRecordProductEmpty()
},
@@ -1244,6 +1244,62 @@ export const useProducts = defineStore('Products', {
return globalStore.gasordines.filter((rec) => rec.active)
},
getAutoriByArrayAuthors(authors: IAuthor[] | null) {
// Gestione degli autori
let authorString = '';
if (authors && Array.isArray(authors)) {
// Crea un array di nomi completi
const fullNames = authors.map(author =>
`${author.name} ${author.surname}`.trim()
);
// Formattazione degli autori
if (fullNames.length === 1) {
authorString = fullNames[0];
} else if (fullNames.length === 2) {
authorString = `${fullNames[0]} e ${fullNames[1]}`;
} else if (fullNames.length > 2) {
const lastAuthor = fullNames.pop();
authorString = `${fullNames.join(', ')} e ${lastAuthor}`;
}
}
return authorString
},
replaceKeyWordsByProduct(myproduct: IProduct, text_html: string) {
if (!myproduct || !text_html) {
return text_html;
}
const autori = this.getAutoriByArrayAuthors(myproduct.productInfo.authors)
const maxDescriptionLength = 100;
const description = myproduct.productInfo.short_descr || '';
const truncatedDescription = description.length > maxDescriptionLength
? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...'
: description;
const prezzo = myproduct.arrvariazioni ? myproduct.arrvariazioni[0].price?.toFixed(2) : ''
// Crea una mappa di sostituzioni
const replacements = {
'{autore}': autori || '',
'{titolo}': myproduct.productInfo.name || '',
'{descrizione}': truncatedDescription || '',
'{prezzo}': prezzo || '',
};
// Esegue le sostituzioni
let result = text_html;
for (const [key, value] of Object.entries(replacements)) {
result = result.replace(new RegExp(key, 'g'), value);
}
return result
},
},