public WB_ModelCacheEventConsumer(IWB_CountryStateZipService taxRateService, IWB_TaxCategoryMappingService taxCategoryMappingService, ISettingService settingService) { //TODO inject static cache manager using constructor this._cacheManager = EngineContext.Current.ContainerManager.Resolve <ICacheManager>("nop_cache_static"); this._taxRateService = taxRateService; this._taxCategoryMappingService = taxCategoryMappingService; this._settingService = settingService; }
public WB_FixedOrByCountryStateZipTaxProvider(IWB_CountryStateZipService taxRateService, IStoreContext storeContext, WB_CountryStateZipObjectContext objectContext, ICacheManager cacheManager, ISettingService settingService, WB_FixedOrByCountryStateZipTaxSettings countryStateZipSettings, ICategoryService categoryService, IWB_TaxCategoryMappingService taxCategoryMappingService ) { this._taxRateService = taxRateService; this._storeContext = storeContext; this._objectContext = objectContext; this._cacheManager = cacheManager; this._settingService = settingService; this._countryStateZipSettings = countryStateZipSettings; this._categoryService = categoryService; this._taxCategoryMappingService = taxCategoryMappingService; }
public WB_FixedOrByCountryStateZipController(ITaxCategoryService taxCategoryService, ICountryService countryService, IStateProvinceService stateProvinceService, ICategoryService categoryService, IWB_CountryStateZipService taxRateService, IWB_TaxCategoryMappingService taxCategoryMappingService, IPermissionService permissionService, IStoreService storeService, ISettingService settingService, WB_FixedOrByCountryStateZipTaxSettings countryStateZipSettings) { this._taxCategoryService = taxCategoryService; this._countryService = countryService; this._stateProvinceService = stateProvinceService; this._categoryService = categoryService; this._taxRateService = taxRateService; this._taxCategoryMappingService = taxCategoryMappingService; this._permissionService = permissionService; this._storeService = storeService; this._settingService = settingService; this._countryStateZipSettings = countryStateZipSettings; }
/// <summary> /// Gets price /// </summary> /// <param name="product">Product</param> /// <param name="taxCategoryId">Tax category identifier</param> /// <param name="price">Price</param> /// <param name="includingTax">A value indicating whether calculated price should include tax</param> /// <param name="customer">Customer</param> /// <param name="priceIncludesTax">A value indicating whether price already includes tax</param> /// <param name="taxRate">Tax rate</param> /// <returns>Price</returns> public virtual decimal GetProductPrice(Product product, int taxCategoryId, decimal price, bool includingTax, Customer customer, bool priceIncludesTax, out decimal taxRate) { //no need to calculate tax rate if passed "price" is 0 if (price == decimal.Zero) { taxRate = decimal.Zero; return(taxRate); } bool isTaxable; IWB_TaxCategoryMappingService _taxCategoryMappingService = EngineContext.Current.Resolve <IWB_TaxCategoryMappingService>(); var _categoryService = EngineContext.Current.Resolve <ICategoryService>(); var cateId = product.ProductCategories.FirstOrDefault(); if (cateId != null) { var category = _categoryService.GetCategoryById(cateId.CategoryId); while (category != null) { var taxcategoryMapping = _taxCategoryMappingService.GetAllTaxCategoryMappings().FirstOrDefault(x => x.CategoryId == category.Id); if (taxcategoryMapping != null) { taxCategoryId = taxcategoryMapping.TaxCategoryId; break; } else { category = _categoryService.GetCategoryById(category.ParentCategoryId); } } } GetTaxRate(product, taxCategoryId, customer, price, out taxRate, out isTaxable, out taxCategoryId); var _settingService = EngineContext.Current.Resolve <ISettingService>(); bool isAbsolute = _settingService.GetSettingByKey <bool>(string.Format("Tax.Worldbuy.TaxProvider.FixedOrByCountryStateZip.TaxCategoryId{0}.IsAbsolute", taxCategoryId)); if (priceIncludesTax) { //"price" already includes tax if (includingTax) { //we should calculate price WITH tax if (!isTaxable) { //but our request is not taxable //hence we should calculate price WITHOUT tax price = CalculatePrice(price, taxRate, false, isAbsolute); } } else { //we should calculate price WITHOUT tax price = CalculatePrice(price, taxRate, false, isAbsolute); } } else { //"price" doesn't include tax if (includingTax) { //we should calculate price WITH tax //do it only when price is taxable if (isTaxable) { price = CalculatePrice(price, taxRate, true, isAbsolute); } } } if (!isTaxable) { //we return 0% tax rate in case a request is not taxable taxRate = decimal.Zero; } //allowed to support negative price adjustments //if (price < decimal.Zero) // price = decimal.Zero; return(price); }