Split Order Activity
Sample Event Body
{
"actor": "snehal.soni@eshopbox.com",
"response_data": {
"externalChannelID": "CH6055",
"customerOrderNumber": "ChnLocTest_03",
"items": [
{
"orderItemId": "ChnLocTest_03-30328965",
"oldStatus": "Unfulfillable",
"oldShipmentId": "-",
"status": "New",
"externalShipmentID": "9891234-4567-3455",
"expectedShipDate": "2023-12-27 12:00:00"
}
]
},
"eventSubType": "split_order",
"resource": "order",
"accountSlug": "tab",
"eventType": "POST",
"version": "v1"
}
Preparation of Event Body
Project Details
PROJECT NAME IN GCP: eshopbox-client-portal-prod
GCP Service: Default
GITLAB REPO NAME: inventory-engine
Steps to achieve:
From the
httpRequestbody
received from front end for split order, fetch actor and account slug.Set all the hard coded values
For every Item received from front end fetch required details from DB
SELECT order_items.id, order_items.orderItemId, shipments.externalShipmentID, SUBSTRING_INDEX( GROUP_CONCAT( shipment_status_logs.status ORDER BY shipment_status_logs.id DESC) , ',', 1) AS latestStatus FROM order_items LEFT JOIN shipments ON shipments.id = order_items.shipment_id LEFT JOIN shipment_status_logs ON shipment_status_logs.shipment_id = order_items.order_id WHERE order_items.id IN (:orderItemIdList) GROUP BY order_items.id
Add all the items in a
itemList
, and for each item set :orderItemId
oldShipmentID
with the value ofexternalShipmentID
oldStatus
based on existing logic.
After complete
split-order
process, fetch the new statusSELECT order_items.orderItemId, order_items.expectedShipDate, order_items.onHold AS onHold, order_items.status, shipments.id, shipments.externalShipmentID AS externalShipmentId FROM order_items LEFT JOIN shipments ON shipments.id = order_items.shipment_id WHERE order_items.id IN (:orderItemIdList)
For each item in the above list, set :
externalShipmentID
newStatus
to either “New”, “On-Hold” or “Unfulfillable”expectedShipDate
Prepare the event request body and publish it to new event sub-type created using below steps.
nf_staging_order_item_split_order_v1
GCP Topic
Create a GCP Pub/Sub topic, in
eshopbox-portal-dev
&eshopbox-portal-prod
project for staging & production respectively.Use the same name as the output of the response for creation of event subtype i.e.
nf_staging_order_item_split_order_v1
for new GCP topic name.Create a push based subscriber with below details:
Push endpoint:
https://esb-notifications-staging.appspot.com/_ah/api/esb/v1/activity
GCP Details
Registration
NOTE: Since the resource type order_item
and event type POST
that we are using are already created, so there is no need to create them.
Register new Event Sub-Type
Use the below code and import the curl in POSTMAN
curl --location 'https://esb-notifications-staging.appspot.com/_ah/api/esb/v1/event' \ --header 'Content-Type: application/json' \ --data '{ "resource":"order_item", "eventType":"POST", "eventSubType":"split_order", "version":"v1" }'
Sample response:
{ "createdat": "2024-01-24T11:15:59.740Z", "resource": "order_item", "topiccreated": "1", "eventsubtype": "split_order", "eventtype": "POST", "id": 1572, "version": "v1", "updatedat": "2024-01-24T11:15:59.740Z", "pubsubtopic": "nf_staging_order_item_split_order_v1", "status": "1" }
From the response we can see the name of new topic is
nf_staging_order_item_split_order_v1
, which will be used to publish event for this type of activity
Register/Create Internal-Subscriber for above GCP Pub/Sub
Use the below code and import the curl in POSTMAN
curl --location 'https://esb-notifications-staging.appspot.com/_ah/api/esb/v1/internal-subscriber' \ --header 'Content-Type: application/json' \ --data '{ "resource": "order_item", "eventType": "POST", "eventSubType": "split_order", "version": "v1", "subscriptionPushEndpoint": "https://esb-notifications-staging.appspot.com/_ah/api/esb/v1/activity", "subscriptionType": "activity" }'
Sample Response:
{ "id": 224, "eventid": 1572, "subscriptioncreated": "1", "subscriptionType": "activity", "subscriptionName": "nf_staging_order_item_split_order_v1604607745_event_-1493611823_subscription", "subscriptionpushendpoint": "https://esb-notifications-staging.appspot.com/_ah/api/esb/v1/activity", "status": "1", "createdat": "2024-01-24T11:17:50.994Z", "updatedat": "2024-01-24T11:17:50.994Z" }
After completion of all above and below steps, request someone from Notifications Team (@Muskan Choudhury (Unlicensed)), to set the status active, so that it is visible in frontend.
Set Activity Details
Project Details:
PROJECT NAME IN GCP: esb-notification-prod
GITLAB REPO NAME: Notifications
Steps to achieve:
Since the resource is order_item
, so we will use the file Order_itemLogService.java
Re-Verify all the values being used to generate the unique
targetId
, to identify the activity, are present in the main request body created in the top of this confluence page.Inside the method
applyCustomLogicOnEvent
, check if the event sub type issplit_order
, thenSet display text as
updated the package
Set all the details for meta data
Current Status: oldStatus > newStatus
Shipment ID: oldShipmentId > newShipmentId
If new Status is not
Unfulfillable
, setExpected Ready to Ship by: expectedShipDate