Corretto incongruenze OrdersCart
This commit is contained in:
@@ -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(<IOrderCart[]>[])
|
||||
const sumval = ref(0)
|
||||
|
||||
const site = ref(globalStore.site)
|
||||
|
||||
const myorder = reactive(<IOrder>{
|
||||
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,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -109,12 +109,12 @@
|
||||
<q-list>
|
||||
<q-item
|
||||
:clickable="tools.isManager()"
|
||||
@click="tools.isManager() ? (openlistorders = true) : null"
|
||||
@click="tools.isManager() ? (visuListDisponibili()) : null"
|
||||
>
|
||||
<q-item-section avatar>
|
||||
<q-icon
|
||||
:color="getQtyAvailable() >= 0 ? 'green' : 'blue'"
|
||||
:name="getQtyAvailable() >= 0 ? 'fas fa-store' : 'fas fa-edit'"
|
||||
color="green"
|
||||
name="fas fa-store"
|
||||
/>
|
||||
</q-item-section>
|
||||
|
||||
@@ -146,9 +146,9 @@
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item
|
||||
v-if="getQtyBookableAvailable() > 0"
|
||||
v-if="getQtyBookableAvailable() > 0 || (myproduct.bookableQty > 0)"
|
||||
:clickable="tools.isManager()"
|
||||
@click="tools.isManager() ? (openlistorders = true) : null"
|
||||
@click="tools.isManager() ? (visuListBookable()) : null"
|
||||
>
|
||||
<q-item-section avatar>
|
||||
<q-icon color="blue" name="fas fa-edit" />
|
||||
@@ -210,7 +210,6 @@
|
||||
class="self-center no-outline"
|
||||
tabindex="0"
|
||||
>
|
||||
Preord.: {{ myorder.quantitypreordered }}
|
||||
</div>
|
||||
</template>
|
||||
</q-field>
|
||||
@@ -298,7 +297,7 @@
|
||||
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="(ordcart, index) of arrordersCart"
|
||||
v-for="(ordcart, index) of listord"
|
||||
:key="index"
|
||||
class="listaev listaev__table"
|
||||
>
|
||||
@@ -347,7 +346,7 @@
|
||||
<td class="text-center">
|
||||
Totali:
|
||||
<span class="totali">{{
|
||||
products.getSumQtyOrderProductInOrdersCart(myproduct._id)
|
||||
sumval
|
||||
}}</span>
|
||||
</td>
|
||||
<td> </td>
|
||||
|
||||
@@ -1,45 +1,89 @@
|
||||
<template>
|
||||
<div v-if="order && order.product" class="q-pa-xs q-gutter-xs">
|
||||
|
||||
<div v-if="order.product" class="row items-center justify-evenly no-wrap">
|
||||
<div class="col-2 text-h6 ellipsis">
|
||||
<q-img v-if="order.product && order.product.img" :src="`` + order.product.img" :alt="order.product.name"
|
||||
:class="myimgclass">
|
||||
<q-img
|
||||
v-if="order.product && order.product.img"
|
||||
:src="`` + order.product.img"
|
||||
:alt="order.product.name"
|
||||
:class="myimgclass"
|
||||
>
|
||||
</q-img>
|
||||
</div>
|
||||
<div class="col-4 q-ml-xs">
|
||||
{{ order.product.name }}
|
||||
<div v-if="showall">
|
||||
<br><span class="text-grey">{{ order.product.description }}</span>
|
||||
<br /><span class="text-grey">{{ order.product.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<div class="row q-mb-xs no-wrap items-center centeritems">
|
||||
<q-btn v-if="showall && !nomodif" round size="xs" text-color="grey" icon="fas fa-minus"
|
||||
@click="addsubqty(false, true)"></q-btn>
|
||||
<!--<q-field outlined dense style="width: 25px; height: 20px; " class="q-mx-xs text-subtitle4">
|
||||
<template v-slot:control>
|
||||
<div class="self-center no-outline" tabindex="0" >{{ order.quantity }}</div>
|
||||
</template>
|
||||
</q-field>-->
|
||||
<div v-if="order.quantity > 0" :class="`q-mx-sm text-blue-14`">{{ order.quantity + order.quantitypreordered }}</div>
|
||||
<q-btn v-if="showall && !nomodif" round size="xs" text-color="grey" icon="fas fa-plus"
|
||||
@click="addsubqty(true, false)"></q-btn>
|
||||
<q-btn
|
||||
v-if="showall && !nomodif"
|
||||
round
|
||||
size="xs"
|
||||
text-color="grey"
|
||||
icon="fas fa-minus"
|
||||
@click="addsubqty(false, true)"
|
||||
></q-btn>
|
||||
<div v-if="order.quantity > 0" :class="`q-mx-sm text-blue-14`">
|
||||
{{ order.quantity }}
|
||||
</div>
|
||||
<div v-if="order.quantity > 0 && order.quantitypreordered > 0">
|
||||
+ {{ $t('ecomm.preord') }}:
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="order.quantitypreordered > 0"
|
||||
:class="`q-mx-sm text-blue-14`"
|
||||
>
|
||||
{{ order.quantitypreordered }}
|
||||
</div>
|
||||
<q-btn
|
||||
v-if="showall && !nomodif"
|
||||
round
|
||||
size="xs"
|
||||
text-color="grey"
|
||||
icon="fas fa-plus"
|
||||
@click="addsubqty(true, false)"
|
||||
></q-btn>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2 no-wrap text-subtitle3_short q-mr-sm">
|
||||
<span :class="isApplicatoSconto() ? 'ordine_scontato_nuovo' : ''">€ {{ order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0 }}</span>
|
||||
<span :class="isApplicatoSconto() ? 'ordine_scontato_nuovo' : ''"
|
||||
>€ {{
|
||||
order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0
|
||||
}}</span
|
||||
>
|
||||
<span v-if="isApplicatoSconto()">
|
||||
<span class="ordine_scontato">(<span class="barrato">€ {{((order.price * order.quantity) + (order.price * order.quantitypreordered)).toFixed(2) }}</span>)</span>
|
||||
<span class="ordine_scontato"
|
||||
>(<span class="barrato"
|
||||
>€
|
||||
{{
|
||||
(
|
||||
order.price * order.quantity +
|
||||
order.price * order.quantitypreordered
|
||||
).toFixed(2)
|
||||
}}</span
|
||||
>)</span
|
||||
>
|
||||
</span>
|
||||
<span v-if="isApplicatoSconto()" class="ordine_scritta_sconto">{{ $t('ecomm.sconto_applicato', {risparmio: getRisparmio()}) }}</span>
|
||||
<span v-if="isApplicatoSconto()" class="ordine_scritta_sconto">{{
|
||||
$t('ecomm.sconto_applicato', { risparmio: getRisparmio() })
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="col-1">
|
||||
<q-btn v-if="!nomodif" icon="fas fa-times" color="negative" round size="xs" @click="removeFromCard">
|
||||
<q-btn
|
||||
v-if="!nomodif"
|
||||
icon="fas fa-times"
|
||||
color="negative"
|
||||
round
|
||||
size="xs"
|
||||
@click="removeFromCard"
|
||||
>
|
||||
</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}})<br />
|
||||
</div>
|
||||
</div>
|
||||
@@ -141,7 +141,7 @@
|
||||
<div v-for="(item, index) of props.row.items" :key="index">
|
||||
<div v-if="!!item.order && item.order.product">
|
||||
{{ item.order.product.name }} ({{
|
||||
productStore.getQuantityByOrder(item.order)
|
||||
productStore.getQuantityByOrder($t, item.order)
|
||||
}})<br />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user