Hide menu Last updated: Oct 12 2015

PriceType examples

This topic provides examples for using the Episerver Commerce APIs to work with PriceType features, such as how to get price types definitions.

Adding custom price types

You can add a new line within the SalePriceTypes section in the ecf.catalog.config file, this will make a new Price Type to be added to the system.

<SalePriceTypes>
<add key="NewCustomPriceType" value="3" description="New Custom Price Type" />
<add key="JurisdictionGroup" value="4" description="Jurisdiction Group"/>
</SalePriceTypes>

Note: The value needs to be unique and it must be greater or equal to 3.

Getting all price types - enum and configuration

PriceTypeConfiguration.PriceTypeDefinitions returns all price types, including predefined price types and price types that were defined in configuration.

namespace CodeSamples.Mediachase.Commerce.Pricing
{
public class PriceTypeConfigurationSample
{
#region GetPriceTypeFromEnumAndConfiguration
public IDictionary<CustomerPricing.PriceType, PriceTypeDefinition> GetAllPriceTypeDefinitions()
{
// Get all price types - included predefined and price types from configuration file.
var priceTypeDefinitions = PriceTypeConfiguration.Instance.PriceTypeDefinitions;
return priceTypeDefinitions;
}
#endregion
}
}

Adding your own customer price group

Customer Price Group is a predefined price type that should be matched with a specific sale code. The different options availiable to marketeers is predefined to: Customer, Partner and Distributor.  As a developer you can add items to that predefined list, to make your own customer price group become available in the drop-down for selection.

Populate the list by adding the code as illustrated in the example below, and call that from your InitializationModule:

private void AddVIPCustomerPriceGroup()
{
    var metaFieldType = DataContext.Current.MetaModel.RegisteredTypes["ContactGroup"];
    var metaEnumItems = MetaEnum.GetItems(metaFieldType);
    var hasVIPGroup = metaEnumItems.Any(item => string.Equals(item.Name, "VIP", StringComparison.InvariantCultureIgnoreCase));
    if (!hasVIPGroup)
    {
        var lastIndex = metaEnumItems.Count();
        MetaEnum.AddItem(metaFieldType, "VIP", ++lastIndex);
    }
}

Related topics

Comments