Storefront Reference Architecture (SFRA)

Customizing the ESW integration in SFRA

1. Customizing the code

When customizing the ESW integration in SFRA, ensure changes are applied to the correct cartridge and file paths. Below are the referenced customization touchpoints from the PDF.

Templates

File Path

int_eshopworld_sfra/cartridge/templates/default/common/layout/page.isml

Description

Base SFRA page layout template (referenced as a customization touchpoint in the overlay cartridge).


Controllers

File Path

int_eshopworld_sfra/cartridge/controllers/Page.js

Description

SFRA controller referenced as an ESW customization touchpoint.


Models

File Path

int_eshopworld_sfra/cartridge/models/productLineItem/decorators/priceTotal.js

Description

Line item price decorator adds ESW-aware non-adjusted/adjusted pricing logic (order history vs live basket).

var eswHelper = require('*/cartridge/scripts/helper/eswSFRAHelper');
var orderHistoryFlag = false;
var eswShopperCurrencyCode = null;
var eswModuleEnabled = eswHelper.getEShopWorldModuleEnabled();

if (lineItem.lineItemCtnr && Object.hasOwnProperty.call(lineItem.lineItemCtnr, 'orderNo')) {
  if (lineItem.lineItemCtnr.orderNo != null) {
    orderHistoryFlag = true;
    eswShopperCurrencyCode = lineItem.lineItemCtnr.originalOrder.custom.eswShopperCurrencyCode;
  }
}

if (lineItem.priceAdjustments.getLength() > 0) {
  if (orderHistoryFlag) {
    result.nonAdjustedPrice = (eswShopperCurrencyCode != null) ? /* ... */ : /* ... */;
  } else {
    var nonAdjustedPrice = (eswModuleEnabled) ? eswHelper.getMoneyObject(/* ... */) : /* ... */;
    result.nonAdjustedPrice = (eswModuleEnabled) ? new Money(nonAdjustedPrice) : /* ... */;
  }
}

if (!orderHistoryFlag) {
  price = lineItem.adjustedPrice;
  // The platform does not include prices for selected option value price by default.
  // So, we must add the option price to get the ...
  collections.forEach(lineItem.optionProductLineItems, function (item) {
    price = price.add(item.adjustedNetPrice);
  });
}

Scripts and JSON

File Path

modules/server/request.js

Description

Server request hook behavior: sets currency/locale normally when ESW disabled; sets ESW location when enabled.

var Site = require('dw/system/Site').getCurrent();
var eswEnabled = Site.getCustomPreferenceValue('eswEshopworldModuleEnabled');
var eswHelper = require('*/cartridge/scripts/helper/eswHelper').getEswHelper();

if (!eswEnabled) {
  setCurrency(request, session);
} else {
  var country = request.httpParameterMap.get(Site.getCustomPreferenceValue('eswCountryUrlParam'));
  eswHelper.setLocation(country);
}

Client scripts

File Path

int_eshopworld_sfra/cartridge/client/default/js/product/detail.js

Description

Product detail page client script listed as extended customization surface.