Skip to content

Commit

Permalink
Merge pull request #364 from amansinghbais/bopis/#358
Browse files Browse the repository at this point in the history
Implemented: dropdown for other shipments in a order in order details page (#358)
  • Loading branch information
ravilodhi committed Jun 14, 2024
2 parents c2e17f2 + d44c387 commit 10b3da5
Show file tree
Hide file tree
Showing 14 changed files with 536 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"Choose language": "Choose language",
"City": "City",
"Click the backdrop to dismiss.": "Click the backdrop to dismiss.",
"Color:": "Color: {color}",
"Colors": "Colors",
"Complete": "Complete",
"Completed": "Completed",
Expand Down Expand Up @@ -114,6 +115,7 @@
"Orders": "Orders",
"Orders Not Found": "Orders Not Found",
"Order item rejection history": "Order item rejection history",
"Other shipments in this order": "Other shipments in this order",
"Order reservations": "Order reservations",
"order reservations at": "{ count } order reservations at { store }",
"Other stores": "Other stores",
Expand All @@ -123,6 +125,7 @@
"Packing slips help customer reconcile their order against the delivered items.": "Packing slips help customer reconcile their order against the delivered items.",
"Partial Order rejection": "Partial Order rejection",
"Password": "Password",
"Pending allocation": "Pending allocation",
"pending approval": "pending approval",
"Picked by": "Picked by { pickers }",
"Pick up location": "Pick up location",
Expand Down Expand Up @@ -169,6 +172,7 @@
"Ship to this address": "Ship to this address",
"Shop": "Shop",
"Show shipping orders": "Show shipping orders",
"Size:": "Size: {size}",
"Sizes": "Sizes",
"Something went wrong": "Something went wrong",
"Something went wrong, could not edit picker.": "Something went wrong, could not edit picker.",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"Orders": "Órdenes",
"Orders Not Found": "Órdenes no encontradas",
"Order item rejection history": "Historial de rechazo de artículos de pedido",
"Other shipments in this order": "Other shipments in this order",
"Order reservations": "Order reservations",
"order reservations at": "{ count } order reservations at { store }",
"Other stores": "Otras tiendas",
Expand All @@ -120,6 +121,7 @@
"Packing slips help customer reconcile their order against the delivered items.": "Las remisiones de embalaje ayudan al cliente a conciliar su orden con los artículos entregados.",
"Partial Order rejection": "Rechazo parcial del pedido",
"Password": "Contraseña",
"Pending allocation": "Pending allocation",
"pending approval": "pendiente de aprobación",
"Picked by": "Recogido por { pickers }",
"Pick up location": "Ubicación de recogida",
Expand Down
43 changes: 43 additions & 0 deletions src/services/OrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,52 @@ const getShippingPhoneNumber = async (orderId: string): Promise<any> => {
return phoneNumber
}

const findOrderShipGroup = async (query: any): Promise<any> => {
return api({
url: "solr-query",
method: "post",
data: query
});
}

const fetchTrackingCodes = async (shipmentIds: Array<string>): Promise<any> => {
let shipmentTrackingCodes = [];
const params = {
"entityName": "ShipmentPackageRouteSeg",
"inputFields": {
"shipmentId": shipmentIds,
"shipmentId_op": "in",
"shipmentItemSeqId_op": "not-empty"
},
"fieldList": ["shipmentId", "shipmentPackageSeqId", "trackingCode"],
"viewSize": 250, // maximum records we could have
"distinct": "Y"
}

try {
const resp = await api({
url: "performFind",
method: "get",
params
})

if (!hasError(resp)) {
shipmentTrackingCodes = resp?.data.docs;
} else if (!resp?.data.error || (resp.data.error && resp.data.error !== "No record found")) {
return Promise.reject(resp?.data.error);
}
} catch (err) {
console.error('Failed to fetch tracking codes for shipments', err)
}

return shipmentTrackingCodes;
}

export const OrderService = {
fetchOrderItems,
fetchOrderPaymentPreferences,
fetchTrackingCodes,
findOrderShipGroup,
getOpenOrders,
getOrderDetails,
getCompletedOrders,
Expand Down
18 changes: 18 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ const resetPicker = async (payload: any): Promise<any> => {
})
}

const fetchFacilityTypeInformation = async (query: any): Promise<any> => {
return api({
url: "performFind",
method: "get",
params: query
});
}

