SiteGenesis
Customizing the ESW integration in SiteGenesis
1. Customizing the code
When customizing the ESW integration in SiteGenesis, you must ensure changes are applied to the correct cartridge and file paths. Below is an example for customizing storefront templates
Templates
File Path
SiteGenesis_core/cartridge/templates/default/components/header/header.isml
Description
Loads ESW landing page, ESW header, app resources, and loader based on ESW module status and preferences.
File Path
SiteGenesis_core/cartridge/templates/default/checkout/components/minilineitems.isml
Description
Renders converted price for a single mini-cart line item.
File Path
SiteGenesis_core/cartridge/templates/default/search/suggestions.isml
Description
Autocomplete “from” price with conversion.
File Path
SiteGenesis_core/cartridge/templates/default/product/producttopcontentPS.isml
Description
Top content for product sets with ESW restriction messaging.
Controllers
File Path
SiteGenesis_controllers/cartridge/controllers/Currency.js
Description
Returns whether a selected country is ESW-allowed and echoes language/currency from cookies; exports web-exposed methods.
'use strict';
/**
* This controller updates the current session currency.
*
* @module controllers/Currency
*/
/* API Includes */
var Currency = require('dw/util/Currency');
var Transaction = require('dw/system/Transaction');
var Site = require('dw/system/Site');
/* Script Modules */
var guard = require('~/cartridge/scripts/guard');
var Cart = require('~/cartridge/scripts/models/CartModel');
/**
* This controller is used in an AJAX call to set the session variable 'currency'.
*/
function setSessionCurrency() {
var eswHelper = require('*/cartridge/scripts/helper/eswHelper').getEswHelper();
var currencyMnemonic = request.httpParameterMap.currencyMnemonic.value;
var Response = require('~/cartridge/scripts/util/Response');
var Countries = require('*/cartridge/scripts/util/Countries');
var URLUtils = require('dw/web/URLUtils');
var redirect = null;
if (eswHelper.getEShopWorldModuleEnabled()) {
var selectedCountry;
var countryParam = request.httpParameterMap.get(Site.getCustomPreferenceValue('eswCountryUrlParam'));
if (empty(countryParam)) {
selectedCountry = countryParam;
} else {
selectedCountry = request.httpParameterMap.country.value;
}
var currencyCode = request.httpParameterMap.currency.value;
var language = request.httpParameterMap.language.value;
if (eswHelper.checkIsEswAllowedCountry(selectedCountry) != null) {
if (request.setLocale(language)) {
if (!eswHelper.overridePrice(selectedCountry)) {
eswHelper.setAllAvailablePriceBooks();
eswHelper.setBaseCurrencyPriceBook(eswHelper.getBaseCurrencyPreference());
}
}
eswHelper.selectCountry(selectedCountry, currencyCode, language);
} else {
delete session.privacy.fxRate;
var defaultCountryCurrencyMapping = eswHelper.getDefaultCountryCurrencyMapping();
if (defaultCountryCurrencyMapping.length > 0) {
eswHelper.createCookie('esw.location', selectedCountry, '/');
var siteCountries = JSON.parse(defaultCountryCurrencyMapping);
var foundCountry = siteCountries.filter(function(item) {
// Set Currency and Locale if esw not allowed country found
if (item.countryCode == selectedCountry) {
// Set cookies
eswHelper.createCookie('esw.currency', item.currencyCode, '/');
eswHelper.createCookie('esw.LanguageIsoCode', language, '/');
// Set Base currency Pricebook
eswHelper.setAllAvailablePriceBooks();
eswHelper.setBaseCurrencyPriceBook(item.currencyCode);
// Set locale
request.setLocale(language);
return true;
}
});
// Set Default Currency and Locale if esw not allowed country not found
if (empty(foundCountry)) {
eswHelper.setAllAvailablePriceBooks();
eswHelper.setBaseCurrencyPriceBook(eswHelper.getBaseCurrencyPreference());
eswHelper.createCookie('esw.currency', session.getCurrency(), '/');
eswHelper.createCookie('esw.LanguageIsoCode', dw.system.Site.getCurrent().getDefaultLocale(), '/');
request.setLocale(dw.system.Site.getCurrent().getDefaultLocale());
}
}
}
// redirect = eswHelper.getCurrent(request.getLocale());
} else {
if (currencyMnemonic) {
currency = Currency.getCurrency(currencyMnemonic);
if (currency) {
session.setCurrency(currency);
Transaction.wrap(function () {
var currentCart = Cart.get();
if (currentCart) {
currentCart.updateCurrency();
currentCart.calculate();
}
});
}
}
}
Response.renderJSON({
redirectUrl: (redirect != null) ? redirect.toString() : '',
success: true
});
}
function getAllowedCountry() {
var Response = require('~/cartridge/scripts/util/Response');
var eswHelper = require('*/cartridge/scripts/helper/eswHelper').getEswHelper()
var language = !empty(request.httpCookies['esw.LanguageIsoCode']) ? request.httpCookies['esw.LanguageIsoCode'].value : eswHelper.getAllowedLanguages()[0].value;
var currency = !empty(request.httpCookies['esw.currency']) ? request.httpCookies['esw.currency'].value : eswHelper.getDefaultCurrencyForCountry(eswHelper.getAvailableCountry());
var selectedCountry = request.httpParameterMap.country.value;
var flag = false;
if (eswHelper.getEShopWorldModuleEnabled() && eswHelper.checkIsEswAllowedCountry(selectedCountry)) {
flag = true;
}
Response.renderJSON({
success : flag,
country : selectedCountry,
language : language,
currency : currency
});
}
/*
* Module exports
*/
/*
* Web exposed methods
*/
/** @see module:controllers/Currency~setSessionCurrency */
exports.SetSessionCurrency = guard.ensure(['get'], setSessionCurrency);
exports.GetAllowedCountry = guard.ensure(['get'], getAllowedCountry);
2. Customizing The Pipeline
- To enable the ESW SFCC plugin, the retailers' technical team needs to compare listed controllers from 1.2 ‘Customizing the controllers’ section, with SG pipelines and make the required customizations/changes. ESW does not support the siteGenesis pipelines version.
- siteGenesis custom controllers can be found on the following path for comparison:
Path:
SiteGenesis_controllers/cartridge/controllers/Cart.jsSiteGenesis_controllers/cartridge/controllers/Currency.jsSiteGenesis_controllers/cartridge/controllers/COCustomer.js
Scripts and JSON
File Path
SiteGenesis_core/cartridge/scripts/util/Resource.ds
Description
Key URL selectors used by ESW flows.
Name
GetMoneyObject(price, noAdjustment, formatted, noRounding)
Description
Helper used wherever prices are calculated or displayed
GetMoneyObject (price, noAdjustment, formatted, noRounding)
- price: This can be a number or a money object, for example, price.
- noAdjustment: Boolean value. If true, no adjustment will be applied.
- formatted: Boolean value. If true, it returns a string value with currency code, for example, $10.00. If false, it returns money object with the currency and the price.
- noRounding: Boolean value. If true, no rounding rule will be applied.
This function is a helper function that is used anywhere prices need to be calculated or displayed. It checks whether a country is a Fixed price country or an FX price country. It applies FX conversions when applicable. It also applies adjustments, duty, and tax where required.