/
Order Splitting Implementation Document

Order Splitting Implementation Document

Project And API Details

GCP Project(Prod) - eshopbox-client-portal-prod Service - default Gitlab Repo - Inventory Engine - Client Portal API type + Path (Staging) = POST https://{accountSLug}.auperator.net/api/v1/splitOrder API type + Path (Prod) = POST https://{accountSLug}.myeshopbox.com/api/v1/splitOrder

 

 

Data Model

 

High Level Sequence Diagram

 

Flow Chart

Implementation

  1. Request Body:

REQUEST BODY :- { "orderId" : 8474565, "packages": { "package_01": [ 30325340,30325341 ],//orderItemId_PK "package_02": [ 30666311,30666312 ] }, "status": { "30325340": "Unfulfillable", "30325341": "New", "30325340": "" } }
  1. Get account Id and actor from access token. It will be used while publishing to show activities.

  2. Create a compiled_orderItemId_list with order item Ids in all the packages

  3. Fetch required details from DB

    SELECT order_items.id, order_items.shipment_id, order_items.status, shipments.externalShipmentID, GROUP_CONCAT(shipment_status_logs.status SEPARATOR '##') AS statusList, SUBSTRING_INDEX(GROUP_CONCAT(shipment_status_logs.status ORDER BY shipment_status_logs.id DESC), ',', 1) AS latest_status FROM order_items LEFT JOIN shipments ON shipments.id = order_items.shipment_id LEFT JOIN shipment_status_logs ON shipment_status_logs.shipment_id = shipments.id WHERE order_items.id IN (30325339, 30325340, 30325341, 30325342, 30325343) GROUP BY order_items.id HAVING (order_items.shipment_id = 0 AND order_items.status != "CANCELLED") OR (latest_status IN ('created','accepted','picking','picked','failed_to_rts'));
  4. If compiled_orderItemId_list size != query result size,

    1. Then throw exception “One of the Order item is already packed or cancelled”

    2. Cause: At least one of the order item id is already either packed or cancelled.

  5. Run a loop for each package recieved from front-end :

    1. If all the orderItemIds in that list have same shipment Id. (i.e. if all the orderItems are in respective packages)

      1. If true:

        1. Return no-action is supposed to be taken

      2. if false:

        1. then continue below

  6. Run a LOOP on above query result

    1. If orderItems.status != “cancelled“ OR statusList != null AND (LatestStatus="packed" OR “cancelled“)

      1. Then throw exception “One of the Order item is already packed or cancelled”

    2. Compile a list of shipmentIds to be cancelled

    3. Prepare a semi-colon separated insert query, for all shipmentIds:

      1. INSERT INTO shipment_status_logs (shipment_id, STATUS, track_payload, remarks, external_updated_at) VALUES (:shipmentId, 'cancelled', '', 'SYSTEM INSERTED split order', :currentTime);
    4. Prepare a Array-List of below update query for the CombinationIdentifier column in orderItemsId table

      1. UPDATE order_items SET CombinationIdentifier = 'packageNumber', shipment_id = 0 WHERE id = :orderItemId;
  7. Perform below query to fetch the remaining order Item Id’s in the shipment that will be cancelled

    1. SELECT id from order_items where shipment_id in (:cancelShipmentIdsList) and not in (:requstedOrderItemIds);
  8. Call WMS Shipment API to prepare event to publish to inventory team for the all the shipments to be cancelled.

  9. UPDATE DATABASE

    1. Run insert query created in step 7.c.

    2. Run update queries in loop created in step 7.d

    3. Run below query for remaining order item Ids fetched in step 8:

      1. Update order_items set shipment_id = 0 where id in (:remainingOrderItemIds) AND `status` != "CANCELLED";
  10. Publish the event in the pub-sub to re-stock the inventory

    1. Details to be added after discussion from inventory team

  11. Call WMS Order API to prepare the event to create new shipment

  12. Run a loop on remaining order item id’s fetched in step 8

    1. Prepare request body using response in step 12 and filtering the list only for those order item ids

    2. Call real time inventory allocation API without any restrictions

  13. Run a loop on all the packages received in request body from front end:

    1. Create request body for items in this package

    2. Call real time inventory allocation API with those items

    3. Working of this API : https://auperator.atlassian.net/wiki/pages/createpage.action?spaceKey=ordershippingengine&title=Real%20Time%20Inventory%20Allocation%20%28Order-Splitting%29&linkCreation=true&fromPageId=4174610433

  14. Create a finalOrderItemIds list with all the items in

    1. compiled_orderItemId_list in step 2

    2. remaining order item id’s fetched in step 8

  15. Call ALGOLIA task queue with above finalOrderItemIds

  16. Prepare the frontend response:

    1. SELECT order_items.id AS orderItemId, order_items.orderItemId AS orderItemIdString, order_items.shipment_id AS shipmentId, order_items.onHold AS onHold, order_items.status AS status, orders.thirdPartyShipping AS thirdPartyShipping, orders.customerOrderNumber AS customerOrderNumber, shipments.externalShipmentID AS externalShipmentId FROM order_items LEFT JOIN orders ON orders.id=order_items.order_id LEFT JOIN shipments ON shipments.id = order_items.shipment_id WHERE order_items.id IN (:finalOrderItemIds)
  17. Return the response

 

Related content