Ordini
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { ICart, IOrder, IProduct, IProductsState } from 'model'
|
||||
import { ICart, IOrder, IOrderCart, IProduct, IProductsState } from 'model'
|
||||
import { storeBuilder } from './Store/Store'
|
||||
|
||||
import Api from '@api'
|
||||
import { tools } from './tools'
|
||||
import { lists } from './lists'
|
||||
import * as ApiTables from './ApiTables'
|
||||
import { GlobalStore, Todos, UserStore } from '@store'
|
||||
import { GlobalStore, Products, Todos, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { Mutation } from 'vuex-module-decorators'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
@@ -15,10 +15,12 @@ import { costanti } from '@src/store/Modules/costanti'
|
||||
import { IAction } from '@src/model'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
|
||||
const state: IProductsState = {
|
||||
products: [],
|
||||
cart: null,
|
||||
cart: { items: [], totalPrice: 0, totalQty: 0, userId: '' },
|
||||
orders: []
|
||||
}
|
||||
|
||||
// const listFieldsToChange: string [] = ['descr', 'statustodo', 'category', 'expiring_at', 'priority', 'id_prev', 'pos', 'enableExpiring', 'progress', 'phase', 'assigned_to_userId', 'hoursplanned', 'hoursworked', 'start_date', 'completed_at', 'themecolor', 'themebgcolor']
|
||||
@@ -36,7 +38,7 @@ function createOrderByProduct(product: IProduct, order: IOrder): IOrder {
|
||||
idapp: process.env.APP_ID,
|
||||
idProduct: product._id,
|
||||
idProducer: product.idProducer,
|
||||
status: tools.OrderStatus.IN_CART,
|
||||
status: shared_consts.OrderStatus.IN_CART,
|
||||
price: product.price,
|
||||
color: product.color,
|
||||
size: product.size,
|
||||
@@ -71,7 +73,15 @@ namespace Getters {
|
||||
return state.cart
|
||||
}, 'getCart')
|
||||
|
||||
const getOrdersCart = b.read((stateparamf: IProductsState) => (tipoord: string): IOrderCart[] => {
|
||||
if (tipoord === 'incorso')
|
||||
return state.orders.filter((rec) => rec.status <= shared_consts.OrderStatus.CHECKOUT_CONFIRMED)
|
||||
else
|
||||
return state.orders.filter((rec) => rec.status < shared_consts.OrderStatus.RECEIVED && rec.status > shared_consts.OrderStatus.CHECKOUT_CONFIRMED)
|
||||
}, 'getOrdersCart')
|
||||
|
||||
const existProductInCart = b.read((stateparamf: IProductsState) => (idproduct): boolean => {
|
||||
// console.log('.state.cart.items', state.cart.items)
|
||||
const ris = state.cart.items.filter((item) => item.order.idProduct === idproduct).reduce((sum, rec) => sum + 1, 0)
|
||||
return ris > 0
|
||||
}, 'existProductInCart')
|
||||
@@ -83,18 +93,21 @@ namespace Getters {
|
||||
|
||||
const objproduct: IProduct = {
|
||||
// _id: tools.getDateNow().toISOString(), // Create NEW
|
||||
descr: '',
|
||||
idProducer: '',
|
||||
idStorehouses: [],
|
||||
producer: null,
|
||||
storehouses: null,
|
||||
code: '',
|
||||
name: '',
|
||||
description: '',
|
||||
department: '',
|
||||
category: '',
|
||||
price: 0.0,
|
||||
color: '',
|
||||
size: '',
|
||||
quantityAvailable: 0,
|
||||
canBeShipped: false,
|
||||
canBeBuyOnline: false,
|
||||
weight: 0,
|
||||
stars: 0,
|
||||
date: tools.getDateNow(),
|
||||
@@ -114,6 +127,9 @@ namespace Getters {
|
||||
get getCart() {
|
||||
return getCart()
|
||||
},
|
||||
get getOrdersCart() {
|
||||
return getOrdersCart()
|
||||
},
|
||||
get existProductInCart() {
|
||||
return existProductInCart()
|
||||
},
|
||||
@@ -151,9 +167,9 @@ namespace Actions {
|
||||
state.products = []
|
||||
}
|
||||
|
||||
console.log('ARRAY PRODUCTS = ', state.products)
|
||||
// console.log('ARRAY PRODUCTS = ', state.products)
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('dbLoad', 'state.products', state.products)
|
||||
// console.log('dbLoad', 'state.products', state.products)
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -169,6 +185,39 @@ namespace Actions {
|
||||
return ris
|
||||
}
|
||||
|
||||
async function loadProduct(context, { code }) {
|
||||
|
||||
console.log('loadProduct', code)
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
console.log('getProduct', 'code', code)
|
||||
|
||||
// if (UserStore.state.my._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/products/' + code, 'POST', { code })
|
||||
.then((res) => {
|
||||
console.log('product', res.data.product)
|
||||
if (res.data.product) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
return res.data.product
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error getProduct', error)
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, tools.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
return ris
|
||||
}
|
||||
|
||||
async function loadCart(context) {
|
||||
|
||||
console.log('loadCart')
|
||||
@@ -189,7 +238,7 @@ namespace Actions {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
state.cart = res.data.cart
|
||||
} else {
|
||||
state.cart = null
|
||||
state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -212,7 +261,7 @@ namespace Actions {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
state.cart = res.data.cart
|
||||
} else {
|
||||
state.cart = null
|
||||
state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -240,7 +289,7 @@ namespace Actions {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
state.cart = res.data.cart
|
||||
} else {
|
||||
state.cart = null
|
||||
state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -270,7 +319,7 @@ namespace Actions {
|
||||
state.cart = res.data.cart
|
||||
if (!!res.data.qty) {
|
||||
// const ind = state.cart.items.findIndex((rec) => rec.order._id === order._id)
|
||||
// state.cart.items[ind].order.quantity = res.data.qty
|
||||
// state.cart.items[ind].order.quantity = res.data.qty
|
||||
|
||||
return res.data.qty
|
||||
}
|
||||
@@ -288,11 +337,41 @@ namespace Actions {
|
||||
return ris
|
||||
}
|
||||
|
||||
async function UpdateStatusCart(context, { cart_id, status }) {
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
// console.log('addSubQtyToItem', 'userid=', UserStore.state.my._id, order)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + UserStore.state.my._id + '/cartstatus', 'POST', { cart_id, status })
|
||||
.then((res) => {
|
||||
|
||||
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_CONFIRMED) {
|
||||
ProductsModule.state.cart = {}
|
||||
if (res.data.orders)
|
||||
Products.state.orders = res.data.orders
|
||||
}
|
||||
return res.data.status
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error UpdateStatusCart', error)
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, tools.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
return ris
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
// loadCart: b.dispatch(loadCart),
|
||||
loadProduct: b.dispatch(loadProduct),
|
||||
loadProducts: b.dispatch(loadProducts),
|
||||
addToCart: b.dispatch(addToCart),
|
||||
addSubQtyToItem: b.dispatch(addSubQtyToItem),
|
||||
UpdateStatusCart: b.dispatch(UpdateStatusCart),
|
||||
removeFromCart: b.dispatch(removeFromCart),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user