November Happy Hour will be moved to Thursday December 5th.

[11.8.2] Saving prices with a custom SalePriceType

Vote:
 

Hi,

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 
         CustomerPricing(CustomerPricing.PriceType.UserName, 
              accountId),
    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?

#195273
Edited, Jul 19, 2018 8:39
Vote:
 

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 ...

#195277
Jul 19, 2018 9:27
Vote:
 

Pretty sure this will work

(CustomerPricing.PriceType)3

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

#195318
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.