我正在Kentico 11 CMS中开发一个商业站点,除了产品价格之外,还需要根据用户的输入来计算其保险费用。
Kentico允许在商店配置应用程序->商店设置->常规选项卡中配置价格四舍五入选项,我也想将其用于自定义计算,以便我的定制功能根据根据全局存储设置的小数位数。
根据Kentico documentation,您可以通过创建根据您的特定要求使用IRoundingService
方法实现Round()
接口的Service类和使用IRoundingServiceFactory
方法实现GetRoundingService()
接口的SeviceFactory类来自定义全局舍入。 。理想情况下,我想避免这种情况,因为我对Kentico中的标准financial舍入选项感到满意,并且只想将其应用于我的自定义功能以保持一致性。
您可以按如下方式检索上下文站点的舍入服务:
using CMS.Core;
using CMS.Ecommerce;
using CMS.SiteProvider;
IRoundingService roundingService = Service.Resolve<IRoundingServiceFactory().GetRoundingService(SiteContext.CurrentSiteID);
然后将舍入方法作为roundingService.Round(insurance, currency)
传递给它一个十进制值和当前货币。
您可以得到的当前货币如下:
CurrencyInfo currencyInfo = ECommerceContext.CurrentCurrency;