DocumentationAPI Reference
Documentation

Price Localization

About

Consumers are most comfortable shopping in their local currency. This component localizes prices and promotions automatically by detecting their local currency based on their geolocation.

Local prices are used through the Reach checkout process on the view/template level with no business logic changes. Both Reach and B2C local currencies that can be used.

Configuration

👍

Be sure to configure Reach's service profiles in order to use Reach localization.

850

Business Manager: Merchant Tools > Site Preferences > Custom Site Preference Groups > Reach

  • Enable Sandbox Mode - Used to switch between Sandbox and Production.
  • Enable localization - Reach localization can be disabled without code changes with this setting.
  • Forbid currency selection - If yes, the customer won't be able to change their autodetected currency.
  • Allowed currencies - Comma separated list of currency codes to allow for localization and will be displayed in the currency dropdown. Confirm that the currencies listed here are enabled either at Reach or locally on your site.
  • Maximum rate lifetime - Currency rates are valid for 24 hours and by default are updated every six hours.
  • Price Format - Reach prices run under the same site locale and are not tied to the SCC B2C site locale and language. This field allows you to set the money format in a way that makes most sense for international customers.
    • The price format value should be in Java MessageFormat with 4 optional parameters.
    • Parameters:
      • {0} = price value;
      • {1} = Money symbol (first available in this order: Reach | Demandware | currency code);
      • {2} = Reach symbol ( first available in this order: Reach | code) ;
      • {3} = DW symbol ( first available in this order: Demandware | code) ;
      • {4} = currency code;
    • If decimals are present in the format, they will be automatically fixed to match the currency's minor units.
480

The currency dropdown displays in place of the default locale dropdown.

Implementation

The Reach component is remote included in the site template with the base price passed as an argument to generate formatted and converted prices. This process allows for page caching.

When the customer's currency is first detected or selected from the dropdown a current rate offer is retrieved by Reach. The rate offer is valid for 24 hours and resets once the configured max lifetime is reached.

796
<!-- old template -->
price: <isprint value="${price.value}" />
<!-- new template -->
price: <isinclude url="${URLUtils.url('Reach-Price', 'price', price.value}" />

Localizing Custom Code

Currency and rate information is exposed for localizing custom templates or components.

Templates

Remote include the Reach controller in a custom template to gain access to the following methods:

  • /Reach-Currency returns the currently selected currency code
  • /Reach-Symbol returns the currently selected currency symbol
  • /Reach-Price?price={Number}&format={formatted* | decimal | raw} returns the given price converted to the selected currency
    • price: required, the base price value. (Ex. 123.45)
    • format: optional formatting to be applied
      • formatted: default value, formats as Money value according selected currency rules (Ex. "$ 123.45")
      • decimal: formats as Decimal value according selected currency minor units (Ex. "123.40")
      • raw: does not apply formatting, returns raw number value (Ex. "123.4" )
<isscript>
// set some sample price data:
baseCurrency = "EUR";
basePrice = new dw.value.Money(100, baseCurrency);
</isscript>

base price:    [<isprint value="${basePrice}" />]
base currency: [<isprint value=${basePrice.currencyCode} />]

localized price:    [<isinclude url="${URLUtils.url('Reach-Price','price', basePrice.value}" />]
localized currency: [<isinclude url="${URLUtils.url('Reach-Currency'}" />]

<!--
Example output:
base price:    [€100]
base currency: [EUR]

localized price:    [CHF 112]
localized currency: [CHF]
-->

Scripts

For script localization, reachLocalization.getReachPrice() returns a ReachPriceModel object and follows the SFRA default price model with these attributes:

  • .currency
  • .value
  • .formatted
  • .decimalValue
const reachLocalization =
require('*/cartridge/scripts/reach/reachLocalization');
  let basePrice = 100;
  let reachPrice = reachLocalization.getReachPrice(basePrice);
  
  trace("Localized price: " + reachPrice.formatted);
  
  let currentCurrency = reachLocalization.currency;
  trace("Selected currency: " + currentCurrency.code + "; isBase: " + currentCurrency.isBase);

Assets and Slots

Remote include the Reach controller for asset or slot localization.

<div class="header-promotion">
<strong>FREE 2-Day SHIPPING</strong> FOR ORDERS OVER $include('Reach-Price', 'value', 300, 'format', 'formatted')$
</div>

Customization

SFRA standards should be followed when customizing the Reach component. The cartridge is built in a modular and object oriented way to facilitate overriding code.

Localization is provided by the reachLocalization module (/bc_reach/cartridge/scripts/reach/reachLocalization.js) and exposes methods like:

  • getCurrency()
  • getReachPrice()
  • switchToCurrency()

The cartridge also has its own error and logging classes for flexible error handling.

Multi-locale

The cartridge as-is does not support multi-locale sites.. An SI can extend the Reach cartridge to support multi-locale sites depending on the retailer's custom business logic.

Privacy Data

The customer's IP address is used to preselect the default customer currency. No other customer data is collected.