Try our conversational search powered by Generative AI!

Loading...
Applies to versions: 14 and higher
Other versions:
ARCHIVED This content is retired and no longer maintained. See the version selector for other versions of this topic.

PriceType examples

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

This topic provides examples for using the Optimizely Commerce APIs to work with PriceType features.

Working with PriceType

Adding custom price types

To add a new PriceType, add a new line within the SalePriceTypes of CatalogOptions in appsettings.json file.

"EPiServer": {
  "Commerce": {
    "CatalogOptions": {
      "SalePriceTypes": [
        {
          "Key": "NewCustomPriceType",
          "Value": "3",
          "Description": "New Custom Price Type"
        },
        {
          "Key": "JurisdictionGroup",
          "Value": "4",
          "Description": "Jurisdiction Group"
        }
      ]
    }
  }
}

Note: The value must be unique and 3 or greater.

Getting all price types enumum and configuration

PriceTypeConfiguration.PriceTypeDefinitions returns all price types, including predefined price types and price types defined in the 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. Options available to marketers are predefined as: Customer, Partner, and Distributor.

As a developer, you can add items to that list, to make your own customer price group available in the drop-down.

PriceScreen.png

Populate the list by adding the code in the example below, and call that from your initialization module.

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);
      }
  }
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading