aggiornamento visualizzazione Ordini e Carrello
This commit is contained in:
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user