Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Product Price Calculation

Whenever you are going to show prices on your frontend it being on the category listing or the product page you are going to use CatalogLibrary to get a price calculation for your product(s). In this article, we will go more in-depth with how price calculations work.

How it works

The price calculation APIs and DTOs are designed to let you get multiple prices for multiple products in multiple price groups - if you want. This makes it easy to do price lists when browsing categories or product pages and lets you easily show different price points for the same product if you are using tiered pricing or differentiated pricing. Basically, you will get a matrix back where you can get the price for a product in a specific price group and a specific price tier.

Product Price Calculation DTOs

Ucommerce.Catalog.Models.ProductPriceCalculationResult


Properties

  • Return type IDictionary<string, Object>

Items

  • Return type IList<Ucommerce.Catalog.Models.Item>

Ucommerce.Catalog.Models.ProductPriceCalculationResult.Item


Properties

  • Return type IDictionary<string, Object>

ProductGuid

  • Return type Guid

PriceGroupGuid

  • Return type Guid

CurrencyISOCode

  • Return type string

Sku

  • Return type string

VariantSku

  • Return type string

MinimumQuantity

  • Return type int

MaximumQuantity

  • Return type int

PriceInclTax

  • Return type Decimal
  • Description
    The price the customer actually pays including Tax.

PriceExclTax

  • Return type Decimal
  • Description
    The price the customer actually pays excluding Tax.

ListPriceInclTax

  • Return type Decimal
  • Description
    Unmodified list price of product including Tax.

ListPriceExclTax

  • Return type Decimal
  • Description
    Unmodified list price of product excluding Tax.

DiscountInclTax

  • Return type Decimal
  • Description
    Unit discount on product including Tax.

DiscountExclTax

  • Return type Decimal
  • Description
    Unit discount on product excluding Tax.

DiscountTax

  • Return type Decimal

DiscountPercentage

  • Return type Decimal

PriceTax

  • Return type Decimal
  • Description
    Tax payable.

ListTax

  • Return type Decimal

Top level APIs

To get price calculations you can use the top level API for that.

    Ucommerce.Api.ICatalogContext catalogContext = ObjectFactory.Instance.Resolve<Ucommerce.Api.ICatalogContext>();
    Ucommerce.Api.ICatalogLibrary catalogLibrary = ObjectFactory.Instance.Resolve<Ucommerce.Api.ICatalogLibrary>();
    
    Ucommerce.Search.Models.Product currentProduct = catalogContext.CurrentProduct;
    Ucommerce.Search.Models.PriceGroup currentPriceGroup = catalogContext.CurrentPriceGroup;
    
    Ucommerce.Catalog.Models.ProductPriceCalculationResult result = 
        catalogLibrary.CalculatePrices(
            new List<Guid>() {currentProduct.Guid}, 
            new List<Guid>() {currentPriceGroup.Guid});
    
    

Price Query

The underlying price calculation is implemented in two different ways:

  • One that evaluates marketing foundation
  • One that leaves out marketing foundation

In some cases, you might want to leave out marketing foundation which is possible by either disabling all active campaigns, or if you want to leave out discounts calculated when showing prices, but not when adding them to your basket.

The actual components that are calculating prices for display purpose are implemented as two queries of the query type

NHibernateQueryBase<ProductPriceQueryArgs, ProductPriceQueryResult>:

UCommerce.NHibernate.Impl.DiscountAppliedProductPriceQuery UCommerce.NHibernate.Impl.ProductPriceQuery

If you want to swap them out, this is done via configuration of Castle Windsor.