Skip to content
Last updated

Overview

This page describes best practices and design patterns for developing front-end applications using Norce Commerce Services. It covers common architectures, configuration, caching, and integration patterns.

Front-end Architectures

A Norce-based commerce application consists of a back-end layer (which interacts with Norce Commerce Services) and one or more front-end layers (which run in browsers or on client devices). The front-end cannot call Norce Commerce Services directly; all service calls must go through the back-end.

There are two main ways to host the back-end layer:

CMS Hosted Back-end

Description of the CMS hosted back-end diagram:
The CMS hosts custom server-side components that retrieve and cache data and metadata from Norce Commerce Services. This is common in solutions using platforms like Optimizely, Umbraco, Sitevision, or Sitecore.

CMS hosted back-end

Self-hosted Back-end

Description of the self-hosted back-end diagram:
When a CMS is not required, the back-end can be hosted independently, allowing free choice of technology and platform. This is typical for "headless" CMS solutions such as Contentful or Prismic.

Self-hosted back-end

Responsibilities of the Back-end

The back-end layer is responsible for:

  • UI Interaction: Fetching data from services based on user actions.
  • Entity Mapping: Transforming Norce Commerce Services data into the subset required by the front-end.
  • Business Logic for Presentation: Applying additional business logic, such as converting stock status to availability messages.
  • Data Consolidation: Combining data from Norce and other sources (CMS, search services) into a client-specific model.
  • Client-specific Logic: Overriding or extending Norce business logic as needed.

Configuration Patterns

Content Delivery Network (CDN)

Norce Commerce Services provides images and files as keys (GUIDs). Combine these keys with a client-specific CDN URL to access the resources.

Example CDN URL:
http://[client-specific-CDN]/[ImageKey]

Example for resizing an image:
http://[client-specific-CDN]/[ImageKey]?w=100

See Image Scaling and CDN for more details.

OAuth2 Authentication

All requests to Norce must include the application-id or the older format Applicationid HTTP header. Missing this header results in a 500 error.

See OAuth2 access for details.

Cache Retention

Cache data whenever possible to improve performance. Organize data into groups with different retention periods.

Example cache groups:

GroupDataRetention
Long cacheApplication configuration, master lists24h
Medium cacheProduct info, product relations, customer info1h
Short cacheBasket, prices, availability5m

Development Patterns

Fetching Data with Batching and Caching

Description of the batching and caching diagram:
When a user requests a product, the back-end checks its cache. If data is missing, it sends parallel requests to Norce Commerce Services (e.g., GetProduct, ListProductRelations, ListPromotions). The back-end processes and maps the data, returns it to the front-end, and updates the cache.

Fetch data with batching and caching

Step-by-step process:

  1. User requests a product.
  2. Back-end checks cache.
  3. If not cached, back-end sends parallel requests to Norce.
  4. Back-end processes and maps responses.
  5. Front-end renders the view.
  6. Back-end updates cache as needed.
Note

Norce Commerce Services uses environment-specific IDs (e.g., ProductId, CategoryId). Always look up entities dynamically to get the correct ID for your environment.

Updating Data

When updating entities like the basket, always use the latest returned object from Norce Commerce Services.

Step-by-step process:

  1. User adds a product to the basket.
  2. Back-end calls Norce Commerce Services.
  3. Norce returns a new basket object.
  4. Replace the old basket with the new one in the front-end and cache.
  5. Note: Small changes (e.g., adding a product) can trigger promotions and affect the basket contents.

Always include AccountId for traceability. Use the user's account ID if logged in, or 1 if not.

Maintaining Context

Norce Commerce Services is stateless. The back-end must maintain session context and include all necessary information in each API call.

Example context parameters:

  • productId
  • searchString
  • storeSeed
  • priceListSeed
  • cultureCode

Table: Context usage in product methods

method inputDescriptionAction / Usage in Methods
productIdIdentifier of the productnot in context
searchStringfiltering the list of productscould either be kept in context, or be the result from a search input.
storeSeedShows additional availability from the stores on the productkeep in context, used in most product calls
priceListSeedShows additional product assortments and prices if exists.keep in context, used in most product calls
cultureCodeShows specific language content instead of default on applicationkeep in context, used in most product calls

Persistence

Decide what to store in cookies or other storage based on application needs. Typically, only IDs are persisted; objects are loaded from cache using these IDs.

Description of the persistence diagram:
IDs such as priceListSeed, accountId, customerId, basketId, cultureCode, and storeId are stored in cookies or session storage, depending on their scope.

Different cookies

Example persistence table:

ValueDescriptionScope
priceListSeedAdditional price lists other than the public. These are VIP or Loyalty club price listsStored during session
accountIdIdentifier of the know visitor to the siteStored in persisted cookie
customerIdIdentifier of the customer, this is usually the customer associated with the account, but sometimes notStored in persisted cookie
basketIdIdentifier of the active basketStored in persisted cookie
cultulureCodeChosen languageStored in persisted cookie
storeId (alt 1)Chosen physical store, orStored in persisted cookie
storeId (alt 2)Another scenario: Automatically resolved nearest physical storeStored during session

Tips and Common Practices

Preloading CDN Images

Preload popular product images to the CDN before launch to avoid cache misses and performance issues.

Resources and Examples

API Reference Portals

Further Reading