Creating Different shipment for virtual Kit Items
What is the purpose of this article?
The purpose of this article is to discuss the implementation for creating a different shipment for those items which are of virtual kit.
Basic points to note.
1. Whenever an order is created, entry is made in order_items table.
2. And if there is a virtual kit item in that order, then for that virtual kit item,entry happenns in order item component table too.
This document explains the steps and flow for achieving this task along with their function's name.
Tasks to be perfomed in short - In the third API “_ah/api/esb/v2/shipment/create“, just one step before creating the shipment, we need to check if the items contained in request body contains a virtual kit item. If it contains then create a different shipment for this order item and remove this item from the request body.
Technical steps to achieve the task
This is the request body for shipment/create API
{ "Test_FC": { "orderId": 46335912, "externalChannelID": "CH2161", "externalShipmentId": "5231753822483-2161-9190", "customerOrderNumber": "5231753822483", "isCOD": "0", "warehouseId": 646, "accountSlug": "quickstarttestvarun", "orderItemIds": [ 27970802, 27970803 ], "shippingAddress": { "city": "gurgaon", "countryCode": "IN", "postalCode": "122016", "addressLine1": "gurgaon", "countryName": "INDIA", "state": "Haryana", "contactPhone": "7678631843", "customerName": "Prateek Kaushik", "email": "prateek.kaushik@eshopbox.com" }, "items": [ { "itemID": "46113011925267", "sku": "U5XTR3H1WY9", "externalWarehouseID": "Test_FC", "quantity": 2, "outOfStock": "false" } ], "externalWmsChannelId": 2456, "pickupPincode": "122503", "expectedShipDate": "2023-01-02 16:00:00", "dimensionLength": 10, "dimensionWidth": 13, "dimensionHeight": 24, "weight": 400, "dimensionUnit": "cm", "weightUnit": "g", "cp_name": "Smartr", "cp_id": 250, "isPincodeServiceable": true, "courierPartner": "ESB_Smartr_Forward" } }
From the request body, extract the items in a list.
List<Map<String, Object>> itemIdList = (List<Map<String, Object>>) request.get("items"); items": [ { "itemID": "46113011925267", "sku": "U5XTR3H1WY9", "externalWarehouseID": "Test_FC", "quantity": 2, "outOfStock": "false" } ]
Iterate each values from the list and extract the itemID.
Query from orders, order_items, and order_item_component table and fetch the order_items and product_additional_info.
If the query does not return anything, then check the next combination.
If query returns values then that means this itemID is of a virtual kit. In this case
Store product_additional_info in a String variable - productAdditionalInfo.
Check if productAdditionalInfo contains “pre-packaged and ready to ship product“.
If true, prepare a separate request for this itemId and pass this new request in the createShipmentAPI function.
Remove this index from the itemIdList from the original request body.
After the iteration is complete, check if the items list of the original request body is not empty, then pass the request body in the createShipmentAPI function to call the CREATE_SHIPMENT_API.