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:
- On the target site, go to Administration > Site Development > Open Commerce API Settings.
- From the Select type drop-down, select Shop.
- From the Select Context drop-down, select the appropriate context, for example, Global (organization-wide) or site-specific.
- Enter the OCAPI Shop API resources provided in the
ocapi-configurations.jsonfile in the documentation folder. - Update the
client_idwith the one you generated from the Commerce Cloud Account Manager. - Click Save.
int_eshopworld_headlessis 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 Parameters | Description | Notes |
|---|---|---|
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 Attribute | Type | Product Base Pricing Attribute |
|---|---|---|
c_eswPrice | Decimal | price |
c_eswPrice_max | Decimal | price_max |
c_eswPrice_per_unit | Decimal | price_per_unit |
c_eswPrice_per_unit_max | Decimal | price_per_unit_max |
c_eswPrices | MapString, Number | prices |
c_shopperCurrency | String (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
| Parameter | Type | Description |
|---|---|---|
c_eswReturnProhibited | Boolean | true/false if product return is prohibited in current shopper country. |
c_eswRestrictedProduct | Boolean | true/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 Attribute | Data Type | Product Base Pricing Attribute |
|---|---|---|
c_eswPrice | Decimal | price |
c_eswPrice_max | Decimal | price_max |
c_eswPrice_per_unit | Decimal | price_per_unit |
c_eswPrice_per_unit_max | Decimal | price_per_unit_max |
c_eswPrices | MapString, Number | prices |
c_shopperCurrency | String (3-char ISO) | - |
c_eswReturnProhibited | Boolean | true/false if product return is prohibited in current shopper country. |
c_eswRestrictedProduct | Boolean | true/false if product is restricted in current shopper country. |
Extension Points (PDP + PLP/CLP)
| Extension Point | ESW Extension Script | Notes |
|---|---|---|
dw.ocapi.shop.product.beforeGET | /int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/setOverridePriceBook.js | Mainly 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.js | Used 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.js | Used 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)
| Attribute | Type | Description |
|---|---|---|
c_eswUnitPrice | Decimal | basePrice (per unit) |
c_eswReturnProhibited | Boolean | true/false if return is prohibited in current shopper country. |
c_eswRestrictedProduct | Boolean | true/false if product is restricted in current shopper country. |
Extension Points (Basket)
| Extension Point | ESW Extension Script | Notes |
|---|---|---|
dw.ocapi.shop.basket.afterPOST | /int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/setOverridePriceBook.js | Mainly 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.js | Standard 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 Parameters | Description | Notes |
|---|---|---|
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)
ESW PreOrder Service Response — FAILED (example)
4.2 Order Hook Extension Points
| Extension Point | ESW Extension Script | Notes |
|---|---|---|
dw.ocapi.shop.order.beforePOST | /int_eshopworld_headless/cartridge/scripts/ocapi/shop/hooks/orderHooks.js | Used 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.js | Sets 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.js | Calls 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.
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-Notifyendpoint is used for SiteGenesis compatible architectureEswRefArchHL-Notifyendpoint 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 Parameters | Type | Description | Notes |
|---|---|---|---|
price | Decimal (Required) | Price of the product. | - |
country | String (Required) | Two-letter ISO code of the shopper's country. | - |
currency | String (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. |
applyAdjust | Boolean (Optional) | Indicates if the country adjustment should be applied. | If provided, the country adjustment value is applied to the price accordingly. |
applyRounding | Boolean (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-CancelOrderendpoint is used for SiteGenesis compatible architecture.EswRefArchHL-CancelOrderendpoint is used for SFRA compatible architecture.
This can be configured by importing systemobjects_headless.xml file from sitesdata/meta directory path.