Commerce Pricing API Reference
Corecommerce
Overview
Section titled “Overview”The Pricing API resolves, reads, and writes prices for catalog entries. IPriceService handles read-only price resolution. IPriceDetailService provides full CRUD for price records.
Namespace
Section titled “Namespace”Optimizely.Commerce.Catalog.Provider
Key interfaces
Section titled “Key interfaces”| Interface | Purpose |
|---|---|
IPriceService | Read-only price lookups with filtering |
IPriceDetailService | Full CRUD for individual price records |
IPriceService
Section titled “IPriceService”GetPrices(MarketId, DateTime, CatalogKey, PriceFilter)
Section titled “GetPrices(MarketId, DateTime, CatalogKey, PriceFilter)”Returns matching prices for a catalog entry filtered by market, currency, and customer group.
Parameters
| Name | Type | Description |
|---|---|---|
market | MarketId | Target market identifier |
validOn | DateTime | Date for price validity check |
catalogKey | CatalogKey | Entry code wrapped in CatalogKey |
filter | PriceFilter | Currency, quantity, and customer pricing group filters |
Returns: IEnumerable<IPriceValue>
Get prices for an entry
public class PriceLookupService
{
private readonly IPriceService _priceService;
public PriceLookupService(IPriceService priceService)
{
_priceService = priceService;
}
public IEnumerable<IPriceValue> GetCurrentPrices(string entryCode, MarketId market)
{
var filter = new PriceFilter
{
Currencies = new[] { new Currency("USD") },
ReturnCustomerPricing = false
};
return _priceService.GetPrices(
market,
DateTime.UtcNow,
new CatalogKey(entryCode),
filter);
}
} GetCatalogEntryPrices(IEnumerable<CatalogKey>)
Section titled “GetCatalogEntryPrices(IEnumerable<CatalogKey>)”Bulk price lookup for multiple entries.
Parameters
| Name | Type | Description |
|---|---|---|
catalogKeys | IEnumerable<CatalogKey> | Collection of entry codes |
Returns: IEnumerable<IPriceValue> — all prices for the given entries
IPriceDetailService
Section titled “IPriceDetailService”List(ContentReference)
Section titled “List(ContentReference)”Returns all price detail records for a catalog entry.
Parameters
| Name | Type | Description |
|---|---|---|
entryContentLink | ContentReference | Content reference to the variant |
Returns: IList<IPriceDetailValue>
Save(IEnumerable<IPriceDetailValue>)
Section titled “Save(IEnumerable<IPriceDetailValue>)”Creates or updates price records.
Parameters
| Name | Type | Description |
|---|---|---|
prices | IEnumerable<IPriceDetailValue> | Price records to save |
Returns: void
Throws: ValidationException if price data is invalid
Set a price for a variant
public void SetPrice(
ContentReference variantLink,
string entryCode,
decimal amount,
Currency currency,
MarketId market)
{
var priceDetail = new PriceDetailValue
{
CatalogKey = new CatalogKey(entryCode),
MarketId = market,
UnitPrice = new Money(amount, currency),
ValidFrom = DateTime.UtcNow,
ValidUntil = null,
MinQuantity = 0,
CustomerPricing = CustomerPricing.AllCustomers
};
_priceDetailService.Save(new[] { priceDetail });
} Delete(IEnumerable<long>)
Section titled “Delete(IEnumerable<long>)”Deletes price records by their IDs.
Parameters
| Name | Type | Description |
|---|---|---|
priceDetailIds | IEnumerable<long> | Price record IDs to delete |
Returns: void
Delete prices for a variant
var prices = _priceDetailService.List(variantLink);
var priceIds = prices.Select(p => p.PriceValueId).ToList();
_priceDetailService.Delete(priceIds); IPriceValue properties
Section titled “IPriceValue properties”| Property | Type | Description |
|---|---|---|
CatalogKey | CatalogKey | Entry code reference |
MarketId | MarketId | Market this price applies to |
UnitPrice | Money | Price amount and currency |
ValidFrom | DateTime | Start of validity window |
ValidUntil | DateTime? | End of validity window (null = no expiry) |
MinQuantity | decimal | Minimum quantity for tiered pricing |
CustomerPricing | CustomerPricing | Customer group restriction |
Price resolution order
Section titled “Price resolution order”- Customer-specific prices (matching customer pricing group)
- Sale prices (time-bound with
ValidFrom/ValidUntil) - Tiered prices (matching
MinQuantity) - Base price (no restrictions,
MinQuantity = 0)
Common exceptions
Section titled “Common exceptions”| Exception | Cause |
|---|---|
ValidationException | Missing required fields (currency, market, amount) |
CatalogEntryNotFoundException | Entry code does not exist |