[11.8.2] Saving prices with a custom SalePriceType



I'm implementing a tiered pricing model for organizations following Shannon's blog here: https://world.episerver.com/blogs/Shannon-Gray/Dates/2012/7/Creating-tiered-pricing-for-organizations-and-visitor-groups/

I've added the custom SalePriceType:

With the new SalePriceType in place I now need to be able to create prices in code associated with this price type. The code to save a price requires creating a PriceDetailValue with a CustomerPricing object:

// Set Price Detail value for Catalog Entry.
var priceDetailValue = new PriceDetailValue
    CatalogKey = new CatalogKey(catalogEntry),
    MarketId = new MarketId("US"),
    CustomerPricing = new 
    ValidFrom = DateTime.UtcNow.AddDays(-7),
    ValidUntil = DateTime.UtcNow.AddDays(7),
    MinQuantity = 0m,
    UnitPrice = new Money(100m, Currency.USD)

The problem is I can't figure out how to create a new CustomerPricing with the PriceTypeId of my custom PriceType as the CustomerPricing uses an enum for PriceType.

Any ideas?

Edited, Jul 19, 2018 8:39

If I understand you correctly then this was introduced in both of my books ...

I'll see if I published it as a blog post ...

Jul 19, 2018 9:27

Pretty sure this will work


Then in your code you will need to cast to integer to check if it is your price type.

Jul 19, 2018 19:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.