# 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. - [Product data model overview](/developer-portal/app-development/product-model) - [Product and variant data model details](/developer-portal/app-development/product-with-variants-model) ## 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:** - [**GetProduct:**](/api-reference/services/productservice/openapi/products/getproduct) Or one of its siblings, retrieves product data, including text, parameters, and variants. - [**ListProductRelations:**](/api-reference/services/productservice/openapi/relations/listproductrelations) Retrieves related products. - [**ListPromotionsByProductId:**](/api-reference/services/productservice/openapi/promotions/listpromotionsbyproductid) Retrieves promotions for the product. **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](/developer-portal/app-development/frontend-development-design). ## 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** ```csharp // 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](/solution-portal/detailed-design/availability-structure). ### 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** ```csharp // 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](/developer-portal/app-development/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-reference/services/productservice/openapi/products/updateproductviewcount) API to increment the product's view statistics. > For more on popularity, see [Product Popularity in Norce](/user-portal/pim/product-popularity). ## Suggested further reading - [Listing products and variants](/developer-portal/app-development/working-with-listing-products-and-variants) - [Frontend development](/developer-portal/app-development/frontend-development-design) design patterns and practices