Last updated

Working with Products and variants

The Product model

The product entity in Norce is complex, and the API may return a lot of data that is either utilized or discarded based on the client's requirements. Understanding and get a familiarity of the entities and the common elements of the product model is key. See the linked pages below.

Product presentation

To display a product on a page in your application, you must determine which calls are required to obtain all the necessary data for the product, and fetch the different data in parallel while caching it locally.

For example, in this scenario, three calls are made: GetProduct, ListProductRelations, and ListPromotionsByProductId.

The idea is that all this data is consolidated on the same product page, and the backend layer is responsible for receiving and mapping the data to its object model before passing it to the frontend.

Map only what you need, and it is usually best to cache your DTO for faster performance.

Read more about this in the Frontend Development Using Norce Commerce Services guide.

Common business logic

Here are some examples of the kind of business logic that is usually handled in the backend layer.

Availability

Norce Commerce provides information on how much of the product is in stock based on the available information. However, it is up to the backend implementation to translate this into something that the customer sees.

Simple code example

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";
}

Read more about the availability structure in Norce here.

Is Buyable

Norce Commerce returns an IsBuyable field, but this is usually not enough for handling validation. Many clients have their own rules here.

Simple code example

private bool ValidateBuyable(bool stormIsBuyableFlag, int onHandValue, int? stockDisplayBreakPoint)
{
    if (!stormIsBuyableFlag)
        return false;
    if (onHandValue > 0)
        return true;
    return false;
}

Update the view count

Norce Commerce has a "rich popularity" functionality, which is a way to manipulate the sort order in listings. One factor that can influence the popularity ranking is how much a product is viewed in the commerce apps. Depending on your implementation, you can decide when this statistic should be updated in Norce Commerce, such as when someone looks at a preview, the product page, only direct searches from Google, or exempt some users, actions, or factors.

Call the method UpdateProductViewCount to add view counts to the statistics that can be used by the popularity functionality.

Read more about popularity here.

Suggested further reading