Inheritance: Nop.Web.Framework.Mvc.BaseNopModel
Ejemplo n.º 1
0
        public ActionResult Tax(TaxSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            _taxSettings = model.ToEntity(_taxSettings);

            var defaultAddress = _addressService.GetAddressById(_taxSettings.DefaultTaxAddressId) ??
                                         new Core.Domain.Common.Address()
                                         {
                                             CreatedOnUtc = DateTime.UtcNow,
                                         };
            defaultAddress = model.DefaultTaxAddress.ToEntity(defaultAddress);
            if (defaultAddress.Id > 0)
                _addressService.UpdateAddress(defaultAddress);
            else
                _addressService.InsertAddress(defaultAddress);

            _taxSettings.DefaultTaxAddressId = defaultAddress.Id;
            _settingService.SaveSetting(_taxSettings);

            //activity log
            _customerActivityService.InsertActivity("EditSettings", _localizationService.GetResource("ActivityLog.EditSettings"));

            SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
            return RedirectToAction("Tax");
        }
Ejemplo n.º 2
0
        public ActionResult Tax(TaxSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            //load settings for a chosen store scope
            var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
            var taxSettings = _settingService.LoadSetting<TaxSettings>(storeScope);
            taxSettings = model.ToEntity(taxSettings);

            /* We do not clear cache after each setting update.
             * This behavior can increase performance because cached settings will not be cleared
             * and loaded from database after each update */
            if (model.PricesIncludeTax_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.PricesIncludeTax, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.PricesIncludeTax, storeScope);

            if (model.AllowCustomersToSelectTaxDisplayType_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.AllowCustomersToSelectTaxDisplayType, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.AllowCustomersToSelectTaxDisplayType, storeScope);

            if (model.TaxDisplayType_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.TaxDisplayType, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.TaxDisplayType, storeScope);

            if (model.DisplayTaxSuffix_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.DisplayTaxSuffix, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.DisplayTaxSuffix, storeScope);

            if (model.DisplayTaxRates_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.DisplayTaxRates, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.DisplayTaxRates, storeScope);

            if (model.HideZeroTax_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.HideZeroTax, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.HideZeroTax, storeScope);

            if (model.HideTaxInOrderSummary_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.HideTaxInOrderSummary, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.HideTaxInOrderSummary, storeScope);

            if (model.ForceTaxExclusionFromOrderSubtotal_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.ForceTaxExclusionFromOrderSubtotal, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.ForceTaxExclusionFromOrderSubtotal, storeScope);

            if (model.TaxBasedOn_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.TaxBasedOn, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.TaxBasedOn, storeScope);

            if (model.DefaultTaxAddress_OverrideForStore || storeScope == 0)
            {
                //update address
                var addressId = _settingService.SettingExists(taxSettings, x => x.DefaultTaxAddressId, storeScope) ?
                    taxSettings.DefaultTaxAddressId : 0;
                var originAddress = _addressService.GetAddressById(addressId) ??
                    new Address
                    {
                        CreatedOnUtc = DateTime.UtcNow,
                    };
                //update ID manually (in case we're in multi-store configuration mode it'll be set to the shared one)
                model.DefaultTaxAddress.Id = addressId;
                originAddress = model.DefaultTaxAddress.ToEntity(originAddress);
                if (originAddress.Id > 0)
                    _addressService.UpdateAddress(originAddress);
                else
                    _addressService.InsertAddress(originAddress);
                taxSettings.DefaultTaxAddressId = originAddress.Id;

                _settingService.SaveSetting(taxSettings, x => x.DefaultTaxAddressId, storeScope, false);
            }
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.DefaultTaxAddressId, storeScope);

            if (model.ShippingIsTaxable_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.ShippingIsTaxable, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.ShippingIsTaxable, storeScope);

            if (model.ShippingPriceIncludesTax_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.ShippingPriceIncludesTax, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.ShippingPriceIncludesTax, storeScope);

            if (model.ShippingTaxClassId_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.ShippingTaxClassId, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.ShippingTaxClassId, storeScope);

            if (model.PaymentMethodAdditionalFeeIsTaxable_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.PaymentMethodAdditionalFeeIsTaxable, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.PaymentMethodAdditionalFeeIsTaxable, storeScope);

            if (model.PaymentMethodAdditionalFeeIncludesTax_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.PaymentMethodAdditionalFeeIncludesTax, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.PaymentMethodAdditionalFeeIncludesTax, storeScope);

            if (model.PaymentMethodAdditionalFeeTaxClassId_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.PaymentMethodAdditionalFeeTaxClassId, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.PaymentMethodAdditionalFeeTaxClassId, storeScope);

            if (model.EuVatEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.EuVatEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.EuVatEnabled, storeScope);

            if (model.EuVatShopCountryId_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.EuVatShopCountryId, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.EuVatShopCountryId, storeScope);

            if (model.EuVatAllowVatExemption_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.EuVatAllowVatExemption, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.EuVatAllowVatExemption, storeScope);

            if (model.EuVatUseWebService_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.EuVatUseWebService, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.EuVatUseWebService, storeScope);

            if (model.EuVatAssumeValid_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.EuVatAssumeValid, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.EuVatAssumeValid, storeScope);

            if (model.EuVatEmailAdminWhenNewVatSubmitted_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(taxSettings, x => x.EuVatEmailAdminWhenNewVatSubmitted, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(taxSettings, x => x.EuVatEmailAdminWhenNewVatSubmitted, storeScope);

            //now clear settings cache
            _settingService.ClearCache();

            //activity log
            _customerActivityService.InsertActivity("EditSettings", _localizationService.GetResource("ActivityLog.EditSettings"));

            SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
            return RedirectToAction("Tax");
        }