aggiornamento visualizzazione Ordini e Carrello

This commit is contained in:
Surya Paolo
2023-12-09 19:38:30 +01:00
parent 2b6411eb77
commit 59c03f28f2
13 changed files with 371 additions and 226 deletions

View File

@@ -32,17 +32,17 @@ export const useProducts = defineStore('Products', {
return state.orders
},
getOrdersCart: (state: IProductsState) => (tipoord: string): IOrderCart[] | undefined => {
getOrdersCart: (state: IProductsState) => (tipoord: number): IOrderCart[] | undefined => {
console.log('state.orders', state.orders)
if (tipoord === 'incorso')
if (tipoord === shared_consts.OrderStatStr.IN_CORSO)
return state.orders.filter((rec: IOrderCart) => (rec.status ? rec.status : 0) <= shared_consts.OrderStatus.CHECKOUT_SENT)
else if (tipoord === 'confermati')
else if (tipoord === shared_consts.OrderStatStr.CONFERMATI)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED)
else if (tipoord === 'pagati')
else if (tipoord === shared_consts.OrderStatStr.PAGATI)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.PAYED)
else if (tipoord === 'completati')
else if (tipoord === shared_consts.OrderStatStr.COMPLETATI)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.RECEIVED)
else if (tipoord === 'cancellati')
else if (tipoord === shared_consts.OrderStatStr.CANCELLATI)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.CANCELED)
},
@@ -54,6 +54,14 @@ export const useProducts = defineStore('Products', {
}
return false
},
getOrderProductInCart: (state: IProductsState) => (idproduct: string): IOrder | null => {
// console.log('.cart.items', this.cart.items)
if (state.cart.items) {
const ris = state.cart.items.find((item: IBaseOrder) => item.order.idProduct === idproduct)
return ris ? ris.order : null
}
return null
},
getRecordEmpty: (state: IProductsState) => (): IProduct => {
@@ -258,7 +266,7 @@ export const useProducts = defineStore('Products', {
})
},
async addToCart({ product, order }: { product: IProduct, order: IOrder }) {
async addToCart({ product, order, addqty }: { product: IProduct, order: IOrder, addqty: boolean }) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
@@ -266,9 +274,41 @@ export const useProducts = defineStore('Products', {
if (!globalStore.site.confpages.enableEcommerce)
return null
const neworder = this.createOrderByProduct(product, order)
let neworder = null;
if (!neworder.idStorehouse)
// Controlla se esiste già nel carrello, allora semplicemente aggiungerò la quantità:
if (this.existProductInCart(product._id)) {
const ordcart = this.getOrderProductInCart(product._id)
if (ordcart) {
if (!addqty && ordcart.quantity === 1) {
// sto per rimuovere l'ultimo pezzo, quindi cancello direttamente
const risrem = await this.removeFromCart({ order: ordcart })
if (risrem) {
order.quantity = 0
return true
} else {
return false
}
}
return await this.addSubQtyToItem({
addqty,
subqty: !addqty,
order: ordcart,
}).then((newqty) => {
order.quantity = newqty
})
}
} else {
if (order.quantity === 0)
order.quantity = 1
neworder = this.createOrderByProduct(product, order)
}
if (neworder && !neworder.idStorehouse)
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store')
console.log('addToCart', 'userid=', userStore.my._id, neworder)
@@ -296,7 +336,7 @@ export const useProducts = defineStore('Products', {
return ris
},
async addSubQtyToItem({ addqty, subqty, order } : { addqty: boolean, subqty: boolean, order: IOrder }) {
async addSubQtyToItem({ addqty, subqty, order }: { addqty: boolean, subqty: boolean, order: IOrder }) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
@@ -331,7 +371,7 @@ export const useProducts = defineStore('Products', {
return ris
},
async UpdateStatusCart({ cart_id, status }: { cart_id:string, status: number }) {
async UpdateStatusCart({ cart_id, status }: { cart_id: string, status: number }) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
@@ -339,8 +379,6 @@ export const useProducts = defineStore('Products', {
if (!globalStore.site.confpages.enableEcommerce)
return null
// console.log('addSubQtyToItem', 'userid=', userStore.my._id, order)
let ris = null
ris = await Api.SendReq('/cart/' + userStore.my._id + '/cartstatus', 'POST', { cart_id, status })
@@ -370,8 +408,6 @@ export const useProducts = defineStore('Products', {
if (!globalStore.site.confpages.enableEcommerce)
return null
// console.log('addSubQtyToItem', 'userid=', userStore.my._id, order)
let ris = null
ris = await Api.SendReq('/cart/' + userStore.my._id + '/orderstatus', 'POST', { order_id, status })

View File

@@ -37,7 +37,7 @@ import { useCircuitStore } from '@store/CircuitStore'
import { routesAdmin } from '@src/router/routesAdmin'
import { routesECommerce } from '@src/router/routesECommerce'
import LandingFooter from '@src/components/LandingFooter/LandingFooter'
import { useProducts } from '@store/Products'
const stateConnDefault = 'online'
@@ -283,6 +283,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
const userStore = useUserStore()
const messageStore = useMessageStore()
const notifStore = useNotifStore()
if (table === costanti.TABEVENTS)
return calendarStore.eventlist
@@ -1498,6 +1499,8 @@ export const useGlobalStore = defineStore('GlobalStore', {
const userStore = useUserStore()
const calendarStore = useCalendarStore()
const circuitStore = useCircuitStore()
const Products = useProducts()
// console.log('calendarStore: loadAfterLogin')
// Load local data
const showall = userStore.isAdmin || userStore.isManager ? '1' : '0'
@@ -1550,13 +1553,13 @@ export const useGlobalStore = defineStore('GlobalStore', {
// console.log('res.data.cart', res.data.cart)
/* if (res.data.cart)
if (res.data.cart)
Products.cart = (res.data.cart) ? { ...res.data.cart } : {}
else
Products.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
Products.orders = (res.data.orders) ? [...res.data.orders] : []
*/
if (showall) {
this.newstosent = (res.data.newstosent) ? [...res.data.newstosent] : []