Poter inserire un Ordine anche per un altra persona... (Modalità Cassa)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd } from 'model'
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort } from 'model'
|
||||
|
||||
import { Api } from '@api'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
@@ -107,6 +107,7 @@ export const useProducts = defineStore('Products', {
|
||||
catprods: [],
|
||||
subcatprods: [],
|
||||
productInfos: [],
|
||||
userActive: {username: '', name: '', surname: '', _id: ''},
|
||||
}),
|
||||
|
||||
getters: {
|
||||
@@ -356,7 +357,7 @@ export const useProducts = defineStore('Products', {
|
||||
createOrderByProduct(product: IProduct, order: IOrder): IOrder {
|
||||
const userStore = useUserStore()
|
||||
const myorder: IOrder = {
|
||||
userId: userStore.my._id,
|
||||
userId: this.userActive._id,
|
||||
idapp: process.env.APP_ID,
|
||||
status: shared_consts.OrderStatus.IN_CART,
|
||||
TotalPriceProduct: 0,
|
||||
@@ -379,7 +380,7 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
initcat() {
|
||||
|
||||
// rec.userId = userStore.my._id
|
||||
// rec.userId = this.userActive._id
|
||||
|
||||
return this.getRecordEmpty()
|
||||
|
||||
@@ -401,15 +402,26 @@ export const useProducts = defineStore('Products', {
|
||||
if (!globalStore.site.confpages.enableEcommerce)
|
||||
return null
|
||||
|
||||
// console.log('getProducts', 'userid=', userStore.my._id)
|
||||
// console.log('getProducts', 'userid=', this.userActive._id)
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// if (this.userActive._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/products', 'POST', { userId: userStore.my._id })
|
||||
let myIdActiveSelected = userStore.my._id
|
||||
if (tools.isSeller())
|
||||
myIdActiveSelected = tools.getCookie(tools.COOK_SELCART, userStore.my._id, false)
|
||||
|
||||
const trovato = userStore.usersList.find((user: IUserShort) => user._id === myIdActiveSelected)
|
||||
if (trovato)
|
||||
this.userActive = trovato
|
||||
else
|
||||
this.userActive = userStore.my
|
||||
|
||||
|
||||
ris = await Api.SendReq('/products', 'POST', { userId: this.userActive._id })
|
||||
.then((res) => {
|
||||
if (res.data.products) {
|
||||
// console.log('aggiorna prodotti')
|
||||
@@ -452,7 +464,7 @@ export const useProducts = defineStore('Products', {
|
||||
if (!globalStore.site.confpages.enableEcommerce)
|
||||
return null
|
||||
|
||||
console.log('updateOrderByOrder', 'userid=', userStore.my._id)
|
||||
console.log('updateOrderByOrder', 'userid=', this.userActive._id)
|
||||
|
||||
let ris = null
|
||||
|
||||
@@ -492,7 +504,7 @@ export const useProducts = defineStore('Products', {
|
||||
if (!globalStore.site.confpages.enableEcommerce)
|
||||
return null
|
||||
|
||||
console.log('updateOrdersCartById', 'userid=', userStore.my._id)
|
||||
console.log('updateOrdersCartById', 'userid=', this.userActive._id)
|
||||
|
||||
let ris = null
|
||||
|
||||
@@ -529,7 +541,7 @@ export const useProducts = defineStore('Products', {
|
||||
if (!globalStore.site.confpages.enableEcommerce)
|
||||
return null
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// if (this.userActive._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
@@ -563,13 +575,13 @@ export const useProducts = defineStore('Products', {
|
||||
if (!globalStore.site.confpages.enableEcommerce)
|
||||
return null
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// if (this.userActive._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'GET', null)
|
||||
ris = await Api.SendReq('/cart/' + this.userActive._id, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data && res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.cart = res.data.cart
|
||||
@@ -596,7 +608,7 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
return Api.SendReq('/cart/' + userStore.my._id, 'DELETE', { orderId: order._id })
|
||||
return Api.SendReq('/cart/' + this.userActive._id, 'DELETE', { orderId: order._id })
|
||||
.then((res) => {
|
||||
this.updateDataProduct(res)
|
||||
|
||||
@@ -680,11 +692,11 @@ export const useProducts = defineStore('Products', {
|
||||
// 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)
|
||||
console.log('addToCart', 'userid=', this.userActive._id, neworder)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'POST', { order: neworder })
|
||||
ris = await Api.SendReq('/cart/' + this.userActive._id, 'POST', { order: neworder })
|
||||
.then((res) => {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.cart = res.data.cart
|
||||
@@ -714,11 +726,11 @@ export const useProducts = defineStore('Products', {
|
||||
if (!globalStore.site.confpages.enableEcommerce)
|
||||
return null
|
||||
|
||||
// console.log('addSubQtyToItem', 'userid=', userStore.my._id, order)
|
||||
// console.log('addSubQtyToItem', 'userid=', this.userActive._id, order)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'POST', { addqty, subqty, order })
|
||||
ris = await Api.SendReq('/cart/' + this.userActive._id, 'POST', { addqty, subqty, order })
|
||||
.then((res: any) => {
|
||||
this.updateDataProduct(res)
|
||||
|
||||
@@ -749,7 +761,7 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/createorderscart', 'POST', { cart_id, status, note, options: this.getOptions() })
|
||||
ris = await Api.SendReq('/cart/' + this.userActive._id + '/createorderscart', 'POST', { cart_id, status, note, options: this.getOptions() })
|
||||
.then((res) => {
|
||||
|
||||
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
@@ -811,7 +823,7 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/ordercartstatus', 'POST', { order_id, status, options: this.getOptions() })
|
||||
ris = await Api.SendReq('/cart/' + this.userActive._id + '/ordercartstatus', 'POST', { order_id, status, options: this.getOptions() })
|
||||
.then((res) => {
|
||||
|
||||
this.updateDataProduct(res)
|
||||
@@ -1013,6 +1025,19 @@ export const useProducts = defineStore('Products', {
|
||||
return arrprod.length
|
||||
},
|
||||
|
||||
changeuserActive(valuerec: any) {
|
||||
if (valuerec) {
|
||||
console.log('valuerec', valuerec)
|
||||
tools.setCookie(tools.COOK_SELCART, valuerec._id)
|
||||
this.products = []
|
||||
this.orders = []
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
|
||||
this.loadOrders()
|
||||
this.loadProducts()
|
||||
}
|
||||
},
|
||||
|
||||
async sendMailToTheBuyer(idOrdersCart: string, templemail_id: string, test: boolean) {
|
||||
return await Api.SendReq('/orders/sendmail', 'POST', { templemail_id, idOrdersCart, previewonly: tools.isDebug(), test })
|
||||
.then((res) => {
|
||||
|
||||
Reference in New Issue
Block a user