/
Split Order Activity

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:

  1. From the httpRequestbody received from front end for split order, fetch actor and account slug.

  2. Set all the hard coded values

  3. For every Item received from front end fetch required details from DB

    1. 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
  4. Add all the items in a itemList, and for each item set :

    1. orderItemId

    2. oldShipmentID with the value of externalShipmentID

    3. oldStatus based on existing logic.

  5. After complete split-order process, fetch the new status

    1. SELECT 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)
  6. For each item in the above list, set :

    1. externalShipmentID

    2. newStatus to either “New”, “On-Hold” or “Unfulfillable”

    3. expectedShipDate

  7. Prepare the event request body and publish it to new event sub-type created using below steps.

    1. nf_staging_order_item_split_order_v1

GCP Topic

  1. Create a GCP Pub/Sub topic, in eshopbox-portal-dev & eshopbox-portal-prod project for staging & production respectively.

  2. 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.

  3. Create a push based subscriber with below details:

    1. Push endpoint: https://esb-notifications-staging.appspot.com/_ah/api/esb/v1/activity

      image-20240130-061228.png
      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

  1. Use the below code and import the curl in POSTMAN

    1. 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" }'
    2. Sample response:

      1. { "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" }
  2. 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

  1. Use the below code and import the curl in POSTMAN

    1. 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" }'
    2. Sample Response:

      1. { "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" }
  2. 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

  1. 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.

  2. Inside the methodapplyCustomLogicOnEvent, check if the event sub type is split_order, then

    1. Set display text as updated the package

    2. Set all the details for meta data

      1. Current Status: oldStatus > newStatus

      2. Shipment ID: oldShipmentId > newShipmentId

      3. If new Status is not Unfulfillable, set Expected Ready to Ship by: expectedShipDate

References:
  1. https://auperator.atlassian.net/wiki/spaces/PLE/pages/4169957382

  2. https://auperator.atlassian.net/wiki/spaces/PLE/pages/4119068699

Related content