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
Property | Type | Description |
---|---|---|
Properties | IDictionary<string,object> | Dynamic list of properties for custom use. |
Items | IList<UCommerce.Catalog.Models.ProductPriceCalculationResult.Item> | Individual price calculations for products in different price groups and price tiers. |
UCommerce.Catalog.Models.ProductPriceCalculationResult.Item
Property | Type | Description | |
---|---|---|---|
Properties | IDictionary<string,object> | Dynamic list of properties for custom use. | |
ProductGuid | Guid | Identifier for the product | |
PriceGroupGuid | Guid | Identifier for the price group used. | |
Sku | string | Identifier for the product. | |
VariantSku | string | Identifier for the price group used. Null if product family. | |
MinimumQuantity | int | Associated with a price tier. This is the minimum amount of products you can have in your basket to fit this price tier. | |
MaximumQuantity | int | Associated with a price tier. This is the maximum amount of products you can have in your basket to fit this price tier. | |
PriceInclTax | decimal | The price the customer needs to pay with discounts subtracted including tax. | |
PriceExclTax | decimal | The price the customer needs to pay with discounts subtracted excluding tax. | |
PriceTax | decimal | tax for the calculated price. | |
ListPriceInclTax | decimal | List price for the product as configured in the backend including tax. | |
ListPriceExclTax | decimal | List price for the product as configured in the backend excluding tax. | |
ListTax | decimal | tax for the ListPrice. | |
DiscountInclTax | decimal | The effective discount for the price including tax. | |
DiscountExclTax | decimal | The effective discount for the price excluding tax. | |
AmountOff | decimal | Total fixed discount for the product without tax. Does not include the percentageOff discounts. | |
PercentageOff | decimal | The percentage discount for the product without tax. |
Top level APIs
To get price calculations you can use the top level API for that.
UCommerce.EntitiesV2.Product currentProduct = UCommerce.Runtime.SiteContext.Current.CatalogContext.CurrentProduct; UCommerce.EntitiesV2.PriceGroup = UCommerce.Runtime.SiteContext.Current.CatalogContext.CurrentPriceGroup; UCommerce.Catalog.Models.ProductPriceCalculationResult = UCommerce.Catalog.Models.ProductPriceCalculationResult CalculatePrice(new List<Guid>() { product.Guid }, new List<Guid>() { product.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.