wholesale-vuex
Version:
Commerce vuex module
1,100 lines (1,037 loc) • 40.3 kB
JavaScript
import { snakeCase } from 'lodash'
import humps from 'lodash-humps'
import createHumps from 'lodash-humps/lib/createHumps'
import { getField, updateField } from 'vuex-map-fields'
import wholesaleOrderProcessor from './wholesale_order_processor.service'
import { questionsList,questionsListTest,checkExistOrNot } from './common.service'
const { doPostOne, doPostMultiple, doPatchOne,doFetchAllorderProcessingIo,doDeleteSelected } = wholesaleOrderProcessor
const snakes = createHumps(snakeCase)
export default {
namespaced: true,
state: {
one: null,
inProgress: true,
fetchInProgress: true,
questionsList: [],
currentQuestions: [],
questionsListTest: [],
currentQuestionsTest: [],
currentItem: 0,
oneNewItemList: [],
orderItemList:null,
oneItem: {},
oneNewItemVariantsList: [],
oneItemVariants: {},
oneItemInformationVariantsList: [],
variantsList: [],
oneVariantsObj:{},
originalVariants:[]
},
getters: {
getField,
},
mutations: {
updateField,
setOne(state, one) {
state.one = one;
},
setQuestionsList(state, data) {
state.questionsList = data.questionsList;
if (!state.currentQuestions.length) {
state.currentQuestions = [data.questionsList[0]]
if (state.questionsList[state.currentItem].ioName === 'order_shipping_address') {
if (!state.currentQuestions[state.currentItem].subQuestion[0].ioInput.shippingAddress.countryIso3) {
state.currentQuestions[state.currentItem].subQuestion[0].ioInput.shippingAddress = data.orderOne.shippingAddress
}
/*state.currentQuestions[state.currentItem].subQuestion[0].newAns.shippingAddress = Object.assign({}, state.currentQuestions[state.currentItem].subQuestion[0].oldAns.shippingAddress)
state.currentQuestions[state.currentItem].subQuestion[0].newAns.billingAddress = Object.assign({}, state.currentQuestions[state.currentItem].subQuestion[0].oldAns.billingAddress)*/
}
}
},
setQuestionsListTest(state, data) {
state.questionsListTest = data.questionsListTest;
if (!state.currentQuestionsTest.length) {
state.currentQuestionsTest = [data.questionsListTest[0]]
}
},
resetCurrentQuestions(state){
state.currentQuestionsTest=[]
state.currentQuestions=[]
state.currentItem = 0
},
setFetchQuestionsListTest(state, data) {
state.questionsListTest = humps(questionsListTest[0].list);
data.questionsListTest.map((item)=>{ item.ioInput = JSON.parse(item.ioInput);
item.ioOutput = JSON.parse(item.ioOutput);
if (item.ioName === 'wholesale_order_brand'){
if(item.ioOutput.value.new_brand){
item.userResponse = 'no'
}else{
item.userResponse = 'yes'
}
item.isModify = false
}
if (item.ioName === 'wholesale_order_shipping_delivery_window'){
if(item.ioOutput.value.wholesale_order_shipping_delivery_window_match_confirmation){
item.userResponse = 'yes'
}else{
item.userResponse = 'no'
}
item.isModify = false
}
});
state.currentQuestionsTest=humps(data.questionsListTest)
},
setFetchQuestionsList(state, data) {
state.orderItemList=data.questionsList.filter((item)=>item.ioName === "order_items_list")[0]
state.questionsList = humps(questionsList[0].list);
data.questionsList.map((item)=>{ item.ioInput = JSON.parse(item.ioInput);
item.ioOutput = JSON.parse(item.ioOutput);
item.isModify = true
item.userResponse = 'yes'
if(item.ioName === 'order_shipping_address_matches' && !item.ioOutput.match){
item.userResponse = 'no'
}
if(item.ioName === 'order_billing_address_matches' && !item.ioOutput.match){
item.userResponse = 'no'
}
});
let questionsArray=data.questionsList
let dataList= data.questionsList.map((item)=>{
let newRec = {}
let addresses = []
for (let j = 0; j < questionsArray.length; j++) {
if ((item.ioName ==='order_shipping_address' && questionsArray[j].ioName === 'order_shipping_address_matches')|| (item.ioName ==='order_billing_address' && questionsArray[j].ioName === 'order_billing_address_matches')) {
addresses.push(questionsArray[j])
}
}
newRec = Object.assign({}, item, addresses.length > 0 ?{ subQuestion: [...new Set(addresses)] }:'')
return newRec
}).filter((obj) => (obj.ioName !=='order_shipping_address_matches' || obj.ioName !=='order_billing_address_matches') )
dataList.filter((item)=>{
if(item.ioName === 'order_shipping_address' && !item.subQuestion){
item.subQuestion=state.questionsList.find((item)=>item.ioName === 'order_shipping_address').subQuestion
}
if(item.ioName === 'order_billing_address' && !item.subQuestion){
item.subQuestion=state.questionsList.find((item)=>item.ioName === 'order_billing_address').subQuestion
}
})
let actualQuestions=humps(questionsList[0].list)
let currentQuestions= humps(actualQuestions.map(obj => dataList.find(o => o.ioName === obj.ioName) || obj));
state.currentItem = currentQuestions.lastIndexOf(currentQuestions.slice().reverse().find(item => item.id));
currentQuestions.forEach((item, index) => {
if(index <= state.currentItem){
if(!item.userResponse){
item.userResponse='no'
}
state.currentQuestions.push(item);
}
});
state.currentQuestions.map((item)=>{
if(item.ioName == 'order_shipping_address'){
if (!item.subQuestion[0].ioInput.shippingAddress.countryIso3) {
item.subQuestion[0].ioInput.shippingAddress = data.orderOne.shippingAddress
}
}
if (item.ioName == 'order_billing_address') {
if (!item.subQuestion[0].ioInput.billingAddress.countryIso3) {
item.subQuestion[0].ioInput.billingAddress = data.orderOne.billingAddress
}
}
if (item.ioName == 'po_number') {
if (!item.ioInput.poNumber) {
item.ioInput.poNumber = data.orderOne.poNumber
}
}
if (item.ioName == 'shipping_cost') {
if (!item.ioInput.shippingCost && !item.ioInput.currency) {
item.ioInput.shippingCost = data.orderOne.shippingCost
item.ioInput.currency = data.orderOne.orderCcy
}
}
if (item.ioName == 'order_discount') {
if (!item.ioInput.totalAmount) {
item.ioInput.totalAmount = data.orderOne.totalAmount
}
}
if (item.ioName == 'order_currency') {
if (!item.ioInput.currency) {
item.ioInput.currency = data.orderOne.orderCcy
}
}
})
},
inProgress(state, yesOrNo) {
state.inProgress = yesOrNo
},
fetchInProgress(state, yesOrNo) {
state.fetchInProgress = yesOrNo
},
setCurrentItem(state, currentItem) {
state.currentItem = currentItem
},
setCurrency(state, currency) {
if (currency) {
state.questionsList.map((item) => {
if (item.ioName === 'shipping_cost' || item.ioName === 'order_currency') {
item.ioInput.currency = currency
}
})
state.currentQuestions.map((item) => {
if (item.ioName === 'shipping_cost' || item.ioName === 'order_currency') {
item.ioInput.currency = currency
}
})
}
},
showNextQuestion(state, data) {
state.currentItem += 1
// 7 questions data
/* if (state.questionsList[state.currentItem]) {
if (state.currentItem == state.currentQuestions.length)
state.currentQuestions.push(state.questionsList[state.currentItem])
else state.currentItem = state.currentQuestions.length - 1
if (!state.currentQuestions[state.currentItem].id) {
state.currentQuestions[state.currentItem].isModify = false
}
if (state.questionsList[state.currentItem].ioName == 'order_billing_address') {
if (!state.currentQuestions[state.currentItem].subQuestion[0].ioInput.billingAddress.countryIso3) {
state.currentQuestions[state.currentItem].subQuestion[0].ioInput.billingAddress = data.orderOne.billingAddress
}
}
if (state.questionsList[state.currentItem].ioName == 'po_number') {
if (!state.currentQuestions[state.currentItem].ioInput.poNumber) {
state.currentQuestions[state.currentItem].ioInput.poNumber = data.orderOne.poNumber
}
}
else if (state.questionsList[state.currentItem].ioName == 'shipping_cost') {
if (!state.currentQuestions[state.currentItem].ioInput.shippingCost && !state.currentQuestions[state.currentItem].ioInput.currency) {
state.currentQuestions[state.currentItem].ioInput.shippingCost = data.orderOne.shippingCost
state.currentQuestions[state.currentItem].ioInput.currency = data.orderOne.orderCcy
}
}
else if (state.questionsList[state.currentItem].ioName == 'order_discount') {
if (!state.currentQuestions[state.currentItem].ioInput.totalAmount) {
state.currentQuestions[state.currentItem].ioInput.totalAmount = data.orderOne.totalAmount
}
}
else if (state.questionsList[state.currentItem].ioName == 'order_currency') {
if (!state.currentQuestions[state.currentItem].ioInput.currency) {
state.currentQuestions[state.currentItem].ioInput.currency = data.orderOne.orderCcy
}
}
}*/
if (state.questionsListTest[state.currentItem]) {
// if user opened last exp panel then and then only we push new item
if (state.currentItem == state.currentQuestionsTest.length)
state.currentQuestionsTest.push(state.questionsListTest[state.currentItem])
else state.currentItem = state.currentQuestionsTest.length - 1
}
},
showPreviousQuestion(state) {
state.currentItem -= 1
//state.currentQuestions[state.currentItem].isModify=false
if (state.currentQuestions[state.currentItem]) {
state.currentQuestions.pop()
}
state.currentQuestions[state.currentItem].isModify = false
},
saveUserResponse(state, data) {
// 7 questions data
/*if (data.ioName === 'order_shipping_address') {
data.subQuestion = state.currentQuestions[state.currentItem].subQuestion
}
if (data.ioName === 'order_billing_address') {
data.subQuestion = state.currentQuestions[state.currentItem].subQuestion
}
if (undefined === data.id) {
data.isModify = false
data.userResponse = 'no'
} else {
data.isModify = true
data.userResponse = 'yes'
}
if (data.ioName === 'order_shipping_address_matches') {
if(!data.ioOutput.match){
data.userResponse = 'no'
}
state.currentQuestions[state.currentItem].subQuestion[0] = data
}else if (data.ioName === 'order_billing_address_matches') {
if(!data.ioOutput.match){
data.userResponse = 'no'
}
state.currentQuestions[state.currentItem].subQuestion[0] = data
}else {
state.currentQuestions[state.currentItem] = data
}*/
if (undefined === data.id) {
data.isModify = false
data.userResponse = 'no'
} else {
data.isModify = true
data.userResponse = 'yes'
}
state.currentQuestionsTest[state.currentItem] = data
},
saveInfoOnDocsResponse(state, data) {
if (data.key === 'skuStockKeeping')
state.currentQuestions[state.currentItem].ioInput.skuStockKeeping = data.flag
else if (data.key === 'skuQuantityOrdered')
state.currentQuestions[state.currentItem].ioInput.skuQuantityOrdered = data.flag
else if (data.key === 'skuItemUnitPrice')
state.currentQuestions[state.currentItem].ioInput.skuItemUnitPrice = data.flag
else if (data.key === 'itemCode')
state.currentQuestions[state.currentItem].ioInput.itemCode = data.flag
else if (data.key === 'itemName')
state.currentQuestions[state.currentItem].ioInput.itemName = data.flag
else if (data.key === 'itemUnitPrice')
state.currentQuestions[state.currentItem].ioInput.itemUnitPrice = data.flag
else if (data.key === 'sizeColor')
state.currentQuestions[state.currentItem].ioInput.sizeColor = data.flag
else if (data.key === 'quantityOrdered')
state.currentQuestions[state.currentItem].ioInput.quantityOrdered = data.flag
/* else if (data.key === 'quantity_ordered')
state.currentQuestions[state.currentItem].subQuestion[data.index].type = data.type*/
state.currentQuestions[state.currentItem].userResponse = 'yes' // to check user is on 7th que on UI
//to reflect a changes on UI
/* let objs = Object.assign([], state.currentQuestions)
state.currentQuestions = []
state.currentQuestions = objs*/
},
resetInfoOnDocsResponse(state, data) {
state.currentQuestions[data.index].ioOutput.infoOnOrderDocuments=null
state.currentQuestions[data.index].ioInput={'skuStockKeeping': null,'skuQuantityOrdered': null,'skuItemUnitPrice': null,'itemCode': null,'itemName': null,'itemUnitPrice': null,'sizeColor': null,'quantityOrdered': null}
},
setNewItemList(state) {
let list = [{
totalQuantity: '3',
totalAmount: '500',
sku: 'sku-1',
itemName: 'mobile',
description: 'test',
color: 'red',
category: 'category',
size: 'S',
wholesalePrice: '50',
retailPrice: '50',
uploadStyleImage: '',
hsCode: 'code-1'
}, {
totalQuantity: '3',
totalAmount: '500',
sku: 'sku-2',
itemName: 'mobile',
description: 'test',
color: 'red',
category: 'category-1',
size: 'S,M',
wholesalePrice: '500',
retailPrice: '50',
uploadStyleImage: '',
hsCode: 'code-2'
}];
state.oneNewItemList =
list.filter((item) => {
item.size = item.size.split(",")
return item
})
},
setOneItem(state, oneItem) {
state.oneItem = oneItem;
if (state.oneItem.variants.length > 0 && state.oneItem.format === "sku") {
state.oneVariantsObj = Object.assign({}, state.oneItem.variants[0])
}
},
setOneVariantsItem(state, item){
state.oneItem =state.oneNewItemList.filter((val) => {
if(val.variantsRefCode = item.variantsRefCode)
return item
})[0]
if (state.oneItem.variants.length > 0 && state.oneItem.format === "variant_size_color") {
state.oneVariantsObj = Object.assign({}, state.oneItem.variants[0])
/* size */
// let resultSize = state.one.variants.map(a =>a.size
// );
// let newListSize=(resultSize.toString()).split(",");
// state.oneVariantsObj.size=[...new Set(newListSize)];
let resultSize = []
state.oneItem.variants.filter((a) => {
if (a.size)
resultSize.push(a.size)
});
let newListSize = resultSize && resultSize.length ? (resultSize.toString()).split(",") : null;
state.oneVariantsObj.size = newListSize && newListSize.length ? [...new Set(newListSize)] : null;
/* color */
let resultColor = []
state.oneItem.variants.filter((a) => {
if (a.color)
resultColor.push(a.color)
});
let newListColor = resultColor && resultColor.length ? (resultColor.toString()).split(",") : null;
state.oneVariantsObj.color = newListColor && newListColor.length ? [...new Set(newListColor)] : null;
/* Category */
let resultCategory = state.oneItem.variants.map(a => a.category
);
let newListCategory = (resultCategory.toString()).split(",");
state.oneVariantsObj.category = [...new Set(newListCategory)];
state.variantsList = state.oneItem.variants;
state.originalVariants = state.oneItem.variants;
}
},
addItem(state, item) {
state.oneNewItemList.push(item);
},
setOrderItemsList(state, orderItemsList) {
state.oneNewItemList=[]
let itemList=orderItemsList.list.filter((item)=>item.ioName === 'order_item')
for(let i=0; i < itemList.length;i++){
let item=humps(JSON.parse(itemList[i].ioOutput))
if(item.value.orderItem){
item.value.orderItem.id=itemList[i].id
}
state.oneNewItemList.push(item.value.orderItem)
}
},
setEditItem(state,index) {
state.oneItem.variants=[]
state.oneItem.variants.push(state.oneVariantsObj)
state.oneNewItemList.splice(index,1,state.oneItem)
/* for(let i=0;i <state.oneNewItemList.length;i++){
if(obj.name === state.oneNewItemList[i]){
state.oneNewItemList[i] =obj
debugger
}*/
//}
//state.oneNewItemList.push(state.oneItem);
/*for (let i = 0; i < newArray.length; i++) {
if (newArray[i].totalQuantity) {
let obj = {
totalQuantity: newArray[i].totalQuantity,
totalAmount: newArray[i].totalAmount,
sku: newArray[i].sku,
itemName: newArray[i].itemName,
description: newArray[i].description,
color: newArray[i].color,
category: newArray[i].category,
size: newArray[i].size,
wholesalePrice: newArray[i].wholesalePrice,
retailPrice: newArray[i].retailPrice,
uploadStyleImage: newArray[i].uploadStyleImage,
hsCode: newArray[i].hsCode
};
state.oneNewItemList.push(obj);
} else {
state.oneNewItemList.push(newArray[i]);
}
}*/
},
setDiscountAmount(state, data) {
state.currentQuestions[data.currentItemIndex].ioInput.discountAmount = Math.round(Number(state.currentQuestions[data.currentItemIndex].ioInput.totalAmount) * (Number(state.currentQuestions[data.currentItemIndex].ioInput.discountPercentage) / 100))
},
setDiscountPercentage(state, data) {
state.currentQuestions[data.currentItemIndex].ioInput.discountPercentage = Math.round((Number(state.currentQuestions[data.currentItemIndex].ioInput.discountAmount) / Number(state.currentQuestions[data.currentItemIndex].ioInput.totalAmount)) * 100)// use .toFixed(2) if u want to show 0.55 in discountPercentage field
},
/* Variants parts*/
setNewItemVariantsList(state) {
let list = [{
totalQuantity: '3',
totalAmount: '500',
styleReferenceCode: 'sku-1',
styleName: 'mobile',
description: 'test',
color: 'red',
category: 'category',
size: 'S',
wholesalePrice: '50',
retailPrice: '50',
uploadStyleImage: '',
hsCode: 'code-1'
}, {
totalQuantity: '3',
totalAmount: '500',
styleReferenceCode: 'sku-2',
styleName: 'mobile',
description: 'test',
color: 'red',
category: 'category-1',
size: 'S,M',
wholesalePrice: '500',
retailPrice: '50',
uploadStyleImage: '',
hsCode: 'code-2'
}];
state.oneNewItemVariantsList =
list.filter((item) => {
item.size = item.size.split(",")
item.category = item.category.split(",")
item.color = item.color.split(",")
return item
})
},
setOneItemVariants(state, oneItem) {
state.oneItemVariants = oneItem;
},
addItemVariants(state, item) {
state.oneNewItemVariantsList.push(item);
},
setEditItemVariants(state) {
let newArray = state.oneNewItemVariantsList;
state.oneNewItemVariantsList = [];
for (let i = 0; i < newArray.length; i++) {
if (newArray[i].totalQuantity) {
let obj = {
totalQuantity: newArray[i].totalQuantity,
totalAmount: newArray[i].totalAmount,
styleReferenceCode: newArray[i].styleReferenceCode,
styleName: newArray[i].styleName,
description: newArray[i].description,
color: newArray[i].color,
category: newArray[i].category,
size: newArray[i].size,
wholesalePrice: newArray[i].wholesalePrice,
retailPrice: newArray[i].retailPrice,
uploadStyleImage: newArray[i].uploadStyleImage,
hsCode: newArray[i].hsCode
};
state.oneNewItemVariantsList.push(obj);
} else {
state.oneNewItemVariantsList.push(newArray[i]);
}
}
},
setItemInformationList(state) {
// state.variantsList = []
if(state.variantsList.length <= 0){
state.oneVariantsObj.category.filter((categoryItem) => {
if (state.oneVariantsObj.color && state.oneVariantsObj.color.length > 0) {
// if variants has color and size
state.oneVariantsObj.color.filter((colorItem) => {
if (state.oneVariantsObj.size && state.oneVariantsObj.size.length > 0) {
state.oneVariantsObj.size.filter((sizeItem) => {
state.variantsList.push(
{
sku: state.oneItem.variantsRefCode + '-' + categoryItem + '-' + sizeItem + '-' + colorItem,
category: categoryItem ? categoryItem : null,
size: sizeItem ? sizeItem : null,
color: colorItem ? colorItem : null,
qty: 0,
//qty: state.oneVariantsObj.qty,
retailPrice: state.oneVariantsObj.retailPrice,
wholesalePrice: state.oneVariantsObj.wholesalePrice,
hsCode: ''// state.oneVariantsObj.hsCode
}
)
})
} else {
// if variants has color and no size
state.variantsList.push(
{
sku: state.oneItem.variantsRefCode + '-' + categoryItem + '-' + colorItem,
category: categoryItem,
size: null,
color: colorItem ? colorItem : null,
qty: 0,
//qty: state.oneVariantsObj.qty,
retailPrice: state.oneVariantsObj.retailPrice,
wholesalePrice: state.oneVariantsObj.wholesalePrice,
hsCode: '' //state.oneVariantsObj.hsCode
}
)
}
})
} else if (state.oneVariantsObj.size && state.oneVariantsObj.size.length > 0) {
// if variants has size and no color
state.oneVariantsObj.size.filter((sizeItem) => {
state.variantsList.push(
{
sku: state.oneItem.variantsRefCode + '-' + categoryItem + '-' + sizeItem,
category: categoryItem,
size: sizeItem,
color: null,
qty: 0,
//qty: state.oneVariantsObj.qty,
retailPrice: state.oneVariantsObj.retailPrice,
wholesalePrice: state.oneVariantsObj.wholesalePrice,
hsCode: '' //state.oneVariantsObj.hsCode
}
)
})
} else {
// if variants has no size and no color , only has category
state.variantsList.push(
{
sku: state.oneItem.variantsRefCode + '-' + categoryItem,
category: categoryItem,
size: null,
color: null,
qty: 0,
//qty: state.oneVariantsObj.qty,
retailPrice: state.oneVariantsObj.retailPrice,
wholesalePrice: state.oneVariantsObj.wholesalePrice,
hsCode: '' //state.oneVariantsObj.hsCode
}
)
}
})
} else {
let newColors = checkExistOrNot({oneVariantsObj: state.oneVariantsObj.color,variantsList: state.originalVariants, type: 'color'})
let newCategory = checkExistOrNot({oneVariantsObj: state.oneVariantsObj.category,variantsList: state.originalVariants, type: 'category'})
let newSize = checkExistOrNot({oneVariantsObj: state.oneVariantsObj.size,variantsList: state.originalVariants, type: 'size'})
let newVariantItems = []
state.originalVariants.filter((item)=>{
let flag = false
if(state.oneVariantsObj.category.includes(item.category)){
if(!state.oneVariantsObj.size.includes(item.size)){
flag = true
}
if(!state.oneVariantsObj.color.includes(item.color)){
flag = true
}
if(!flag) {
newVariantItems.push(item)
}
}
})
let totalMixedCategories = [...new Set([...newCategory, ...state.oneVariantsObj.category])]
let totalMixedColors = [...new Set([...newColors, ...state.oneVariantsObj.color])]
let totalMixedSizes = [...new Set([...newSize, ...state.oneVariantsObj.size])]
// if(newCategory.length){
for(let i=0; i< totalMixedCategories.length; i++){
let category = totalMixedCategories[i];
// if(newColors.length){
for(let j=0; j< totalMixedColors.length; j++){
let color = totalMixedColors[j];
// if(newSize.length){
for(let k=0; k< totalMixedSizes.length; k++){
let size = totalMixedSizes[k];
let obj = {
sku: state.oneItem.variantsRefCode + '-' + category + '-' + size + '-' + color,
category: category ? category : null,
size: size ? size : null,
color: color ? color : null,
qty: 0,
retailPrice: state.oneVariantsObj.retailPrice,
wholesalePrice: state.oneVariantsObj.wholesalePrice,
hsCode: ''
}
// avoid duplication
if(!newVariantItems.filter((item => item.sku == obj.sku)).length)
newVariantItems.push(obj)
} // totalMixedSizes
//}
} //totalMixedColors
//}
} // totalMixedCategories
//} //newCategory.length
state.variantsList = [...new Set([...newVariantItems])]
}
/*state.oneItemInformationVariantsList = []
state.oneItemVariants.category.filter((categoryItem) => {
state.oneItemVariants.color.filter((colorItem) => {
state.oneItemVariants.size.filter((sizeItem) => {
state.oneItemInformationVariantsList.push(
{
sku: state.oneItemVariants.styleReferenceCode + '-' + categoryItem + '-' + sizeItem + '-' + colorItem,
category: categoryItem,
size: sizeItem,
color: colorItem,
quantity: 1,
retailPrice: state.oneItemVariants.retailPrice,
wholesalePrice: state.oneItemVariants.wholesalePrice,
codes: state.oneItemVariants.hsCode
}
)
})
})
})*/
},
setNewVariantsList(state) {
state.variantsList = [];
state.originalVariants = []
},
setOneVariantsObj(state, oneItem) {
state.oneVariantsObj = oneItem;
},
},
actions: {
fetchQuestionsList: async ({ commit,dispatch }, { sessionId, appId, orderOne }) => {
commit('fetchInProgress', true)
commit('resetCurrentQuestions')
try {
const list = await doFetchAllorderProcessingIo({ sessionId, appId })
if (list.length > 0) {
let orderShippingAddress = false;
let orderShippingAddressIndex = null;
let orderShippingAddressMatches = false;
let orderBillingAddress = false;
let orderBillingAddressIndex = null;
let orderBillingAddressMatches = false;
for (let j = 0; j < list.length; j++) {
if (list[j].io_name === 'order_shipping_address') {
orderShippingAddress = true
orderShippingAddressIndex=j
}
if (list[j].io_name === 'order_shipping_address_matches') {
orderShippingAddressMatches = true
}
if (list[j].io_name === 'order_billing_address') {
orderBillingAddress = true
orderBillingAddressIndex=j
}
if (list[j].io_name === 'order_billing_address_matches') {
orderBillingAddressMatches = true
}
}
if (!orderShippingAddress || !orderShippingAddressMatches) {
let obj=list.find((item)=>item.io_name === 'order_shipping_address')
if(obj)
list.splice(orderShippingAddressIndex, 1)
dispatch('dataProcessorOne/deleteSelected', {item:obj}, { root: true });
}
if (!orderBillingAddress || !orderBillingAddressMatches) {
let obj=list.find((item)=>item.io_name === 'order_billing_address')
if(obj)
list.splice(orderBillingAddressIndex, 1)
dispatch('dataProcessorOne/deleteSelected', {item:obj}, { root: true });
}
commit('setFetchQuestionsList', await humps({ questionsList: list, orderOne }))
commit('setFetchQuestionsListTest', await humps({ questionsListTest: list, orderOne }))
commit('setOrderItemsList', await humps({ list, orderOne }))
commit('fetchInProgress', false)
return await humps(list)
} else {
commit('setQuestionsList', await humps({ questionsList: questionsList[0].list, orderOne }))
commit('setQuestionsListTest', await humps({ questionsListTest: questionsListTest[0].list, orderOne }))
commit('fetchInProgress', false)
return await humps(questionsList[0].list)
}
}
catch (err) {
throw err
} finally {
commit('fetchInProgress', false)
}
},
showNextQuestion: async ({ commit }, { orderOne }) => {
commit('inProgress', true)
try {
commit('showNextQuestion', humps({ orderOne }))
commit('inProgress', false)
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
showPreviousQuestion: async ({ commit }) => {
commit('inProgress', true)
try {
commit('showPreviousQuestion')
commit('inProgress', false)
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
saveUserResponse: async ({ commit }, { item }) => {
commit('inProgress', true)
try {
if (undefined === item.id) {
let data = await doPostOne(snakes(item))
if(data){
data.io_input = JSON.parse(data.io_input);
data.io_output = JSON.parse(data.io_output);
commit('saveUserResponse', humps(data))
commit('inProgress', false)
}
} else {
let data = await doPatchOne(snakes(item))
if(data){
data.io_input = JSON.parse(data.io_input);
data.io_output = JSON.parse(data.io_output);
commit('saveUserResponse', humps(data))
commit('inProgress', false)
}
}
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
saveOrderItems: async ({ commit }, { items,type } ) => {
commit('inProgress', true)
try {
let data = await doPostMultiple(snakes(items))
if(data){
commit('saveUserResponse', humps(data))
commit('inProgress', false)
}
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
updateOrderItems: async ({ commit,state }, {item,type} ) => {
commit('inProgress', true)
try {
if(type === 'sku'){
state.oneItem.variants=[]
state.oneItem.variants.push(state.oneVariantsObj)
item.io_output.value.order_item=state.oneItem
}else{
state.oneItem.variants=[]
state.oneItem.variants= (state.variantsList).filter(item => item.category.toString())
item.io_output.value.order_item=state.oneItem
}
let data = await doPatchOne(snakes(item))
if(data){
commit('saveUserResponse', humps(data))
commit('inProgress', false)
}
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
saveInfoOnDocsResponse: async ({ commit }, { key, flag }) => {
commit('inProgress', true)
try {
commit('saveInfoOnDocsResponse', { key, flag }) // we will get btn clicked resp of 7th que
commit('inProgress', false)
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
setCurrentItem: async ({ commit }, { currentItem }) => {
commit('inProgress', true)
try {
commit('setCurrentItem', currentItem) // we will get yes/no btn clicked resp 1-6 que
commit('inProgress', false)
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
setCurrency: async ({ commit }, { currency }) => {
commit('inProgress', true)
try {
commit('setCurrency', currency) // we will get yes/no btn clicked resp 1-6 que
commit('inProgress', false)
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
resetInfoOnDocsResponse: async ({ commit }, { index }) => {
commit('inProgress', true)
try {
commit('resetInfoOnDocsResponse', { index }) // we will get btn clicked resp of 7th que
commit('inProgress', false)
}
catch (err) {
throw err
} finally {
commit('inProgress', false)
}
},
deleteSelected: async ({ commit }, {item}) => {
commit('inProgress', true);
try {
await doDeleteSelected({item});
commit('inProgress', false)
return ({ deleteSelected: true })
} catch (err) {
commit('inProgress', false)
return ({ deleteSelected: false })
}
finally {
commit('inProgress', false);
}
},
newItem({ commit },{ appId, purchaseOrderId, purchaserBusinessEntityId, providerBusinessEntityId, brandId ,startDate,endDate,itemsFormat }) {
commit('inProgress', false)
commit('setOneItem', {
'appId': appId,
'purchaseOrderId': purchaseOrderId,
'brandId': brandId ? brandId:'',
'format': itemsFormat,
'lineNumber': 0,
'quantity': 0,
'unitPrice': 0,
'name': '',
//'description': '',
'variantsRefCode': '',
'variants': [],
'description':null,
'purchaserBusinessEntityId': purchaserBusinessEntityId,
'providerBusinessEntityId': providerBusinessEntityId,
'shipmentStartDate':startDate,
'shipmentCancelDate':endDate
})
},
newItemList({ commit }) {
commit('setNewItemList');
},
addNewItem: async ({ commit,state }, item) => {
commit('inProgress', true);
try {
commit('addItem', /*{
totalQuantity: item.totalQuantity,
totalAmount: item.totalAmount,
sku: item.sku,
itemName: item.itemName,
description: item.description,
color: item.color,
category: item.category,
size: item.size,
wholesalePrice: item.wholesalePrice,
retailPrice: item.retailPrice,
uploadStyleImage: item.uploadStyleImage,
hsCode: item.hsCode
}*/
(Object.assign({}, state.oneItem,{
name: item.name,
variantsRefCode: item.variantsRefCode,
variants: [state.oneVariantsObj],
description:item.description})));
commit('inProgress', false);
return ({ new: true });
} catch (err) {
commit('inProgress', false);
throw err;
}
},
addNewItemVariants: async ({ commit,state }, item) => {
commit('inProgress', true);
try {
commit('addItem',
(Object.assign({}, state.oneItem,{
name: item.name,
variantsRefCode: item.variantsRefCode,
variants:(state.variantsList).filter(item => item.category.toString()),
description:item.description})));
commit('inProgress', false);
return ({ new: true });
} catch (err) {
commit('inProgress', false);
throw err;
}
},
editItem({ commit }, item) {
commit('setOneItem', item);
},
editVariantsItem({ commit }, item) {
commit('setOneVariantsItem', item);
},
editSaveItem: async ({ commit },{index}) => {
commit('inProgress', true);
try {
commit('setEditItem',index);
commit('inProgress', false);
return ({ new: true });
} catch (err) {
commit('inProgress', false);
throw err;
}
},
newItemVariants({ commit }) {
commit('setOneItemVariants', {
totalQuantity: '',
totalAmount: '',
styleReferenceCode: '',
styleName: '',
description: '',
color: '',
category: '',
size: '',
wholesalePrice: '',
retailPrice: '',
uploadStyleImage: '',
hsCode: ''
})
// commit('setItemInformationList');
},
newItemVariantsList({ commit }) {
commit('setNewItemVariantsList');
},
newVariantsList: async ({ commit }) => {
//commit('variantsListInProgress', true);
try {
commit('setNewVariantsList');
// commit('variantsListInProgress', false);
} catch (err) {
// commit('variantsListInProgress', false);
}
},
newItemVariant({ commit }) {
commit('setOneVariantsObj', {
sku: '',
category: null,
size: null,
color: null,
qty: '',
retailPrice: '',
wholesalePrice: '',
hsCode: '',
})
},
editItemVariants({ commit }, item) {
commit('setOneItemVariants', item);
commit('setItemInformationList');
},
editSaveItemVariants: async ({ commit }) => {
commit('inProgress', true);
try {
commit('setEditItemVariants');
commit('inProgress', false);
return ({ new: true });
} catch (err) {
commit('inProgress', false);
throw err;
}
},
newItemInformationVariantsList: async ({ commit }) => {
commit('inProgress', true);
try {
commit('setItemInformationList');
commit('inProgress', false);
} catch (err) {
commit('inProgress', false);
}
},
setDiscountAmount: async ({ commit }, { currentItemIndex }) => {
commit('inProgress', true);
try {
commit('setDiscountAmount', { currentItemIndex });
commit('inProgress', false);
} catch (err) {
commit('inProgress', false);
}
},
setDiscountPercentage: async ({ commit }, { currentItemIndex }) => {
commit('inProgress', true);
try {
commit('setDiscountPercentage', { currentItemIndex });
commit('inProgress', false);
} catch (err) {
commit('inProgress', false);
}
},
},
}