- Cataloghi: pagine, schede, formato
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine, IAuthor, ISubCatProd } from 'model'
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine, IAuthor, ISubCatProd, IText } from 'model'
|
||||
|
||||
import { Api } from '@api'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
@@ -1267,32 +1267,46 @@ export const useProducts = defineStore('Products', {
|
||||
return authorString
|
||||
},
|
||||
|
||||
replaceKeyWordsByProduct(myproduct: IProduct, text_html: string) {
|
||||
if (!myproduct || !text_html) {
|
||||
return text_html;
|
||||
replaceKeyWordsByProduct(myproduct: IProduct, testo: IText) {
|
||||
if (!myproduct || !testo.contenuto) {
|
||||
return testo.contenuto;
|
||||
}
|
||||
|
||||
const autori = this.getAutoriByArrayAuthors(myproduct.productInfo.authors)
|
||||
|
||||
const maxDescriptionLength = 100;
|
||||
const maxDescriptionLength = testo.maxlength ?? 100;
|
||||
const description = myproduct.productInfo.short_descr || '';
|
||||
const long_descr = myproduct.productInfo.description || '';
|
||||
|
||||
const truncatedDescription = description.length > maxDescriptionLength
|
||||
? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: description;
|
||||
|
||||
const truncatedlongDescription = long_descr.length > maxDescriptionLength
|
||||
? long_descr.substring(0, long_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: long_descr;
|
||||
|
||||
const prezzo = myproduct.arrvariazioni ? myproduct.arrvariazioni[0].price?.toFixed(2) : ''
|
||||
const prezzo_scontato = myproduct.arrvariazioni ? myproduct.arrvariazioni[0].sale_price?.toFixed(2) : ''
|
||||
const misure = myproduct.arrvariazioni ? myproduct.arrvariazioni[0].misure : ''
|
||||
const formato = myproduct.arrvariazioni ? myproduct.arrvariazioni[0].formato : ''
|
||||
const pagine = myproduct.arrvariazioni ? myproduct.arrvariazioni[0].pagine : ''
|
||||
|
||||
// Crea una mappa di sostituzioni
|
||||
const replacements = {
|
||||
'{autore}': autori || '',
|
||||
'{titolo}': myproduct.productInfo.name || '',
|
||||
'{descrizione}': truncatedDescription || '',
|
||||
'{descrizione_estesa}': truncatedlongDescription || '',
|
||||
'{pagine}': pagine || '',
|
||||
'{misure}': misure || '',
|
||||
'{formato}': formato || '',
|
||||
'{prezzo}': prezzo || '',
|
||||
'{prezzo_scontato}': prezzo_scontato || '',
|
||||
};
|
||||
|
||||
// Esegue le sostituzioni
|
||||
let result = text_html;
|
||||
let result = testo.contenuto;
|
||||
for (const [key, value] of Object.entries(replacements)) {
|
||||
result = result.replace(new RegExp(key, 'g'), value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user