How to Create an Order Summary JSON API Service with the HybrisArchitect.com Dashboard (Part 1 of 2)

This article is the first installment of a two part series that describes how the HybrisArchitect.com Dashboard's Order Summary Card was developed.

The HybrisArchitect.com Dashboard (HAD) is equipped with several reports that track Order, Customer, Product, and Inventory metrics.

At the end of this tutorial, we will have built the two Order JSON APIs used for the Orders Summary Card.

Orders Summary Card

The Orders Summary Card requires two individual JSON API services. The first API service is the Today's Orders Totals API, which provides the total amount, total count and average order total for today's orders. The bottom part of the Orders Summary Card uses the Year-to-Date Orders Total API, which displays the year-to-date's total order amount, total order count and average order total.

Before We Start Developing the Two Orders API Services

Prerequisite: The HybrisArchitect.com Dashboard should be running.
To learn how to start the HybrisArchitect.com Dashboard, please refer to: https://hybrisarchitect.com/how-to-start-the-hybrisarchitect-com-dashboard-from-the-hybris-administration-console-hac/

Development Environment Used: Local development machine (Windows). This tutorial will work on Mac and Linux environments.

Important Architectural Note:  Each controller is a unique, stand-alone file with no dependencies on other controller files.  The developer may update a single controller file without impacting the other controller files.

Today's Orders Total API

The following are the steps to create the Today's Orders Total API:

1. Create a controller file called order.daily.totals.json.groovy under the /controller folder.

2. Open the order.daily.totals.json.groovy file in your preferred IDE and develop the following Groovy code to create the Today's Order Total API

3. Click your IDE's Save button

4. Go to your Web browser, and enter the following URL: http://localhost:3094/json/order.daily.totals.json

5. Congratulations! The Today's Orders Total API is complete! Next, we will create the Year-to-Date Orders Total API.

Year-to-Date Orders Total API

The following are the steps to create the Year-to-Date Orders Total API:

1. Create a controller file called order.totals.json.groovy under the /controller folder.

2. Open the order.totals.json.groovy file in your preferred IDE and develop the following Groovy code to create the Order Summary JSON API

3. Click your IDE's Save button

4. Go to your Web browser, and enter the following URL: http://localhost:3094/json/order.totals.json

5. Congratulations! The Year-to-Date Orders Total API is complete, too! This tutorial is done
 As a reminder, with the HybrisArchitect.com Dashboard, we can deploy new code code changes without an Hybris ANT Build or Hybris Server Restart.

About the author

Marc is the Founder of HybrisArchitect.com. He enjoys helping others learn more about SAP Hybris Commerce. Marc has held the role of Hybris Architect at Exemplis and Nasty Gal. He is a long-time Java/Spring developer. Marc holds an M.S. Software Engineering from Carnegie Mellon University and a B.S. in Accountancy from California State University, Fresno. He can be reached at: info@hybrisarchitect.com

Add a Comment

Your email address will not be published. Required fields are marked *