const fetchPartyInformation = async (query: any): Promise<any> => {
return api({
url: "performFind",
method: "get",
params: query
});
}

const fetchReservedQuantity = async (query: any): Promise <any> => {
return api({
url: "solr-query",
Expand All @@ -42,6 +58,8 @@ const fetchReservedQuantity = async (query: any): Promise <any> => {
}

export const UtilService = {
fetchFacilityTypeInformation,
fetchPartyInformation,
fetchPaymentMethodTypeDesc,
fetchRejectReasons,
fetchStatusDesc,
Expand Down
164 changes: 160 additions & 4 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { translate } from "@hotwax/dxp-components";
import emitter from '@/event-bus'
import store from "@/store";
import { prepareOrderQuery } from "@/utils/solrHelper";
import { getOrderCategory } from "@/utils/order";
import logger from "@/logger";

const actions: ActionTree<OrderState , RootState> ={
Expand Down Expand Up @@ -168,7 +169,8 @@ const actions: ActionTree<OrderState , RootState> ={
return arr
}, []),
placedDate: orderItem.orderDate,
shippingInstructions: orderItem.shippingInstructions
shippingInstructions: orderItem.shippingInstructions,
shipGroupSeqId: orderItem.shipGroupSeqId
}
})

Expand Down Expand Up @@ -213,6 +215,7 @@ const actions: ActionTree<OrderState , RootState> ={
// As one order can have multiple parts thus checking orderId and partSeq as well before making any api call
if(current.orderId === payload.orderId && current.orderType === orderType && current.part?.orderPartSeqId === payload.orderPartSeqId) {
this.dispatch('product/getProductInformation', { orders: [ current ] })
await dispatch('fetchShipGroupForOrder');
return current
}
if(orders.length) {
Expand Down Expand Up @@ -304,8 +307,9 @@ const actions: ActionTree<OrderState , RootState> ={
await dispatch('updateCurrent', { order: currentOrder })
},

updateCurrent ({ commit }, payload) {
async updateCurrent ({ commit, dispatch }, payload) {
commit(types.ORDER_CURRENT_UPDATED, { order: payload.order })
await dispatch('fetchShipGroupForOrder');
},

async getPackedOrders ({ commit, state }, payload) {
Expand Down Expand Up @@ -370,7 +374,8 @@ const actions: ActionTree<OrderState , RootState> ={
ids.push(picker.split('/')[0]);
return ids;
}, [])) : "",
picklistId: orderItem.picklistId
picklistId: orderItem.picklistId,
shipGroupSeqId: orderItem.shipGroupSeqId
}
})
this.dispatch('product/getProductInformation', { orders });
Expand Down Expand Up @@ -439,7 +444,8 @@ const actions: ActionTree<OrderState , RootState> ={

return arr
}, []),
placedDate: orderItem.orderDate
placedDate: orderItem.orderDate,
shipGroupSeqId: orderItem.shipGroupSeqId
}
})
this.dispatch('product/getProductInformation', { orders });
Expand Down Expand Up @@ -1010,6 +1016,156 @@ const actions: ActionTree<OrderState , RootState> ={
}
commit(types.ORDER_CURRENT_UPDATED, { order });
},

async fetchShipGroupForOrder({ dispatch, state }) {
const order = JSON.parse(JSON.stringify(state.current))

// return if orderId is not found on order
if (!order?.orderId) {
return;
}

const params = {
groupBy: 'shipGroupSeqId',
'shipGroupSeqId': '[* TO *]', // check to ignore all those records for which shipGroupSeqId is not present
'-shipGroupSeqId': order.shipGroupSeqId,
orderId: order.orderId,
docType: 'ORDER'
}

const orderQueryPayload = prepareOrderQuery(params)

let resp, total, shipGroups = [];

Check warning on line 1038 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'total' is defined but never used

Check warning on line 1038 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'total' is defined but never used

Check warning on line 1038 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'total' is defined but never used
const facilityTypeIds: Array<string> = [];

try {
resp = await OrderService.findOrderShipGroup(orderQueryPayload);

if (resp.status === 200 && !hasError(resp) && resp.data.grouped?.shipGroupSeqId.matches > 0) {
shipGroups = resp.data.grouped.shipGroupSeqId.groups
} else {
throw resp.data
}
} catch (err) {
console.error('Failed to fetch ship group information for order', err)
}

// return if shipGroups are not found for order
if (!shipGroups.length) {
return;
}

shipGroups = shipGroups.map((shipGroup: any) => {
const shipItem = shipGroup?.doclist?.docs[0]

if (!shipItem) {
return;
}

// In some case we are not having facilityTypeId in resp, resulting in undefined being pushed in the array
// so checking for facilityTypeId before updating the array
shipItem.facilityTypeId && facilityTypeIds.push(shipItem.facilityTypeId)

return {
items: shipGroup.doclist.docs,
facilityId: shipItem.facilityId,
facilityTypeId: shipItem.facilityTypeId,
facilityName: shipItem.facilityName,
shippingMethod: shipItem.shippingMethod,
orderId: shipItem.orderId,
shipGroupSeqId: shipItem.shipGroupSeqId
}
})

this.dispatch('util/fetchFacilityTypeInformation', facilityTypeIds)

// fetching reservation information for shipGroup from OISGIR doc
await dispatch('fetchAdditionalShipGroupForOrder', { shipGroups });
},

