diff --git a/src/components/CProductCard/CProductCard.ts b/src/components/CProductCard/CProductCard.ts index 0fa0b6d0..95431550 100755 --- a/src/components/CProductCard/CProductCard.ts +++ b/src/components/CProductCard/CProductCard.ts @@ -57,15 +57,19 @@ export default defineComponent({ const openlistorders = ref(false) const endload = ref(false) + const myproduct = ref({}) const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean) => { // console.log('valoriopt', item.table) return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter) }) - const myproduct = computed((): IProduct => { - return products.getProduct(props.code) - }) + /*const myproduct = computed((): IProduct => { + console.log('getproduct computed') + const ris = products.getProduct(props.code) + console.log(' received', ris) + return ris + })*/ function iconWhishlist(order: IProduct) { @@ -103,6 +107,8 @@ export default defineComponent({ } + updateproduct() + if (ris === null || myorder.quantity === 0) tools.showNotif($q, msg) else @@ -130,6 +136,10 @@ export default defineComponent({ } } + function updateproduct() { + myproduct.value = products.getProduct(props.code) + } + function getStorehouses() { const myarr: any = [] @@ -154,15 +164,8 @@ export default defineComponent({ return false } - function updateQtyAvailable() { - myproduct.value.quantityAvailable = myproduct.value.stockQty - if (myproduct.value.QuantitaOrdinateInAttesa! > 0) { - myproduct.value.quantityAvailable! -= myproduct.value.QuantitaOrdinateInAttesa! - } - } - function getQtyAvailable() { - updateQtyAvailable() + products.updateQuantityAvailable(myproduct.value._id) let qty = myproduct.value.quantityAvailable! return qty } @@ -184,6 +187,8 @@ export default defineComponent({ }) function load() { + updateproduct() + console.log('Load', myproduct.value.name) // console.log('created Cproductcard', code) arrordersCart.value = products.getOrdersCartByIdProduct(myproduct.value._id) @@ -199,7 +204,7 @@ export default defineComponent({ } } - + console.log('°°° ENDLOAD °°°') endload.value = true } @@ -218,8 +223,8 @@ export default defineComponent({ function enableAddQty() { if (site.value.ecomm!.enablePreOrders) { return true - } else { - return getQtyAvailable() > 0 + } else { + return getQtyAvailable() > 0 } } diff --git a/src/components/CProductCard/CProductCard.vue b/src/components/CProductCard/CProductCard.vue index b1cb43f6..58e7bdb5 100755 --- a/src/components/CProductCard/CProductCard.vue +++ b/src/components/CProductCard/CProductCard.vue @@ -51,7 +51,7 @@ myproduct.after_price }} - + diff --git a/src/rootgen/admin/confsite/confsite.ts b/src/rootgen/admin/confsite/confsite.ts index a5708eb1..0cb33d6d 100755 --- a/src/rootgen/admin/confsite/confsite.ts +++ b/src/rootgen/admin/confsite/confsite.ts @@ -10,13 +10,14 @@ import { CMyFieldDb } from '@/components/CMyFieldDb' import { useGlobalStore } from '@store/globalStore' import { costanti } from '@costanti' import { tools } from '@src/store/Modules/tools' +import { ISites } from '@src/model' export default defineComponent({ name: 'Confsite', components: { CImgText, CCard, CMyPage, CTitleBanner, CMyFieldRec, CMyFieldDb }, setup() { - const mysite = ref(null) + const mysite = ref({}) const tab = ref('server') const globalStore = useGlobalStore() diff --git a/src/store/Products.ts b/src/store/Products.ts index c2b36563..004172d9 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -44,7 +44,7 @@ export const useProducts = defineStore('Products', { getProduct: (state: IProductsState) => (code: string): IProduct => { const prod = state.products.find((prod: IProduct) => prod.code === code) - return prod ? prod : { storehouses: [], scontisticas: [] } + return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [] } }, getCart: (state: IProductsState) => (): ICart => { @@ -106,17 +106,20 @@ export const useProducts = defineStore('Products', { getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => { let totalQuantity = 0; + if (state.orders) { const orderscart = state.orders if (orderscart) { for (const myord of orderscart) { - myord.items?.forEach((item: IBaseOrder) => { - if (item.order) { - if (item.order.idProduct === idproduct) { - totalQuantity += item.order.quantity || 0; + if (myord.items) { + for (const item of myord.items) { + if (item.order) { + if (item.order.idProduct === idproduct) { + totalQuantity += item.order.quantity || 0; + } } } - }); + } } } } @@ -124,6 +127,7 @@ export const useProducts = defineStore('Products', { }, getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => { + console.log('getOrdersCartByIdProduct') // console.log('.cart.items', this.cart.items) try { if (state.orders) { @@ -133,6 +137,7 @@ export const useProducts = defineStore('Products', { return item.order.idProduct === idproduct }) }) + console.log('Ordini ', ris) return ris ? ris : [] } } catch (e) { @@ -141,6 +146,17 @@ export const useProducts = defineStore('Products', { return [] }, + updateQuantityAvailable: (state: IProductsState) => (id: string): any => { + + const indelem = state.products.findIndex((prod: IProduct) => prod._id === id) + if (indelem >= 0) { + state.products[indelem].quantityAvailable = state.products[indelem].stockQty + if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) { + state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa! + } + } + + }, getRecordEmpty: (state: IProductsState) => (): IProduct => { const tomorrow = tools.getDateNow()