When the customer land on the order history page, he clicks on the order -> b2b customer land on the order detail page, a business can ask to show the order invoice PDF document, delivery ASN document, Order confirmation & Order acknowledgment PDF document, which they have in S4
Approach:-
SAP Commerce/SAP Hybris <-----> SAP CPI <------> S4 System
Integration to connect S4 system via CPI to SAP Commerce/SAP Hybris and to get the order-related details like Order status, Invoice document, Delivery document, Order confirmation and Order acknowledgment document.
When we placed the Order from B2B Side, Order will reach S4 via CPI or any middleware which transfers the SAP Hybris request to the respective format of S4, The order will be getting created as Interim Order(Parent Order) in S4.
When the customer representative picks up the order, he will apply some delivery block like Z0, Z1, etc., based upon the request passed in the order Idoc request.
Like if you have any additional fields in SAP Commerce/SAP Hybris checkout steps, like
1.) price negotiation check box,
2.) special text field check area.
3.) Price token send to S4(Hidden attribute)
4.) Order as quote indicator.
We have to show the order status on Order History Page and
Order Details Page for the Interim(Parent) order from S4, So basically what the order status is in S4, the same we have to replicate to B2B Channel, via ODATA call, Also PDF document related information we will
show on the order details page.
Option available -
1. Direct integration call, from SAP Commerce/SAP Hybris to S4 when the order history page is loading.
NOTE:- Performance can be affected if there are many orders available, as one by one you need to iterate the order from the order history page and pass it to S4, via middleware.
2. Write a utility job - Cron job, for which we can write a trigger, that runs at the particular time interval which is configured, in the Cron expression.
in Cron job -> we have executed method(Inherits from the implemented OOTB class), where we can write the logic to fetch all the parent orders, in the order model we have SAP order code attribute available, you can check the same in the Administrator tab, of the back office.
Request Body that we will pass to CPI from B2B/B2C SAP Commerce/SAP Hybris
{
"sapOrderCode": "sap order code reference id"
}
The response body from S4 will get the order status and hex string for all the above-mentioned documents from the S4 system.
From B2B Side we will convert Hex String into PDF and the same we will show on B2B Side dynamically.
When the order detail page is loaded, in the Order detail response from S4, we will get reference no. for the doc, like for the delivery note, and order confirmation doc reference no, which we need to show on the storefront via real-time integration call.
Now, when viewing the document, the customer has to click on the storefront, where the reference no. is shown.
Request mapping for it, via a Ajax call.
@ResponseBody
@RequestMapping(value = "/invoicePDFView", method =
{ RequestMethod.POST, RequestMethod.GET })
//produces = MediaType.APPLICATION_JSON_VALUE)
public void invoicePDFView(final String document number, final String sapOrderCode, final String type of document,
final HttpServletRequest request, final HttpServletResponse response) throws DecoderException, IOException
This line of code will decode the hex string --->
final byte[] decodedHex = org.apache.commons.codec.binary.Hex.decodeHex(documentPDF.toCharArray());
if (null != decodedHex && decodedHex.length > 0) {
if (!StringUtils.isEmpty(document name))
{
response.setHeader("Content-Disposition", "inline;filename=" + documentName);
}
response.setDateHeader("Expires", -1);
response.setContentType("application/pdf");
response.getOutputStream().write(decodedHex);
response.getOutputStream().close();
response.getOutputStream().flush();
}
Following above is the sudo logic, which can be used, by the developer and modify it while debugging.
Thanks for reading.
No comments:
Post a Comment