TechTalk: Extending the Data Model with OrderCloud

April 17, 2015

Category: Development

Every business has processes unique to their own environments. OrderCloud supports that uniqueness through the concept of custom fields. These fields exist on the 3 primary resources that drive B2B transactions: orders, products and users.

Very basically, these custom fields allow you to add properties on the object as additional data, ultimately extending the data model. You can think of it as a new column in your database table, or a new property on your object model. What you want to store in those fields is up to you.

Let’s take a look at how we’ve used it to add functionality like “favorite products” to some of our custom solution applications.

The concept of “favorite products” is a common B2C functionality that your B2B buyers may request. Simply put, it allows a user to specify any number of products as one’s they frequently order. Implementation of this feature provides enhancements to the catalog navigation for quicker ordering.

First, to support this data set, we’ll use a custom user field and name it “FavoriteProducts” and specify the text type. Then assign it to the company so every user has access to it. That field is now returned on the User API resource in the CustomFields array. OrderCloud will store data on the Value property of the CustomField. In the case of storing choices for favorite products the InteropID of the API Product resource is being added. We chose to store multiple favorite product selections by delimiting the InteropIDs with “||”.

Second, a custom angular module that contains all the resources needed to present users with the functionality is created. Custom modules are built to be self contained. This means that it contains all the templates, directives, services and controllers needed. This allows anyone to simply include the one JavaScript file in their repository to take advantage of the custom functionality.

Finally, all that is left is to include the custom module in the application repository. Make sure to include the script reference in the index.html file and add the dependency to the app.js. After those two tasks are completed you can simply use the new “<favoriteproduct>” directive element anywhere you would like.