A single portal for curated, field-tested and SAP-verified expertise for your SAP C/4HANA suite. Whether it's a new implementation, adding new features, or getting additional value from an existing deployment, get it here, at CX Works.
Custom SAP Commerce Cloud Events for SAP Cloud Platform Extension Factory
Extend your use case with custom events
SAP Cloud Platform Extension Factory provides a flexible way to extend SAP Commerce Cloud using events. However, your use case may require events that are not implemented in the current Application Connector. This article describes how to create custom events in SAP Commerce for SAP Cloud Platform Extension Factory. A custom SAP Commerce Cloud extension is created to expose a custom event in SAP Commerce Cloud to SAP Cloud Platform Extension Factory.
SAP Commerce Cloud events are simple Java classes without further metadata, which extend the SAP Commerce Cloud AbstractEvent.
There are three steps to creating a custom event:
Define the event bean.
Register the event with the application connector.
Trigger the event from the business logic.
Example Use Case
Users can write product reviews on our SAP Commerce website. We would like to analyze these reviews for customer sentiment based on what they write. Currently, when a user submits a product review, there is no out-of-the-box event. Once we create one, we can write a serverless function in SAP Cloud Platform Extension Factory to send the review comments to a text analytics service which will determine whether the user's sentiment is positive or negative. Based on that result, we can trigger other actions like notify our customer service representative through a ticketing system or create a marketing interaction to follow up with the user. The example event included in this article is product.reviewsubmitted.
Custom Extension Setup
Create a custom SAP Commerce Cloud extension, my-custom-events, using the yempty template with ant extgen.
ant extgen -Dtemplate=yempty -Dname=my-custom-events
Register your new extension in localextensions.xml.
The example event in this article is triggered when a customer product review is submitted. This leverages the customerreview extension in SAP Commerce Cloud. Out-of-the-box, the CustomerReview type does not have a unique key. For this example, the CustomerReview type is extended and a unique reviewcode attribute is added. This allows you to model the CustomerReview type as an Integration Object.
Extend the type in *items.xml.
<itemtype code="CustomerReview" autocreate="false" generate="false" >
<attribute type="java.lang.String" qualifier="code">
Unique id for the customer review
<persistence type="property" />
<modifiers read="true" write="true" search="true" initial="true" optional="false" unique="true"/>
Run ant all.
Extend the CustomerReviewService to populate and save the new code attribute.
Kubeless will mount the secret as files that can be accessed.
var surl = fs.readFileSync('/ecc-odata-review-service/SERVICE_URL');
var suid = fs.readFileSync('/ecc-odata-review-service/SERVICE_UID');
var spwd = fs.readFileSync('/ecc-odata-review-service/SERVICE_PWD');
Another option is to inject the secret as container environment variables. This can be defined on the function through YAML as discussed in the Kubernetes documentation.
This article described how to add a custom event in SAP Commerce Cloud to SAP Cloud Platform Extension Factory. This will allow you to go beyond the out-of-the-box events and enable even more business functions and use cases using the flexibility of SAP Cloud Platform Extension Factory.
You're going to be redirected to a page that requires login with SAP ID, do you want to proceed?
You are now leaving CX Works
Links to information published on other SAP sites
Indicated by icon
You are leaving CX Works and entering another SAP-hosted site.
Links to information published on non-SAP sites
Indicated by icon
You are entering a site that is not hosted by SAP. By using such links, you agree to the following:
The content of the linked-to site is not SAP documentation. You may not infer any product claims against SAP based on this information.
SAP does not agree or disagree with the content on the linked-to site, nor does SAP warrant the availability and correctness. SAP shall not be liable for any damages caused by the use of such content unless damages have been caused by SAP's gross negligence or willful misconduct.