Easy Extension Framework v0.5 Help

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.

{ "code": "Product", "attributes": [ { "qualifier": "marketingCategory", "type": "java.lang.String", "name": [ { "lang": "en", "value": "Marketing Category" } ], "persistence": { "type": "property", "column": "p_marketing_category" }, "modifiers": { "unique": "false", "initial": "false", "optional": "true", "write": "true", "partof": "false", "read": "true", "search": "false", "encrypted": "false" } } ] }

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:

import de.hybris.platform.commercefacades.product.data.ProductData ProductData.metaClass.marketingCategory = null ProductData.metaClass.getMarketingCategory = { -> delegate.marketingCategory } ProductData.metaClass.setMarketingCategory = { value -> delegate.marketingCategory = value }

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:

import de.hybris.platform.commercewebservicescommons.dto.product.ProductWsDTO ProductWsDTO.metaClass.marketingCategory = null ProductWsDTO.metaClass.getMarketingCategory = { -> delegate.marketingCategory } ProductWsDTO.metaClass.setMarketingCategory = { value -> delegate.marketingCategory = value }

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:

import de.hybris.platform.commercefacades.product.converters.populator.ProductBasicPopulator import de.hybris.platform.commercefacades.product.data.ProductData import de.hybris.platform.core.model.product.ProductModel class ProductMarketingCategoryPopulator extends ProductBasicPopulator { @Override void populate(ProductModel source, ProductData target) { if (source.marketingCategory != null) { target.marketingCategory = source.marketingCategory.code } } }

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:

easyCoreBeans{ productMarketingCategoryPopulator(ProductMarketingCategoryPopulator) registerAlias('productMarketingCategoryPopulator', 'productBasicPopulator') }

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:

easyWebBeans('/occ/springmvc-v2') { productWsDTOFieldSetLevelMapping.levelMapping.DEFAULT = 'summary,averageRating,purchasable,stock(DEFAULT),description,variantMatrix(DEFAULT),name,baseOptions(DEFAULT),baseProduct,availableForPickup,variantOptions(DEFAULT),code,url,price(DEFAULT),numberOfReviews,manufacturer,categories(BASIC,name),priceRange,multidimensional,configuratorType,configurable,tags,sapAddToCartDisabled,sapAddToCartDisabledMessage,sapUnit,marketingCategory' productWsDTOFieldSetLevelMapping.levelMapping.FULL = 'summary,productReferences(FULL),classifications(FULL),averageRating,purchasable,volumePrices(FULL),variantType,stock(FULL),description,variantMatrix(FULL),name,baseOptions(FULL),baseProduct,availableForPickup,variantOptions(FULL),reviews(FULL),code,url,price(FULL),numberOfReviews,manufacturer,volumePricesFlag,futureStocks(FULL),images(FULL),categories(FULL),potentialPromotions(FULL),priceRange,multidimensional,configuratorType,configurable,tags,sapAddToCartDisabled,sapAddToCartDisabledMessage,sapUnit,marketingCategory' }

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.

Last modified: 18 August 2025