Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

To integrate SAP Hybris C4C with Pricefx, we use two approaches:

In this section:

Set up SAP Environment

First you need to create accounts for accessing OData API and Web Service API. For details see /wiki/spaces/INTG/pages/649232840.

Create WebService API Account

For details see /wiki/spaces/INTG/pages/506331149.

Common SAP Integration Configuration

pfx.url=pricefx_url
pfx.partition=pricefx_partition
pfx.username=pricefx_user
pfx.password=pricefx_password

Configure Fetching Products and Customers

application.properties
integration.sap.productsRefreshAfter=3600000
integration.sap.oDataServiceUri=https://myNNNNNN.crm.ondemand.com/sap/byd/odata/v1/c4codata/
integration.sap.rest.username=sap_rest_username
integration.sap.rest.password=sap_rest_password
integration.sap.ws.username=sap_ws_username
integration.sap.ws.password=sap_ws_password

camel-context.xml - Products
<pfx:loadMapper id="sapProductMapper">
        <pfx:body in="ID" out="sku"/>
        <pfx:body in="Description" out="label"/>
        <pfx:body in="UnitOfMeasureCode" out="unitOfMeasure"/>
</pfx:loadMapper>


<camelContext xmlns="http://camel.apache.org/schema/spring" useMDCLogging="true">
<route>
            <from uri="timer://foo?repeatCount=1"/>
            <to uri="pfx-c4c?method=fetchProducts&username={{integration.sap.rest.username}}&password={{integration.sap.rest.password}}&url={{integration.sap.url}}/sap/byd/odata/v1/c4codata/&batchedMode=true"/>
            <log message="body: ${body}" />
            <split>
                <simple>${body}</simple>
                <to uri="pfx-c4c?method=fetchProducts&username={{integration.sap.rest.username}}&password={{integration.sap.rest.password}}&url={{integration.sap.url}}/sap/byd/odata/v1/c4codata/"/>
                <log message="body: ${body}" />
                <to uri="pfx-api?method=loaddata&objectType=C&mapper=sapProductMapper"/>
            </split>
        </route>
</camelContext>

camel-context.xml - Customers
    <pfx:loadMapper id="sapCustomerMapper">
        <pfx:body in="CustomerID" out="customerId"/>
        <pfx:body in="Name" out="name"/>
        <pfx:body in="EMail" out="attribute1"/>
    </pfx:loadMapper>

        <route>
            <from uri="timer://foo?repeatCount=1"/>
            <to uri="pfx-c4c?method=fetchCustomers&username={{integration.sap.rest.username}}&password={{integration.sap.rest.password}}&url={{integration.sap.url}}/sap/byd/odata/v1/c4codata/&batchedMode=true"/>
            <log message="body: ${body}" />
            <split>
                <simple>${body}</simple>
                <to uri="pfx-c4c?method=fetchCustomers&username={{integration.sap.rest.username}}&password={{integration.sap.rest.password}}&url={{integration.sap.url}}/sap/byd/odata/v1/c4codata/"/>
                <to uri="pfx-api?method=loaddata&objectType=C&mapper=sapCustomerMapper"/>
            </split>
        </route>

Delta Synchronization of Products and Customers

Add the &deltaSync=true parameter to the fetch URI. The parameter must be added to both the batchedMode parent and the split section of the route definition.

...
<to uri="pfx-c4c?method=fetchCustomers&username={{integration.sap.rest.username}}&password={{integration.sap.rest.password}}&url={{integration.sap.url}}/sap/byd/odata/v1/c4codata/&batchedMode=true&deltaSync=true"/>
            <split>
                <simple>${body}</simple>
                <to uri="pfx-c4c?method=fetchCustomers&username={{integration.sap.rest.username}}&password={{integration.sap.rest.password}}&url={{integration.sap.url}}/sap/byd/odata/v1/c4codata/&deltaSync=true"/>

Full-synchronization (no delta) routes can be configured as well. The system stores the date and time of last synchronizations in Pricefx Advanced Configuration Options.

Configure Price Lists Syncing

application.properties
integration.sap.url=myNNNNNN.crm.ondemand.com
integration.sap.ws.username=sap_ws_username
integration.sap.ws.password=sap_ws_password

<pfx:multilevelMapper id="sapPriceListMapper">
        <pfx:header in="priceListId" out="priceListId"/>
        <pfx:groovy expression="'MSG_' + System.currentTimeMillis() + '_' + headers.priceListId" out="messageId"/>
        <pfx:simple expression="headers.receivedEvent[targetDate]" out="startDate"/>
        <pfx:groovy expression="headers.receivedEvent.expiryDate?headers.receivedEvent.expiryDate:new org.joda.time.LocalDate(headers.receivedEvent.targetDate).plusDays(30)" out="endDate"/>
        <pfx:simple expression="headers.receivedEvent[label]" out="name"/>
        <pfx:property in="EUR" out="currencyCode"/>
        <pfx:property in="04" out="actionCode"/><!-- 01=create, 04=update (always use 04 in batch mode) -->
        <pfx:body in="data[].resultPrice" out="priceSpecificationList[].amount"/>
        <pfx:body in="data[].sku" out="priceSpecificationList[].productId"/>
        <pfx:body in="data[].currency" out="priceSpecificationList[].currency"/>
        <pfx:body in="data[].unitOfMeasure" out="priceSpecificationList[].unitCode"/>
</pfx:multilevelMapper>

<pfx:filter id="priceListFilter">
</pfx:filter>

<camelContext xmlns="http://camel.apache.org/schema/spring" useMDCLogging="true">
        <contextScan/>
        <route>
            <from uri="direct:handleItemApprovedPlEvent"/>
            <log message="Price list event was received ${body}"/>
            <setHeader headerName="priceListId">
                <simple resultType="java.lang.Long">${body[data][0][id]}</simple>
            </setHeader>
            <setHeader headerName="receivedEvent">
                <simple>${body[data][0]}</simple>
            </setHeader>
            <toD uri="pfx-api?method=fetch&objectType=PLI&priceListId=${headers.priceListId}&filter=priceListFilter&batchedMode=true&batchSize=10"/>
            <split>
                <simple>${body}</simple>
                <toD uri="pfx-api?method=fetch&objectType=PLI&priceListId=${headers.priceListId}&filter=priceListFilter"/>
                <log message="${body}"/>
                <to uri="pfx-c4c?method=updatePriceList&mapper=sapPriceListMapper&username={{integration.sap.ws.username}}&password={{integration.sap.ws.password}}&url={{integration.sap.url}}/sap/bc/srt/scs/sap/managesalespricelistin2"/>
                <log message="Response status: ${headers.responseStatus}" />
                <log message="Response body: ${body}"/>
            </split>

        </route>
</camelContext>

Handle Exceptions

The pfx-c4c updatePriceList can throw three types of exceptions:

  • net.pricefx.integration.component.c4c.PfxC4CException
    Occurs when a business error from SAP C4C is received as a response to the request call. For example, a price list with the same validity already exists, a product with a particular ID does not exist, etc. PfxC4CException.getExceptionLog() gets the SAP C4C error log message.

  • org.apache.camel.CamelExecutionException
    This exception is thrown for technical issues.

  • java.lang.Exception or other exception

  • No labels