Headless (OCAPI) Architecture

Customizing the ESW integration in OCAPI

1. Configuring OCAPI

This section describes how to configure Shop API resources under OCAPI settings. ESW recommends that you configure Shop API version 23.1 or later for optimum utilization of the cartridge.

You can generate a new client ID and password by logging in to the Commerce Cloud Account Manager.

Adding Shop API Resources

For the cartridge to work, you must add Shop API resources to the cartridge.

To add resources:

  1. On the target site, go to Administration > Site Development > Open Commerce API Settings.
  2. From the Select type drop-down, select Shop.
  3. From the Select Context drop-down, select the appropriate context, for example, Global (organization-wide) or site-specific.
  4. Enter the OCAPI Shop API resources provided in the ocapi-configurations.json file in the documentation folder.
  5. Update the client_id with the one you generated from the Commerce Cloud Account Manager.
  6. Click Save.

int_eshopworld_headless is an overlay cartridge that includes all OCAPI customizations. You can duplicate the customizations in your cartridge by including the function calls in your OCAPI hook call files.

3. OCAPI Endpoint Customizations

3.1 Product Detail Page (PDP)

Request

GET http://hostname:port/dw/shop/v{OCAPI_VERSION}/products/{id}?expand=prices

Request Parameters

ESW ParametersDescriptionNotes
country-code (Required)Two-letter ISO code of the shopper's country.-
currency-code (Optional)Three-letter ISO code of the shopper's local currency.If the currency code is provided in the request, the ESW plugin uses this currency. If not provided, the ESW plugin uses the currency code provided in the ESW Default Country Currency Mapping site preference.
currency (Optional)Three-letter ISO code of the shopper's local currency.This is a standard OCAPI parameter. The parameter is required for Fixed Pricing and Override Price Books.

OCAPI Response

Product Document (out-of-the-box pricing attributes are converted and assigned to ESW custom attributes.)

Pricing Attributes Mapping (PDP)
ESW AttributeTypeProduct Base Pricing Attribute
c_eswPriceDecimalprice
c_eswPrice_maxDecimalprice_max
c_eswPrice_per_unitDecimalprice_per_unit
c_eswPrice_per_unit_maxDecimalprice_per_unit_max
c_eswPricesMapString, Numberprices
c_shopperCurrencyString (3-char ISO)-

3.2 Product Listing Page (PLP/CLP)

You can also add search-related query parameters to the URL as well.

Request

GET http://hostname:port/dw/shop/v{OCAPI_VERSION}/product_search?expand=prices

Request Parameters

ParameterTypeDescription
c_eswReturnProhibitedBooleantrue/false if product return is prohibited in current shopper country.
c_eswRestrictedProductBooleantrue/false if product is restricted in current shopper country.

OCAPI Response

Product Search Result Hits (out-of-the-box pricing attributes are converted and assigned to ESW custom attributes.)

Pricing Attributes Mapping (PLP/CLP)
ESW AttributeData TypeProduct Base Pricing Attribute
c_eswPriceDecimalprice
c_eswPrice_maxDecimalprice_max
c_eswPrice_per_unitDecimalprice_per_unit
c_eswPrice_per_unit_maxDecimalprice_per_unit_max
c_eswPricesMapString, Numberprices
c_shopperCurrencyString (3-char ISO)-
c_eswReturnProhibitedBooleantrue/false if product return is prohibited in current shopper country.
c_eswRestrictedProductBooleantrue/false if product is restricted in current shopper country.

Extension Points (PDP + PLP/CLP)

Extension PointESW Extension ScriptNotes
dw.ocapi.shop.product.beforeGET/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/setOverridePriceBook.jsMainly used for Fixed Pricing and Override Price Book to get prices directly from the price book.
dw.ocapi.shop.product.modifyGETResponse/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/pdpPriceHook.jsUsed for dynamic/calculated prices. Skips dynamic calculations for Fixed Pricing model countries.
dw.ocapi.shop.product_search.modifyGETResponse/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/plpPriceHook.jsUsed for dynamic/calculated prices. Skips dynamic calculations for Fixed Pricing model countries.

3.3 Cart or Basket Page

Basket / Cart Customizations (High level)

ESW uses extension scripts to:

  • Apply override price book logic (Fixed Pricing / Override Price Books)
  • Recalculate basket totals and apply ESW conversions for dynamic pricing countries

Basket Pricing / Flags (Custom attributes referenced)

AttributeTypeDescription
c_eswUnitPriceDecimalbasePrice (per unit)
c_eswReturnProhibitedBooleantrue/false if return is prohibited in current shopper country.
c_eswRestrictedProductBooleantrue/false if product is restricted in current shopper country.

Extension Points (Basket)

Extension PointESW Extension ScriptNotes
dw.ocapi.shop.basket.afterPOST/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/setOverridePriceBook.jsMainly used for Fixed Pricing and Override Price Book to get prices directly from the price book.
dw.order.calculate/int_eshopworld_headless/cartridge/scripts/cart/calculate.jsStandard SFCC calculate.js extension script calculates/recalculates the basket sent in the request. The customized/added function call eswBasketPriceConversions is used for dynamic/calculated prices and skips dynamic calculations for Fixed Pricing model countries.

