Skip to content
Last updated

Working with Products and Variants in Norce Commerce

Overview:
This guide explains how to retrieve, present, and process product and variant data using Norce Commerce ProductService. It covers best practices for API usage, business logic, and frontend/backend responsibilities.

Understanding the Product Model

The product entity in Norce Commerce is complex and may return extensive data. Clients should understand the structure to efficiently map and use only the necessary elements.

Retrieving and Presenting Product Data

To display a product in your application, determine which API calls are required for all necessary data. Fetch data in parallel and cache locally for performance.

Typical API calls for product presentation:

Best practice:
Consolidate all data on the product page. The backend should map API responses to your object model before passing to the frontend. Cache only the mapped DTOs you need for performance.

More on frontend design patterns, see Frontend Development Using Norce Commerce Services.

Common Business Logic for Products and Variants

Backend layers often implement business logic based on product data. Below are common examples, each with context and sample code.

Product Availability Logic

Norce Commerce provides stock information, but the backend should translate this into customer-facing messages.

Example: Availability validation logic

// Returns a user-friendly availability message based on stock values.
private string ValidateAvailability(int onHandValue, int? stockDisplayBreakPoint)
{
    if (onHandValue >= stockDisplayBreakPoint.GetValueOrDefault(0))
        return "Is in Stock";
    else if (onHandValue > 0)
        return "Only few items in stock";
    return "Out of stock";
}

For details on the availability structure, see Availability Structure in Norce.

Buyability Validation

The IsBuyable field from Norce Commerce is not always sufficient. Many clients add custom rules to determine if a product can be purchased.

Example: Buyability validation logic

// Validates if a product is buyable based on Norce flag and stock.
private bool ValidateBuyable(bool norceIsBuyableFlag, int onHandValue, int? stockDisplayBreakPoint)
{
    if (!norceIsBuyableFlag)
        return false;
    if (onHandValue > 0)
        return true;
    return false;
}

Always validate buyability in your backend. See Product Model: Buying Information.

Updating Product View Count

Norce Commerce tracks product popularity, which can affect sort order in listings. You can update view counts based on your application's logic (e.g., on product page view, preview, or search).

How to update view count:
Call the UpdateProductViewCount API to increment the product's view statistics.

For more on popularity, see Product Popularity in Norce.

Suggested further reading