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

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.

oldprices.png

** New schema **

newprice.png

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;