本文整理汇总了C#中IPriceFormatter.FormatPrice方法的典型用法代码示例。如果您正苦于以下问题:C# IPriceFormatter.FormatPrice方法的具体用法?C# IPriceFormatter.FormatPrice怎么用?C# IPriceFormatter.FormatPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPriceFormatter
的用法示例。
在下文中一共展示了IPriceFormatter.FormatPrice方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareProductOverviewModels
//.........这里部分代码省略.........
//priceModel.AvailableForPreOrder = false;
if (permissionService.Authorize(StandardPermissionProvider.DisplayPrices))
{
//find a minimum possible price
decimal? minPossiblePrice = null;
Product minPriceProduct = null;
foreach (var associatedProduct in associatedProducts)
{
//calculate for the maximum quantity (in case if we have tier prices)
var tmpPrice = priceCalculationService.GetFinalPrice(associatedProduct,
workContext.CurrentCustomer, decimal.Zero, true, int.MaxValue);
if (!minPossiblePrice.HasValue || tmpPrice < minPossiblePrice.Value)
{
minPriceProduct = associatedProduct;
minPossiblePrice = tmpPrice;
}
}
if (minPriceProduct != null && !minPriceProduct.CustomerEntersPrice)
{
if (minPriceProduct.CallForPrice)
{
priceModel.OldPrice = null;
priceModel.Price = localizationService.GetResource("Products.CallForPrice");
}
else if (minPossiblePrice.HasValue)
{
//calculate prices
decimal taxRate;
decimal finalPriceBase = taxService.GetProductPrice(minPriceProduct, minPossiblePrice.Value, out taxRate);
decimal finalPrice = currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, workContext.WorkingCurrency);
priceModel.OldPrice = null;
priceModel.Price = String.Format(localizationService.GetResource("Products.PriceRangeFrom"), priceFormatter.FormatPrice(finalPrice));
}
else
{
//Actually it's not possible (we presume that minimalPrice always has a value)
//We never should get here
Debug.WriteLine("Cannot calculate minPrice for product #{0}", product.Id);
}
}
}
else
{
//hide prices
priceModel.OldPrice = null;
priceModel.Price = null;
}
}
break;
}
#endregion
}
break;
case ProductType.SimpleProduct:
default:
{
#region Simple product
//add to cart button
priceModel.DisableBuyButton = product.DisableBuyButton ||
!permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart) ||
!permissionService.Authorize(StandardPermissionProvider.DisplayPrices);
示例2: GetBasePriceInfo
/// <summary>
/// gets the base price
/// </summary>
/// <param name="product">Product</param>
/// <param name="localizationService">Localization service</param>
/// <param name="priceFormatter">Price formatter</param>
/// <param name="priceAdjustment">Price adjustment</param>
/// <returns>The base price</returns>
public static string GetBasePriceInfo(this Product product, ILocalizationService localizationService, IPriceFormatter priceFormatter,
decimal priceAdjustment = decimal.Zero)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null)
throw new ArgumentNullException("localizationService");
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
{
decimal price = decimal.Add(product.Price, priceAdjustment);
decimal basePriceValue = Convert.ToDecimal((price / product.BasePriceAmount) * product.BasePriceBaseAmount);
string basePrice = priceFormatter.FormatPrice(basePriceValue, false, false);
string unit = "{0} {1}".FormatWith(product.BasePriceBaseAmount, product.BasePriceMeasureUnit);
return localizationService.GetResource("Products.BasePriceInfo").FormatWith(basePrice, unit);
}
return "";
}
示例3: LoadPriceRangeFilters
public virtual void LoadPriceRangeFilters(string priceRangeStr, IWebHelper webHelper, IPriceFormatter priceFormatter)
{
var priceRangeList = GetPriceRangeList(priceRangeStr);
if (priceRangeList.Count > 0)
{
this.Enabled = true;
var selectedPriceRange = GetSelectedPriceRange(webHelper, priceRangeStr);
this.Items = priceRangeList.ToList().Select(x =>
{
//from&to
var item = new PriceRangeFilterItem();
if (x.From.HasValue)
item.From = priceFormatter.FormatPrice(x.From.Value, true, false);
if (x.To.HasValue)
item.To = priceFormatter.FormatPrice(x.To.Value, true, false);
string fromQuery = string.Empty;
if (x.From.HasValue)
fromQuery = x.From.Value.ToString(new CultureInfo("en-US"));
string toQuery = string.Empty;
if (x.To.HasValue)
toQuery = x.To.Value.ToString(new CultureInfo("en-US"));
//is selected?
if (selectedPriceRange != null
&& selectedPriceRange.From == x.From
&& selectedPriceRange.To == x.To)
item.Selected = true;
//filter URL
string url = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + fromQuery + "-" + toQuery, null);
url = ExcludeQueryStringParams(url, webHelper);
item.FilterUrl = url;
return item;
}).ToList();
if (selectedPriceRange != null)
{
//remove filter URL
string url = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
url = ExcludeQueryStringParams(url, webHelper);
this.RemoveFilterUrl = url;
}
}
else
{
this.Enabled = false;
}
}
示例4: 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;
}
示例5: GetBasePriceInfo
/// <summary>
/// Gets the base price
/// </summary>
/// <param name="product">Product</param>
/// <param name="localizationService">Localization service</param>
/// <param name="priceFormatter">Price formatter</param>
/// <param name="priceAdjustment">Price adjustment</param>
/// <param name="languageIndependent">Whether the result string should be language independent</param>
/// <returns>The base price</returns>
public static string GetBasePriceInfo(this Product product, ILocalizationService localizationService, IPriceFormatter priceFormatter,
ICurrencyService currencyService, ITaxService taxService, IPriceCalculationService priceCalculationService,
Currency currency, decimal priceAdjustment = decimal.Zero, bool languageIndependent = false)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null && !languageIndependent)
throw new ArgumentNullException("localizationService");
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var taxrate = decimal.Zero;
var currentPrice = priceCalculationService.GetFinalPrice(product, workContext.CurrentCustomer, true);
decimal price = taxService.GetProductPrice(product, decimal.Add(currentPrice, priceAdjustment), out taxrate);
price = currencyService.ConvertFromPrimaryStoreCurrency(price, currency);
decimal basePriceValue = Convert.ToDecimal((price / product.BasePriceAmount) * product.BasePriceBaseAmount);
string basePrice = priceFormatter.FormatPrice(basePriceValue, true, currency);
string unit = "{0} {1}".FormatWith(product.BasePriceBaseAmount, product.BasePriceMeasureUnit);
if (languageIndependent)
{
return "{0} / {1}".FormatWith(basePrice, unit);
}
return localizationService.GetResource("Products.BasePriceInfo").FormatWith(basePrice, unit);
}
return "";
}
示例6: GetBasePriceInfo
/// <summary>
/// Gets the base price info
/// </summary>
/// <param name="product">Product</param>
/// <param name="productPrice">The calculated product price</param>
/// <param name="localizationService">Localization service</param>
/// <param name="priceFormatter">Price formatter</param>
/// <param name="currency">Target currency</param>
/// <param name="languageInsensitive">Whether the result string should be language insensitive</param>
/// <returns>The base price info</returns>
public static string GetBasePriceInfo(this Product product,
decimal productPrice,
ILocalizationService localizationService,
IPriceFormatter priceFormatter,
Currency currency,
bool languageInsensitive = false)
{
Guard.ArgumentNotNull(() => product);
Guard.ArgumentNotNull(() => localizationService);
Guard.ArgumentNotNull(() => priceFormatter);
Guard.ArgumentNotNull(() => currency);
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
{
var value = Convert.ToDecimal((productPrice / product.BasePriceAmount) * product.BasePriceBaseAmount);
var valueFormatted = priceFormatter.FormatPrice(value, true, currency);
var amountFormatted = Math.Round(product.BasePriceAmount.Value, 2).ToString("G29");
var infoTemplate = localizationService.GetResource(languageInsensitive ? "Products.BasePriceInfo.LanguageInsensitive" : "Products.BasePriceInfo");
var result = infoTemplate.FormatInvariant(
amountFormatted,
product.BasePriceMeasureUnit,
valueFormatted,
product.BasePriceBaseAmount
);
return result;
}
return "";
}