async fetchAdditionalShipGroupForOrder({ commit, state }, payload) {
const order = JSON.parse(JSON.stringify(state.current))


// return if orderId is not found on order
if (!order?.orderId) {
return;
}

const shipGroupSeqIds = payload.shipGroups.map((shipGroup: any) => shipGroup.shipGroupSeqId)
const orderId = order.orderId

const params = {
groupBy: 'shipGroupSeqId',
'shipGroupSeqId': `(${shipGroupSeqIds.join(' OR ')})`,
'-fulfillmentStatus': '(Rejected OR Cancelled)',
orderId: orderId
}

const orderQueryPayload = prepareOrderQuery(params)

let resp, total, shipGroups: any = [];

try {
resp = await OrderService.findOrderShipGroup(orderQueryPayload);
if (resp.status === 200 && !hasError(resp) && resp.data.grouped?.shipGroupSeqId.matches > 0) {
total = resp.data.grouped.shipGroupSeqId.ngroups
shipGroups = resp.data.grouped.shipGroupSeqId.groups
} else {
throw resp.data
}
} catch (err) {
console.error('Failed to fetch ship group information for order', err)
}

shipGroups = payload.shipGroups.map((shipGroup: any) => {
const reservedShipGroupForOrder = shipGroups.find((group: any) => shipGroup.shipGroupSeqId === group.doclist?.docs[0]?.shipGroupSeqId)

const reservedShipGroup = reservedShipGroupForOrder?.groupValue ? reservedShipGroupForOrder.doclist.docs[0] : ''

return reservedShipGroup ? {
...shipGroup,
items: reservedShipGroupForOrder.doclist.docs,
carrierPartyId: reservedShipGroup.carrierPartyId,
shipmentId: reservedShipGroup.shipmentId,
category: getOrderCategory(reservedShipGroupForOrder.doclist.docs[0])
} : {
...shipGroup,
category: getOrderCategory(shipGroup.items[0])
}
})

const carrierPartyIds: Array<string> = [];
const shipmentIds: Array<string> = [];


if (total) {
shipGroups.map((shipGroup: any) => {
if (shipGroup.shipmentId) shipmentIds.push(shipGroup.shipmentId)
if (shipGroup.carrierPartyId) carrierPartyIds.push(shipGroup.carrierPartyId)
})
}

try {
this.dispatch('util/fetchPartyInformation', carrierPartyIds)
const shipmentTrackingCodes = await OrderService.fetchTrackingCodes(shipmentIds)

shipGroups.find((shipGroup: any) => {
const trackingCode = shipmentTrackingCodes.find((shipmentTrackingCode: any) => shipGroup.shipmentId === shipmentTrackingCode.shipmentId)?.trackingCode

shipGroup.trackingCode = trackingCode;
})
} catch (err) {
console.error('Failed to fetch information for ship groups', err)
}

this.dispatch('product/getProductInformation', { orders: [{ parts: shipGroups }] })

order['shipGroups'] = shipGroups

commit(types.ORDER_CURRENT_UPDATED, {order})
return shipGroups;
},
}

export default actions;
2 changes: 2 additions & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export default interface UtilState {
rejectReasons: [];
paymentMethodTypeDesc: any;
statusDesc: any;
facilityTypeDesc: any;
partyNames: any;
}
Loading

0 comments on commit 10b3da5

Please sign in to comment.