Extending an Existing OCC Service
The Easy Extension Framework allows you to extend existing OCC services by adding and populating additional attributes to the OCC service response. This is particularly useful when you want to enhance an existing functionality by adding and populating new attributes.
Steps to Extend an Existing OCC Service
This section step by step explains how to extend an existing OCC service using the Easy Extension Framework. We consider here an example of adding a marketing category field to the ProductModel
and populating the category code from the associated marketing category to the OCC response of the product details OCC response.
Step 1: Create a New Easy Extension
The first step is generate of an easy extension as explained at Generate an Easy Extension.
Step 2: Add the new attribute to existing item type
The SAP Commerce cloud data model can be enhanced in the Easy extension framework in easytypes.json
as explained at Example definition of adding attributes to an existing item type using easy item type. In this case, you need to add a new attribute marketingCategory
to the Product
item type.
Step 3: Add the additional attributes to the Data Objects (Java Beans)
While using, Easy Extension Framework, you can add additional attributes to the data objects (Java Beans) using Groovy metaclass. This allows you to dynamically add new properties to existing Java Beans without modifying the original class.
For an example, if you want to add a new attribute marketingCategory
to the ProductData
class, you can do it as follows in EasyBeans.groovy
file of your easy extension:
Step 4: Add the new attributes to the OCC Service Response (WsDTO)
To add the new attributes to the OCC service response, you need to modify the corresponding WsDTO class. Similar to the Java Beans, you can use Groovy metaclass to add new properties to the WsDTO class as well.
For example, if you want to add the marketingCategory
attribute to the ProductWsDTO
class, you can do it as follows in EasyBeans.groovy
file of your easy extension:
Step 5: Populate the new attributes in the Java Beans (Product Data)
To populate the new attributes in the Java Bean, you need to implement a new Populator
or extend an existing one. For example, if you want to populate the marketingCategory
attribute in the ProductData
, you can extend a new populator as ProductMarketingCategoryPopulator
as below:
Step 6: Register the Populator
Finally, you need to register the new populator as spring bean in your easy extension's EasyBeans.groovy
file as:
Step 7: Include the newly added attribute in the OCC Service field sets
To include the newly added attribute in the OCC service field sets, you need to modify the corresponding field set configuration. This is typically done in the EasyBeans.groovy
file as:
Step 8: Deploy the Easy Extension
After making all the changes, you need to deploy your easy extension to the SAP Commerce Cloud server via Easy
tab in SAP Commerce Cloud Administration Console (hAC).
Step 9: Test the Extended OCC Service
Once the easy extension is deployed, you can test the extended OCC service by calling the product details endpoint and checking if the marketingCategory
attribute is included in the response.