- scheda prodotto migliorata
- aggiornamento filtri
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine, IAuthor, ISubCatProd, IText, IOptCatalogo, ICatalog, ICatPrTotali, ISingleProductOrdered, ISchedaSingola, IMyScheda, IElementiScheda, T_Web_StatiProdotto } from 'model'
|
||||
import type { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine, IAuthor, ISubCatProd, IText, IOptCatalogo, ICatalog, ICatPrTotali, ISingleProductOrdered, ISchedaSingola, IMyScheda, IElementiScheda, T_Web_StatiProdotto, T_Web_Tipologie, T_WEB_TipiFormato } from 'model'
|
||||
|
||||
import { Api } from '@api'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
@@ -130,6 +130,10 @@ export const useProducts = defineStore('Products', {
|
||||
},
|
||||
|
||||
isDisponibile: (state: IProductsState) => (product: IProduct): boolean => {
|
||||
return product?.arrvariazioni?.[0]?.quantita > 1
|
||||
},
|
||||
|
||||
isDisponibilitaOk: (state: IProductsState) => (product: IProduct): boolean => {
|
||||
return product?.arrvariazioni?.[0]?.quantita > 100
|
||||
},
|
||||
|
||||
@@ -146,11 +150,9 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
isPubblicatoById: (state: IProductsState) => (idStatoProdotto: number): boolean => {
|
||||
switch (idStatoProdotto) {
|
||||
case 1:
|
||||
case 4:
|
||||
case 34:
|
||||
case 45:
|
||||
case 46:
|
||||
case 1: // In Commercio
|
||||
case 45: // In Commercio
|
||||
case 46: // 2023 in commercio
|
||||
case undefined:
|
||||
return true;
|
||||
default:
|
||||
@@ -158,16 +160,41 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
},
|
||||
|
||||
isProssimaUscitaById: (state: IProductsState) => (idStatoProdotto: number): boolean => {
|
||||
// 4 - Prossima uscita
|
||||
// 34 - In Prevendita
|
||||
return (idStatoProdotto === 4) || (idStatoProdotto === 34)
|
||||
},
|
||||
|
||||
isPubblicato: (state: IProductsState) => (productInfo: IProductInfo): boolean => {
|
||||
return state.isPubblicatoById(productInfo.idStatoProdotto)
|
||||
},
|
||||
|
||||
isNonVendibile: (state: IProductsState) => (productInfo: IProductInfo): boolean => {
|
||||
return !state.isPubblicatoById(productInfo.idStatoProdotto) && !state.isProssimaUscitaById(productInfo.idStatoProdotto)
|
||||
},
|
||||
|
||||
isProssimaUscita: (state: IProductsState) => (productInfo: IProductInfo): boolean => {
|
||||
return state.isProssimaUscitaById(productInfo.idStatoProdotto)
|
||||
},
|
||||
|
||||
getDescrStatiProdottoByIdStatoProdotto: (state: IProductsState) => (idStatoProdotto: number): string => {
|
||||
const ctrec = state.stati_prodotto.find((mystatus: T_Web_StatiProdotto) => mystatus.IdStatoProdotto === idStatoProdotto)
|
||||
return (ctrec) ? ctrec.Descrizione : ''
|
||||
},
|
||||
|
||||
|
||||
getDescrByIdTipologia: (state: IProductsState) => (idTipologia: number): string => {
|
||||
const ctrec = state.tipologie.find((mystatus: T_Web_Tipologie) => mystatus.IdTipologia === idTipologia)
|
||||
return (ctrec) ? ctrec.Descrizione : ''
|
||||
},
|
||||
|
||||
getDescrByIdTipoFormato: (state: IProductsState) => (idTipoFormato: number): string => {
|
||||
const ctrec = state.tipoformato.find((mystatus: T_WEB_TipiFormato) => mystatus.IdTipoFormato === idTipoFormato)
|
||||
return (ctrec) ? ctrec.Descrizione : ''
|
||||
},
|
||||
|
||||
|
||||
getArrayidArgomentoByArridCatProds: (state: IProductsState) => (arridCatProds: string[]): string[] => {
|
||||
const myarr: string[] = []
|
||||
for (const idCatProd of arridCatProds) {
|
||||
@@ -1426,114 +1453,158 @@ export const useProducts = defineStore('Products', {
|
||||
return testo.contenuto;
|
||||
}
|
||||
|
||||
const autori = this.getAutoriByArrayAuthors(myproduct.productInfo.authors)
|
||||
const collana = tools.formatCollane(myproduct.productInfo.idCollana)
|
||||
const replacements: { [key: string]: any } = {};
|
||||
|
||||
if (testo.contenuto.includes('{autore}')) {
|
||||
replacements['{autore}'] = this.getAutoriByArrayAuthors(myproduct.productInfo.authors) || '';
|
||||
}
|
||||
|
||||
if (testo.contenuto.includes('{collana}')) {
|
||||
replacements['{collana}'] = tools.formatCollane(myproduct.productInfo.idCollana) || '';
|
||||
}
|
||||
|
||||
const maxDescriptionLength = testo.maxlength ?? 100;
|
||||
const description = myproduct.productInfo.short_descr || '';
|
||||
const long_descr = myproduct.productInfo.description || '';
|
||||
const date_pub = tools.getstrDateShort(myproduct.productInfo.date_pub) || '';
|
||||
const fatLast3M = myproduct.productInfo.fatLast3M! || 0;
|
||||
const fatLast6M = myproduct.productInfo.fatLast6M! || 0;
|
||||
const vLast3M = myproduct.productInfo.vLast3M! || 0;
|
||||
const vLast6M = myproduct.productInfo.vLast6M! || 0;
|
||||
const ranking_globale = myproduct.productInfo.rank3M! || 0;
|
||||
const venduti = myproduct.productInfo.totVen! || 0;
|
||||
const fatturati = myproduct.productInfo.totFat! || 0;
|
||||
|
||||
const linkvenduti = '<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-ordini-by-idarticolo/' + myproduct.productInfo.sku + '" target="_blank">' + venduti + '</a>'
|
||||
const linkfatturati = '<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-fatturati-by-idarticolo/' + myproduct.productInfo.sku + '" target="_blank">' + fatturati + '</a>'
|
||||
const debugstr = this.getkeyValStr('Pub:', date_pub) +
|
||||
this.getkeyValStr('fat6M', fatLast6M) +
|
||||
// this.getkeyValStr('Rank3M', myproduct.productInfo.rank3M) +
|
||||
this.getkeyValStr('Ven:', linkvenduti) +
|
||||
this.getkeyValStr('v3M', vLast3M) +
|
||||
this.getkeyValStr('v6M', vLast6M) +
|
||||
this.getkeyValStr('Fatt:', linkfatturati) +
|
||||
this.getkeyValStr('fat3M', fatLast3M)
|
||||
|
||||
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;
|
||||
|
||||
let addtesto = false
|
||||
|
||||
const long_descr_macro = myproduct.productInfo.descrizione_completa_macro || '';
|
||||
if (long_descr_macro.length > maxDescriptionLength) {
|
||||
addtesto = true
|
||||
}
|
||||
const addstrcontinua = '<span class="book-link">👉🏻 <a href="{link_macro}" target="_blank">continua a leggere</a></span>'
|
||||
|
||||
let descrizione_completa_macro = addtesto
|
||||
? long_descr_macro.substring(0, long_descr_macro.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: long_descr_macro;
|
||||
|
||||
if (addtesto) {
|
||||
descrizione_completa_macro += addstrcontinua
|
||||
if (testo.contenuto.includes('{descrizione_da_fdv}')) {
|
||||
const description = myproduct.productInfo.short_descr || '';
|
||||
replacements['{descrizione_da_fdv}'] = description.length > maxDescriptionLength
|
||||
? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: description;
|
||||
}
|
||||
|
||||
const descr_trafiletto_catalogo = myproduct.productInfo.descr_trafiletto_catalogo || '';
|
||||
const short_descr = myproduct.productInfo.descrizione_breve_macro || '';
|
||||
const descrizione_breve_macro = short_descr.length > maxDescriptionLength
|
||||
? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: short_descr;
|
||||
if (testo.contenuto.includes('{descrizione_estesa_fdv}')) {
|
||||
const long_descr = myproduct.productInfo.description || '';
|
||||
replacements['{descrizione_estesa_fdv}'] = long_descr.length > maxDescriptionLength
|
||||
? long_descr.substring(0, long_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: long_descr;
|
||||
}
|
||||
|
||||
const sottotitolo = myproduct.productInfo.sottotitolo || '';
|
||||
const link_macro = myproduct.productInfo.link_macro || '';
|
||||
if (testo.contenuto.includes('{descrizione_estesa}')) {
|
||||
let addtesto = false;
|
||||
const long_descr_macro = myproduct.productInfo.descrizione_completa_macro || '';
|
||||
if (long_descr_macro.length > maxDescriptionLength) {
|
||||
addtesto = true;
|
||||
}
|
||||
const addstrcontinua = '<span class="book-link">👉🏻 <a href="{link_macro}" target="_blank">continua a leggere</a></span>';
|
||||
let descrizione_completa_macro = addtesto
|
||||
? long_descr_macro.substring(0, long_descr_macro.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: long_descr_macro;
|
||||
|
||||
const prezzo = tools.arrotonda2Dec(myproduct.arrvariazioni![0].price) || ''
|
||||
const prezzo_scontato = tools.arrotonda2Dec(myproduct.arrvariazioni![0].sale_price) || ''
|
||||
const categoria = this.getCatProdsStrByCatProds(myproduct.productInfo.catprods!)
|
||||
const sottocategoria = myproduct.productInfo.subcatprods && myproduct.productInfo.subcatprods.length > 0 ? myproduct.productInfo.subcatprods[0].name! : ''
|
||||
const descr_categoria = myproduct.productInfo.catprods && myproduct.productInfo.catprods.length > 0 ? this.getCatProdDescrStrByIdCatProd(myproduct.productInfo.catprods![0].name) : ''
|
||||
const misure = myproduct.arrvariazioni![0].misure || ''
|
||||
const formato = myproduct.arrvariazioni![0].formato || ''
|
||||
const pagine = myproduct.arrvariazioni![0].pagine || ''
|
||||
const qta = myproduct.arrvariazioni![0].quantita || ''
|
||||
const isbn = myproduct.productInfo.code || ''
|
||||
const image_link = myproduct.productInfo.image_link || ''
|
||||
const imagefile = myproduct.productInfo.imagefile || ''
|
||||
const stato = this.getDescrStatiProdottoByIdStatoProdotto(myproduct.productInfo.idStatoProdotto || '')
|
||||
if (addtesto) {
|
||||
descrizione_completa_macro += addstrcontinua;
|
||||
}
|
||||
replacements['{descrizione_estesa}'] = descrizione_completa_macro || '';
|
||||
}
|
||||
|
||||
const scale = optcatalogo.printable ? optcatalogo.areadistampa?.scale : 1
|
||||
// Crea una mappa di sostituzioni
|
||||
const replacements = {
|
||||
'{autore}': autori || '',
|
||||
'{titolo}': myproduct.productInfo.name || '',
|
||||
'{sottotitolo}': (sottotitolo) || '',
|
||||
'{descrizione_da_fdv}': truncatedDescription || '',
|
||||
'{descrizione_estesa_fdv}': truncatedlongDescription || '',
|
||||
'{descrizione_estesa}': descrizione_completa_macro || '',
|
||||
'{debug}': (debugstr) || '',
|
||||
'{categoria}': (categoria) || '',
|
||||
'{sottocategoria}': (sottocategoria) || '',
|
||||
'{descr_categoria}': (descr_categoria) || '',
|
||||
'{pagine}': (pagine) || '',
|
||||
'{isbn}': (isbn) || '',
|
||||
'{misure}': misure || '',
|
||||
'{argomento}': categoria || '',
|
||||
'{date_pub}': date_pub || '',
|
||||
'{ranking_globale}': ranking_globale || '',
|
||||
'{venduti}': venduti || '',
|
||||
'{formato}': formato || '',
|
||||
'{stato}': stato || '',
|
||||
'{collana}': collana ? collana || '' : '',
|
||||
'{prezzo}': prezzo || '',
|
||||
'{scale}': scale || '',
|
||||
'{prezzo_scontato}': prezzo_scontato || '',
|
||||
'{descrizione_completa_macro}': descrizione_completa_macro || '',
|
||||
'{descrizione_breve_macro}': descrizione_breve_macro || '',
|
||||
'{descr_trafiletto_catalogo}': descr_trafiletto_catalogo || '',
|
||||
'{link_macro}': link_macro || '',
|
||||
'{qta}': qta || '',
|
||||
'{image_link}': image_link || '',
|
||||
'{imagefile}': imagefile || '',
|
||||
};
|
||||
if (testo.contenuto.includes('{descrizione_breve_macro}')) {
|
||||
const short_descr = myproduct.productInfo.descrizione_breve_macro || '';
|
||||
replacements['{descrizione_breve_macro}'] = short_descr.length > maxDescriptionLength
|
||||
? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: short_descr;
|
||||
}
|
||||
|
||||
if (testo.contenuto.includes('{descr_trafiletto_catalogo}')) {
|
||||
const short_descr = myproduct.productInfo.descr_trafiletto_catalogo || '';
|
||||
replacements['{descr_trafiletto_catalogo}'] = short_descr.length > maxDescriptionLength
|
||||
? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
|
||||
: short_descr;
|
||||
}
|
||||
|
||||
if (testo.contenuto.includes('{prezzo}') || testo.contenuto.includes('{prezzo_scontato}')) {
|
||||
const prezzo = tools.arrotonda2Dec(myproduct.arrvariazioni![0].price) || '';
|
||||
const prezzo_scontato = tools.arrotonda2Dec(myproduct.arrvariazioni![0].sale_price) || '';
|
||||
replacements['{prezzo}'] = prezzo;
|
||||
replacements['{prezzo_scontato}'] = prezzo_scontato;
|
||||
}
|
||||
|
||||
// Additional replacements based on the content
|
||||
const keysToCheck = [
|
||||
'{titolo}', '{sottotitolo}', '{categoria}', '{sottocategoria}', '{descr_categoria}',
|
||||
'{pagine}', '{isbn}', '{misure}', '{argomento}', '{date_pub}', '{ranking_globale}',
|
||||
'{venduti}', '{formato}', '{tipologia}', '{stato}', '{scale}', '{descr_trafiletto_catalogo}',
|
||||
'{link_macro}', '{qta}', '{image_link}', '{imagefile}', '{debug}'
|
||||
];
|
||||
|
||||
for (const key of keysToCheck) {
|
||||
if (testo.contenuto.includes(key)) {
|
||||
switch (key) {
|
||||
case '{titolo}':
|
||||
replacements[key] = myproduct.productInfo.name || '';
|
||||
break;
|
||||
case '{sottotitolo}':
|
||||
replacements[key] = myproduct.productInfo.sottotitolo || '';
|
||||
break;
|
||||
case '{sottocategoria}':
|
||||
replacements[key] = myproduct.productInfo.subcatprods && myproduct.productInfo.subcatprods.length > 0 ? myproduct.productInfo.subcatprods[0].name! : '';
|
||||
break;
|
||||
case '{descr_categoria}':
|
||||
replacements[key] = myproduct.productInfo.catprods && myproduct.productInfo.catprods.length > 0 ? this.getCatProdDescrStrByIdCatProd(myproduct.productInfo.catprods![0].name) : '';
|
||||
break;
|
||||
case '{pagine}':
|
||||
replacements[key] = myproduct.arrvariazioni![0].pagine || '';
|
||||
break;
|
||||
case '{isbn}':
|
||||
replacements[key] = myproduct.productInfo.code || '';
|
||||
break;
|
||||
case '{misure}':
|
||||
replacements[key] = myproduct.arrvariazioni![0].misure || '';
|
||||
break;
|
||||
case '{argomento}':
|
||||
replacements[key] = this.getCatProdsStrByCatProds(myproduct.productInfo.catprods!) || '';
|
||||
break;
|
||||
case '{date_pub}':
|
||||
replacements[key] = tools.getstrDateShort(myproduct.productInfo.date_pub) || '';
|
||||
break;
|
||||
case '{ranking_globale}':
|
||||
replacements[key] = myproduct.productInfo.rank3M! || '0';
|
||||
break;
|
||||
case '{venduti}':
|
||||
replacements[key] = myproduct.productInfo.totVen! || '0';
|
||||
break;
|
||||
case '{formato}':
|
||||
replacements[key] = this.getDescrByIdTipoFormato(myproduct.arrvariazioni[0].idTipoFormato || 0)
|
||||
break;
|
||||
case '{tipologia}':
|
||||
replacements[key] = this.getDescrByIdTipologia(myproduct.arrvariazioni[0].idTipologia || 0);
|
||||
break;
|
||||
case '{stato}':
|
||||
replacements[key] = this.getDescrStatiProdottoByIdStatoProdotto(myproduct.productInfo.idStatoProdotto || '');
|
||||
break;
|
||||
case '{scale}':
|
||||
replacements[key] = optcatalogo.printable ? optcatalogo.areadistampa?.scale : '1';
|
||||
break;
|
||||
case '{link_macro}':
|
||||
replacements[key] = myproduct.productInfo.link_macro || '';
|
||||
break;
|
||||
case '{qta}':
|
||||
replacements[key] = myproduct.arrvariazioni![0].quantita || '';
|
||||
break;
|
||||
case '{image_link}':
|
||||
replacements[key] = myproduct.productInfo.image_link || '';
|
||||
break;
|
||||
case '{imagefile}':
|
||||
replacements[key] = myproduct.productInfo.imagefile || '';
|
||||
break;
|
||||
case '{debug}':
|
||||
const date_pub = replacements['{date_pub}'] || '';
|
||||
const fatLast6M = myproduct.productInfo.fatLast6M! || 0;
|
||||
const linkvenduti = `<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-ordini-by-idarticolo/${myproduct.productInfo.sku}" target="_blank">${replacements['{venduti}']}</a>`;
|
||||
const vLast3M = myproduct.productInfo.vLast3M! || 0;
|
||||
const vLast6M = myproduct.productInfo.vLast6M! || 0;
|
||||
const linkfatturati = `<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-fatturati-by-idarticolo/${myproduct.productInfo.sku}" target="_blank">${myproduct.productInfo.totFat! || 0}</a>`;
|
||||
const fatLast3M = myproduct.productInfo.fatLast3M! || 0;
|
||||
|
||||
replacements[key] = this.getkeyValStr('Pub:', date_pub) +
|
||||
this.getkeyValStr('fat6M', fatLast6M) +
|
||||
this.getkeyValStr('Ven:', linkvenduti) +
|
||||
this.getkeyValStr('v3M', vLast3M) +
|
||||
this.getkeyValStr('v6M', vLast6M) +
|
||||
this.getkeyValStr('Fatt:', linkfatturati) +
|
||||
this.getkeyValStr('fat3M', fatLast3M);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Esegue le sostituzioni
|
||||
let result = testo.contenuto;
|
||||
@@ -1541,7 +1612,7 @@ export const useProducts = defineStore('Products', {
|
||||
result = result.replace(new RegExp(key, 'g'), value);
|
||||
}
|
||||
|
||||
return result.trim()
|
||||
return result.trim();
|
||||
},
|
||||
|
||||
getSubCatStrByProduct(myproductInfo: IProductInfo): string {
|
||||
|
||||
Reference in New Issue
Block a user