本文整理汇总了C#中IMeasureService.GetMeasureWeightById方法的典型用法代码示例。如果您正苦于以下问题:C# IMeasureService.GetMeasureWeightById方法的具体用法?C# IMeasureService.GetMeasureWeightById怎么用?C# IMeasureService.GetMeasureWeightById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMeasureService
的用法示例。
在下文中一共展示了IMeasureService.GetMeasureWeightById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatBasePrice
/// <summary>
/// Format base price (PAngV)
/// </summary>
/// <param name="product">Product</param>
/// <param name="productPrice">Product price (in primary currency). Pass null if you want to use a default produce price</param>
/// <param name="localizationService">Localization service</param>
/// <param name="measureService">Measure service</param>
/// <param name="currencyService">Currency service</param>
/// <param name="workContext">Work context</param>
/// <param name="priceFormatter">Price formatter</param>
/// <returns>Base price</returns>
public static string FormatBasePrice(this Product product, decimal? productPrice, ILocalizationService localizationService,
IMeasureService measureService, ICurrencyService currencyService,
IWorkContext workContext, IPriceFormatter priceFormatter)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null)
throw new ArgumentNullException("localizationService");
if (measureService == null)
throw new ArgumentNullException("measureService");
if (currencyService == null)
throw new ArgumentNullException("currencyService");
if (workContext == null)
throw new ArgumentNullException("workContext");
if (priceFormatter == null)
throw new ArgumentNullException("priceFormatter");
if (!product.BasepriceEnabled)
return null;
var productAmount = product.BasepriceAmount;
//Amount in product cannot be 0
if (productAmount == 0)
return null;
var referenceAmount = product.BasepriceBaseAmount;
var productUnit = measureService.GetMeasureWeightById(product.BasepriceUnitId);
//measure weight cannot be loaded
if (productUnit == null)
return null;
var referenceUnit = measureService.GetMeasureWeightById(product.BasepriceBaseUnitId);
//measure weight cannot be loaded
if (referenceUnit == null)
return null;
productPrice = productPrice.HasValue ? productPrice.Value : product.Price;
decimal basePrice = productPrice.Value /
//do not round. otherwise, it can cause issues
measureService.ConvertWeight(productAmount, productUnit, referenceUnit, false) *
referenceAmount;
decimal basePriceInCurrentCurrency = currencyService.ConvertFromPrimaryStoreCurrency(basePrice, workContext.WorkingCurrency);
string basePriceStr = priceFormatter.FormatPrice(basePriceInCurrentCurrency, true, false);
var result = string.Format(localizationService.GetResource("Products.BasePrice"),
basePriceStr, referenceAmount.ToString("G29"), referenceUnit.Name);
return result;
}