Select version
v7.18 v7.16 v7.13 v7.12 v7.11 v7.9 v7.8 v7.7 v7.6 v7.5 v7.3 v7.1 v7.0 v6.8 v6.7 v6.6 v6 v5 v4 v3 v2

Migrating Price Structure to Version 7.16

Since version 7.16 we've made changes to the pricing structure in Ucommerce. This means there's two breaking changes you need to be aware of. In this article we'll highlight those and see how we can fix them. Schema changes are applied automatically when updating, but there will be breaking changes in the code that needs to be fixed.

Schema changes

** Old schema **

In the old schema price were stored in the priceGroupPrice table with a relationship between the product and the pricegroup.


** New schema **


In the new schema, prices are stored in the new price table with a reference to a pricegroup and contains a guid. This makes it easier to store prices against a price group for anything else that are not a product.

In addition a new table ProductPrice exists where we will store prices for products. Furthermore there's a new quantity column that are used to store multiple price tiers per price group for a single product. This means that we are no longer able to assume a single price per price group for a product.

PriceGroupPrice prices becomes ProductPrice

First thing is that the concept PriceGroupPrice no longer exists. This has become just a price and can store any price for anything. The breaking changes are as follows:

  • PriceGroupPrice has been removed. ** UCommerce.EntitiesV2.Product.PriceGroupPrices no longer exists. ** Use the new UCommerce.EntitiesV2.Product.ProductPrices property instead.
  • UCommerce.EntitiesV2.Product.GetPrice(PriceGroup priceGroup) no longer exists.
  • UCommerce.EntitiesV2.Product.AddPriceGroupPrice(PriceGroupPrice priceGroupPrice) no longer exists.
  • UCommerce.EntitiesV2.Product.RemovePriceGroupPrice(PriceGroupPrice price) no longer exists.

New top level APIs for price calculations

    	UCommerce.EntitiesV2.Product currentProduct = UCommerce.Runtime.SiteContext.Current.CatalogContext.CurrentProduct;
    	UCommerce.Api.PriceCalculation priceCalculation = UCommerce.Api.CatalogLibrary.CalculatePrice(currentProduct);

The code above will still work in version 7.16 but the PriceCalculation type is now obsolete together with the old API and will be removed in a later version of Ucommerce. So to have a smoother upgrade path, It's encouraged to change to the new APIs before upgrading further.

The new APIs looks like the following:

    	UCommerce.Catalog.Models.ProductPriceCalculationResult CalculatePrice(IList<Guid> productGuids, IList<Guid> priceGroupGuids)

To use the new API and achieve what you had before:

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

When you show prices, you can do it either with or without Tax. Previously you could do this:

    	UCommerce.Api.PriceCalculation priceCalculation = UCommerce.Api.CatalogLibrary.CalculatePrice(currentProduct);
    	var priceForTheCustomer = priceCalculation.YourPrice.Amount;

The amount property on YourPrice would observe the configuration on the catalog to show prices with or without tax. This is something that looks a little different now as we only provide prices with and without Tax. You can very easly make up for this:

    	UCommerce.EntitiesV2.ProductCatalog = UCommerce.Runtime.SiteContext.Current.CatalogContext.CurrentCatalog;
    	UCommerce.Catalog.Models.ProductPriceCalculationResult result = UCommerce.Catalog.Models.ProductPriceCalculationResult CalculatePrice(new List<Guid>() { product.Guid }, new List<Guid>() { priceGroup.Guid });
    	var priceForProductItem = result.Items.First(x => x.ProductGuid = product.Guid && x.PriceGroupGuid == priceGroup.Guid);
    	var priceToShow = UCommerce.Runtime.SiteContext.Current.CatalogContext.CurrentCatalog.ShowPricesIncludingVAT ? priceForProductItem.PriceInclTax  : priceForProductItem.PriceExclTax;
Ucommerce Aps - Vestergade 58N, 4th. floor - 8000 Aarhus C - Denmark
Phone +45 61 799 997 - Email [email protected] Ucommerce logo