diff --git a/src/components/CProductCard/CProductCard.ts b/src/components/CProductCard/CProductCard.ts index 7a60817a..2056283f 100755 --- a/src/components/CProductCard/CProductCard.ts +++ b/src/components/CProductCard/CProductCard.ts @@ -10,7 +10,7 @@ import { CCopyBtn } from '../CCopyBtn' import { func_tools, toolsext } from '@store/Modules/toolsext' -import { IOrder, IOrderCart, IProduct } from '@src/model' +import { IBaseOrder, IOrder, IOrderCart, IProduct } from '@src/model' import { tools } from '@store/Modules/tools' import { useProducts } from '@store/Products' @@ -43,11 +43,15 @@ export default defineComponent({ const globalStore = useGlobalStore() const products = useProducts() + const listord = ref([]) + const sumval = ref(0) + const site = ref(globalStore.site) const myorder = reactive({ idapp: process.env.APP_ID, quantity: 0, + quantitypreordered: 0, idStorehouse: '', idProvider: '' }) @@ -87,7 +91,11 @@ export default defineComponent({ return false } - await products.addtoCartBase({ $q, t, code: myproduct.value.code!, order: myorder, addqty: add }) + const ris = await products.addtoCartBase({ $q, t, code: myproduct.value.code!, order: myorder, addqty: add }) + updateproduct() + if (ris && ris.myord) { + + } } function getnumstore() { @@ -214,16 +222,36 @@ export default defineComponent({ function enableAddQty() { if (site.value.ecomm && site.value.ecomm.enablePreOrders) { - return true + return getQtyBookableAvailable() > 0 || getQtyAvailable() > 0 } else { return getQtyAvailable() > 0 } } + function visuListDisponibili() { + openlistorders.value = true + sumval.value = products.getSumQtyOrderProductInOrdersCart(myproduct.value._id) + + listord.value = arrordersCart.value.filter((ordercart: IOrderCart) => ordercart.items!.reduce((accumulator, item) => { + return accumulator + item.order.quantity + }, 0)) + } + + function visuListBookable() { + openlistorders.value = true + sumval.value = products.getSumQtyPreOrderInOrdersCart(myproduct.value._id) + + listord.value = arrordersCart.value.filter((ordercart: IOrderCart) => ordercart.items!.reduce((accumulator, item) => { + return accumulator + item.order.quantitypreordered + }, 0)) + } + onMounted(load) return { + visuListDisponibili, + visuListBookable, addtoCart, iconWhishlist, getmycardcl, @@ -251,6 +279,8 @@ export default defineComponent({ site, getQtyWarnPreOrdered, getQtyBookableAvailable, + listord, + sumval, } } }) diff --git a/src/components/CProductCard/CProductCard.vue b/src/components/CProductCard/CProductCard.vue index 9e774f2e..e7e1a1ea 100755 --- a/src/components/CProductCard/CProductCard.vue +++ b/src/components/CProductCard/CProductCard.vue @@ -109,12 +109,12 @@ @@ -146,9 +146,9 @@ @@ -210,7 +210,6 @@ class="self-center no-outline" tabindex="0" > - Preord.: {{ myorder.quantitypreordered }} @@ -298,7 +297,7 @@ @@ -347,7 +346,7 @@ Totali: {{ - products.getSumQtyOrderProductInOrdersCart(myproduct._id) + sumval }}   diff --git a/src/components/CSingleCart/CSingleCart.vue b/src/components/CSingleCart/CSingleCart.vue index ae745d84..bbbd758f 100755 --- a/src/components/CSingleCart/CSingleCart.vue +++ b/src/components/CSingleCart/CSingleCart.vue @@ -1,45 +1,89 @@ diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index 80bd1958..3e30b08c 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -1651,7 +1651,8 @@ const msg_it = { ord_not_confirmed: 'E\' avvenuto un errore. Ordine non Confermato. Ricaricare la pagina e riprovare.', btn_cassa: 'Vai alla Cassa', available: 'Disponibili', - preorders: 'In Prenotazione', + preorders: 'Pre-Ordinabili', + preord: 'Pre-Ordinate', di_cui_x_in_carrello: '(nel tuo carrello: {qty})', evaso: 'Ordine Evaso', consegnato: 'Ordine Consegnato', diff --git a/src/store/Products.ts b/src/store/Products.ts index 91b8fb26..a2f263fe 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -123,6 +123,28 @@ export const useProducts = defineStore('Products', { return null }, + getSumQtyPreOrderInOrdersCart: (state: IProductsState) => (idproduct: string): number => { + let totalQuantity = 0; + + if (state.orders) { + const orderscart = state.orders + if (orderscart) { + for (const myord of orderscart) { + if (myord.items) { + for (const item of myord.items) { + if (item.order) { + if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) { + totalQuantity += (item.order.quantitypreordered) || 0; + } + } + } + } + } + } + } + return totalQuantity + }, + getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => { let totalQuantity = 0; @@ -134,7 +156,7 @@ export const useProducts = defineStore('Products', { for (const item of myord.items) { if (item.order) { if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) { - totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0; + totalQuantity += (item.order.quantity) || 0; } } } @@ -183,22 +205,6 @@ 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! - } - state.products[indelem].bookableAvailableQty = state.products[indelem].bookableQty - if (state.products[indelem].QuantitaPrenotateInAttesa! > 0) { - state.products[indelem].bookableAvailableQty! -= state.products[indelem].QuantitaPrenotateInAttesa! - } - } - - },*/ - getRecordEmpty: (state: IProductsState) => (): IProduct => { const tomorrow = tools.getDateNow() @@ -461,16 +467,15 @@ export const useProducts = defineStore('Products', { } } else { if (this.isQtyAvailableByProduct(product)) { - order.quantitypreordered = 0 order.quantity = 1 + order.quantitypreordered = 0 } else { if (this.isInPreorderByProduct(product)) { - order.quantity = 0 order.quantitypreordered = 1 + order.quantity = 0 } } - if (!order.idStorehouse) { if (product.storehouses.length === 1) { order.idStorehouse = product.storehouses[0]._id @@ -500,7 +505,7 @@ export const useProducts = defineStore('Products', { } this.updateDataProduct(res) - return { risult: !!res } + return { risult: !!res, myord: res.data.myord } }) .catch((error) => { console.log('error addToCart', error) @@ -631,49 +636,87 @@ export const useProducts = defineStore('Products', { async addtoCartBase({ $q, t, code, order, addqty }: { $q: any, t: any, code: string, order: IOrder, addqty: boolean }) { let product = this.getProductByCode(code) - return this.addToCart({ product, order, addqty }).then((ris) => { - let strprod = t('ecomm.prodotto') + return await this.addToCart({ product, order, addqty }) + .then((ris) => { + let strprod = t('ecomm.prodotto') - let msg = '' - console.log('ris', ris) - if (ris === null || ris.myord == null) { - msg = t('ecomm.error_cart') - tools.showNegativeNotif($q, msg) - return - } else { - - let qta = ris.myord.quantity + ris.myord.quantitypreordered - if (qta > 1 || qta === 0) - strprod = t('ecomm.prodotti') - - if (qta === 0) { + let msg = '' + console.log('ris', ris) + if (ris && ris.myord == null) { msg = t('ecomm.prodotto_tolto') + tools.showNotif($q, msg) + return + } + if (ris === null || ris.myord == null) { + msg = t('ecomm.error_cart') + tools.showNegativeNotif($q, msg) + return } else { - msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta }) + + let qta = ris.myord.quantity + ris.myord.quantitypreordered + if (qta > 1 || qta === 0) + strprod = t('ecomm.prodotti') + + if (qta > 0) { + msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta }) + } + } - } + //updateproduct() - //updateproduct() + if (ris === null || ris.myord.quantity === 0) + tools.showNotif($q, msg) + else + tools.showPositiveNotif($q, msg) - if (ris === null || ris.myord.quantity === 0) - tools.showNotif($q, msg) - else - tools.showPositiveNotif($q, msg) - - }) + return ris + }) }, - getQuantityByOrder(order: IOrder): string { + getQuantityByOrder($t: any, order: IOrder): string { let mystr = ''; if (order.quantity > 0) { mystr += order.quantity } + if ((order.quantitypreordered > 0) && (order.quantity > 0)) { + mystr += ' ' + $t('ecomm.available') + mystr += ' + ' + } if (order.quantitypreordered > 0) { - mystr += ' Prenotata :' + order.quantitypreordered + mystr += ' ' + order.quantitypreordered + ' ' + $t('ecomm.preord'); } return mystr }, + + isQtyAvailableByProduct(product: IProduct): boolean { + if (product) { + return (product.quantityAvailable! > 0) + } + return false; + }, + + isInPreorderByProduct(product: IProduct): boolean { + if (product) { + return (product.bookableAvailableQty! > 0) + } + return false; + }, + + isQtyAvailableByOrder(order: IOrder): boolean { + if (order && order.product) { + return this.isQtyAvailableByProduct(order.product) + } + return false; + }, + + isInPreorderByOrder(order: IOrder): boolean { + if (order && order.product) { + return this.isInPreorderByProduct(order.product) + } + return false; + }, + }, }) diff --git a/src/views/ecommerce/checkOut/checkOut.ts b/src/views/ecommerce/checkOut/checkOut.ts index 15db645f..b9fdebcc 100755 --- a/src/views/ecommerce/checkOut/checkOut.ts +++ b/src/views/ecommerce/checkOut/checkOut.ts @@ -183,7 +183,7 @@ export default defineComponent({ const myprod = productStore.getProductByCode(lowerSearchText); if (myprod && myprod.active) { - let myorder: IOrder = { quantity: 1, price: 0, TotalPriceProduct: 0 } + let myorder: IOrder = { quantity: 1, quantitypreordered: 0, price: 0, TotalPriceProduct: 0 } await productStore.addtoCartBase({ $q, t, code: myprod.code!, order: myorder, addqty: true }) search.value = '' load() diff --git a/src/views/ecommerce/orderInfo/orderInfo.vue b/src/views/ecommerce/orderInfo/orderInfo.vue index 31e2a655..cc796023 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.vue +++ b/src/views/ecommerce/orderInfo/orderInfo.vue @@ -57,7 +57,7 @@ v-if="!!item && item.order && item.order.product" > {{ item.order.product.name }} ({{ - productStore.getQuantityByOrder(item.order) + productStore.getQuantityByOrder($t, item.order) }})
@@ -141,7 +141,7 @@
{{ item.order.product.name }} ({{ - productStore.getQuantityByOrder(item.order) + productStore.getQuantityByOrder($t, item.order) }})