For more information on how OCAPI response attributes can be used to display or represent the different prices on the Cart Page, see Headless (OCAPI) Attributes Mapping with Cart.

4. ESW Checkout Redirect (OCAPI Order + ESW Checkout)

4.1 Create Order (Shop API)

Request

POST http://hostname:port/dw/shop/v{OCAPI_VERSION}/orders

Request Parameters

ESW ParametersDescriptionNotes
country-code (Required)Two-letter ISO code of the shopper's country.-
currency-code (Optional)Three-letter ISO code of the shopper's local currency.If the currency code is provided in the request, the ESW plugin uses this currency. If not provided, the ESW plugin uses the currency code provided in the ESW Default Country Currency Mapping site preference.

OCAPI Response

orderResponse Document (appended with ESW PreOrder Service Response)

ESW PreOrder Service Response — SUCCESS (example)
"c_eswPreOrderResponseStatus": "OK",
"c_eswPreOrderResponse": {
  "preOrderCode": "7d06f6ec-fbd4-417b-8275-67b3e0d94de1",
  "orderNumber": "7d06f6ec-fbd4-417b-8275-67b3e0d94de1",
  "redirectUrl": "https://checkout-ui-plugus.sandbox.eshopworld.com/7d06f6..."
}
ESW PreOrder Service Response — FAILED (example)
"c_eswPreOrderResponseStatus": "ERROR",
"c_eswPreOrderResponse": [
  {
    "message": "RetailerCartId is required.",
    "code": 8
  }
]

4.2 Order Hook Extension Points

Extension PointESW Extension ScriptNotes
dw.ocapi.shop.order.beforePOST/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/orderHooks.jsUsed for Fixed Pricing / Override Price Book to get prices directly from the price book based on the basket currency. Also sets basket attributes with faux information to help create an order in SFCC (Shipping Address, Billing Address, Customer Email Address, ESW Payment Method). Sets required product line item custom attributes (ESW Unit Price, ESW Delta Rounding Value).
dw.ocapi.shop.order.afterPOST/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/orderHooks.jsSets order-level custom attributes: eswFxrate, eswShopperCurrencyOrderDiscount, eswDeliveryOptions. Also fetches and stores override shipping method rates used by ESW Checkout. To store override shipping methods JSON with rates, the ESW plugin uses eswDeliveryOptions, an order-level custom attribute available in the systemobjects_headless.xml metadata file.
dw.ocapi.shop.order.modifyPOSTResponse/int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/orderHooks.jsCalls ESW Checkout service and appends the service response into the Order OCAPI [POST] orderResponse document.

5. Basket Creation Request Payload (Minimum Example)

The following code sample shows the minimum request payload required to create an ESW Checkout Order:

For information on Checkout API and its request body attributes, see the Checkout API.
For information on the OCAPI endpoints, see SFCC - Shop API Resources.

{
  "product_items": [
    {
      "product_id": "750518699721",
      "quantity": 1
    },
    {
      "product_id": "750518699769",
      "quantity": 1
    }
  ],
  "shipments": [
    {
      "shipping_method": {
        "id": "POST"
      }
    }
  ],
  "currency": "USD"
}

6. Order Confirmation

The ESW Order Confirmation is a webhook call initiated from the ESW system to the retailer system. Similar to other architectures, the Headless (OCAPI) Architecture also has a similar flow for Order Confirmation.

For order confirmation requests in Headless OCAPI:

  • EswHL-Notify endpoint is used for SiteGenesis compatible architecture
  • EswRefArchHL-Notify endpoint is used for SFRA compatible architecture
    Configurations for this can be done using the ESW Metadata Items custom site preference under ESW Checkout Configuration.

7. Generic Price Conversion Endpoint

SFCC Custom Web Endpoint

  • SiteGenesis compatible Architecture:
    • GET https://hostname/on/demandware.store/Sites-SiteGenesis-Site/en_US/EswHL-Price
  • SFRA compatible Architecture:
    • GET https://hostname/on/demandware.store/Sites-RefArch-Site/en_US/EswRefArchHL-Price

Request Parameters

ESW ParametersTypeDescriptionNotes
priceDecimal (Required)Price of the product.-
countryString (Required)Two-letter ISO code of the shopper's country.-
currencyString (Optional)Three-letter ISO code of the shopper's local currency.If provided, the ESW plugin uses this currency. If not provided, the ESW plugin uses the currency code provided in the ESW Default Country Currency Mapping site preference.
applyAdjustBoolean (Optional)Indicates if the country adjustment should be applied.If provided, the country adjustment value is applied to the price accordingly.
applyRoundingBoolean (Optional)Indicates if the prices should be rounded.If provided, the prices are rounded accordingly.

Response

The formatted converted price in the shopper currency.

8. Order Cancelation

The ESW Order Cancelation is a webhook call that is initiated from the ESW system to the retailer’s system.

SFCC Custom Web Endpoint (Headless OCAPI)

For order cancelation requests in Headless OCAPI:

  • EswHL-CancelOrder endpoint is used for SiteGenesis compatible architecture.
  • EswRefArchHL-CancelOrder endpoint is used for SFRA compatible architecture.

This can be configured by importing systemobjects_headless.xml file from sitesdata/meta directory path.