Example Code for Integrating Servigistics InService with an Ordering System
This example code for integrating Servigistics InService with an ordering system is for reference purposes only. This code is used in a custom Java source file of the custom delegate that implements the com.ptc.sc.services.plugins.CommerceDelegate interface. You can modify this code based on your requirements.
Example Code for Getting the Key and Value of Order Soft Attributes
The following example code gets the key and value of soft attributes for orders from Servigistics InService by using the placeOrder() method. The soft attributes of the order contain the value that you set in the Set Shopping Parameter dialog:
@Override
public SCEOrder placeOrder (SCEOrder orderObj) throws Exception
{ //Code to fetch the SoftAttributes from Order Object and this information can be send to third party ordering system
Map<String, Object> existingAttrs = orderObj.getTypedAttrs();
if (existingAttrs != null) {
String dealarCode = existingAttrs.get("dealerCode") !=
null ? existingAttrs.get("dealerCode").toString() : null ;
String customer = existingAttrs.get("customer") !=
null ? existingAttrs.get("customer").toString() : null ;
String location = existingAttrs.get("location") !=
null ? existingAttrs.get("location").toString() : null ;
}
return orderObj;
}
Example Code for Getting the Cart Information
The following example code gets the cart information from Servigistics InService by using the placeOrder() method. This information contains the metadata of the cart that is being ordered, such as the name, notes, and time stamp (creation and modification date and time):
@Override
public SCEOrder placeOrder (SCEOrder orderObj) throws Exception
{
String cartName = orderObj.getName();
String dealerName = orderObj.getDealer().getName();
String notes = orderObj.getNote();
return orderObj;
}
Example Code for Getting the Cart Item Information
The following example code gets the cart item information from Servigistics InService by using the placeOrder() method. This contains the information about the items (parts) added to the cart, such as part number and quantity:
@Override
public SCEOrder placeOrder (SCEOrder orderObj) throws Exception
{ //Code to get cartItem information
List<SCECartItem> cartItems = getCartItems(orderObj);
for (SCECartItem cartItem : cartItems) {
String partNumber;
String price;
String quantity;
String notes = cartItem.getNotes();
String description = cartItem.getDescription();
if (cartItem.getPricingmetadata() != null) {
JSONObject pricingInfo = new JSONObject
(cartItem.getPricingmetadata());
}
if (cartItem instanceof SCEInternalCartItem) {
SCEInternalCartItem internalCartItem =
(SCEInternalCartItem) cartItem;
SCENavLink sceNavLink =
internalCartItem.getE3cNavLink();
if (sceNavLink != null) {
SCENavItemHistoryMetadata historyMetaData = sceNavLink.getItemHistoryMetadata();
if (historyMetaData != null) {
JSONObject part =
historyMetaData.getJSONObject();
partNumber = part.getString
("partNumber");
}
}
}else {
SCEExternalCartItem externalCartItem =
(SCEExternalCartItem) cartItem;
partNumber = externalCartItem.getPartNumber();
}
}
return orderObj;
}
}
Example Code for Getting Order Details from the Ordering System
The following example code gets the orderStatus custom attribute details from a third-party ordering system by using the placeOrder() method:
@Override
public SCEOrder placeOrder (SCEOrder orderObj) throws Exception
{ // Code to Set any additional information like OrderStaus
that is return back from the third party order system
Map<String, Object> existingAttrs = orderObj.getTypedAttrs();
if (existingAttrs == null) {
existingAttrs = new HashMap<String, Object>();
existingAttrs.put("orderStatus", "Order Success");
orderObj.setTypedAttrs(existingAttrs);
} else {
existingAttrs.put("orderStatus", "Order Success");
}
return orderObj;
}
The following response for a placed order shows the orderId and orderStatus attributes in a JSON file:
To display custom attributes from a third-party ordering system on the
Details page of an order in
Servigistics InService, see the “Displaying Custom Attributes on the Details Page of an Order” section in
Customizing Servigistics InService with the Third-Party Ordering System Information.