public ActionResult Catalog(CatalogSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            _catalogSettings = model.ToEntity(_catalogSettings);
            _settingService.SaveSetting(_catalogSettings);

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

            SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
            return RedirectToAction("Catalog");
        }
        public ActionResult Catalog(CatalogSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

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

            /* 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.ShowProductSku_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowProductSku, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowProductSku, storeScope);

            if (model.ShowManufacturerPartNumber_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowManufacturerPartNumber, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowManufacturerPartNumber, storeScope);

            if (model.ShowGtin_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowGtin, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowGtin, storeScope);

            if (model.ShowFreeShippingNotification_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowFreeShippingNotification, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowFreeShippingNotification, storeScope);

            if (model.AllowProductSorting_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.AllowProductSorting, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.AllowProductSorting, storeScope);

            if (model.AllowProductViewModeChanging_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.AllowProductViewModeChanging, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.AllowProductViewModeChanging, storeScope);

            if (model.ShowProductsFromSubcategories_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowProductsFromSubcategories, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowProductsFromSubcategories, storeScope);

            if (model.ShowCategoryProductNumber_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowCategoryProductNumber, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowCategoryProductNumber, storeScope);

            if (model.ShowCategoryProductNumberIncludingSubcategories_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowCategoryProductNumberIncludingSubcategories, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowCategoryProductNumberIncludingSubcategories, storeScope);

            if (model.CategoryBreadcrumbEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.CategoryBreadcrumbEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.CategoryBreadcrumbEnabled, storeScope);

            if (model.ShowShareButton_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowShareButton, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowShareButton, storeScope);

            if (model.PageShareCode_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.PageShareCode, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.PageShareCode, storeScope);

            if (model.ProductReviewsMustBeApproved_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductReviewsMustBeApproved, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductReviewsMustBeApproved, storeScope);

            if (model.AllowAnonymousUsersToReviewProduct_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.AllowAnonymousUsersToReviewProduct, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.AllowAnonymousUsersToReviewProduct, storeScope);

            if (model.NotifyStoreOwnerAboutNewProductReviews_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.NotifyStoreOwnerAboutNewProductReviews, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.NotifyStoreOwnerAboutNewProductReviews, storeScope);

            if (model.EmailAFriendEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.EmailAFriendEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.EmailAFriendEnabled, storeScope);

            if (model.AllowAnonymousUsersToEmailAFriend_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.AllowAnonymousUsersToEmailAFriend, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.AllowAnonymousUsersToEmailAFriend, storeScope);

            if (model.RecentlyViewedProductsNumber_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.RecentlyViewedProductsNumber, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.RecentlyViewedProductsNumber, storeScope);

            if (model.RecentlyViewedProductsEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.RecentlyViewedProductsEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.RecentlyViewedProductsEnabled, storeScope);

            if (model.RecentlyAddedProductsNumber_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.RecentlyAddedProductsNumber, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.RecentlyAddedProductsNumber, storeScope);

            if (model.RecentlyAddedProductsEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.RecentlyAddedProductsEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.RecentlyAddedProductsEnabled, storeScope);

            if (model.CompareProductsEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.CompareProductsEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.CompareProductsEnabled, storeScope);

            if (model.ShowBestsellersOnHomepage_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowBestsellersOnHomepage, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowBestsellersOnHomepage, storeScope);

            if (model.NumberOfBestsellersOnHomepage_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.NumberOfBestsellersOnHomepage, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.NumberOfBestsellersOnHomepage, storeScope);

            if (model.SearchPageProductsPerPage_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.SearchPageProductsPerPage, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.SearchPageProductsPerPage, storeScope);

            if (model.SearchPageAllowCustomersToSelectPageSize_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.SearchPageAllowCustomersToSelectPageSize, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.SearchPageAllowCustomersToSelectPageSize, storeScope);

            if (model.SearchPagePageSizeOptions_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.SearchPagePageSizeOptions, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.SearchPagePageSizeOptions, storeScope);

            if (model.ProductSearchAutoCompleteEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductSearchAutoCompleteEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductSearchAutoCompleteEnabled, storeScope);

            if (model.ProductSearchAutoCompleteNumberOfProducts_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductSearchAutoCompleteNumberOfProducts, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductSearchAutoCompleteNumberOfProducts, storeScope);

            if (model.ShowProductImagesInSearchAutoComplete_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ShowProductImagesInSearchAutoComplete, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ShowProductImagesInSearchAutoComplete, storeScope);

            if (model.ProductSearchTermMinimumLength_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductSearchTermMinimumLength, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductSearchTermMinimumLength, storeScope);

            if (model.ProductsAlsoPurchasedEnabled_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductsAlsoPurchasedEnabled, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductsAlsoPurchasedEnabled, storeScope);

            if (model.ProductsAlsoPurchasedNumber_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductsAlsoPurchasedNumber, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductsAlsoPurchasedNumber, storeScope);

            if (model.EnableDynamicPriceUpdate_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.EnableDynamicPriceUpdate, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.EnableDynamicPriceUpdate, storeScope);

            if (model.DynamicPriceUpdateAjax_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.DynamicPriceUpdateAjax, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.DynamicPriceUpdateAjax, storeScope);

            if (model.NumberOfProductTags_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.NumberOfProductTags, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.NumberOfProductTags, storeScope);

            if (model.ProductsByTagPageSize_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductsByTagPageSize, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductsByTagPageSize, storeScope);

            if (model.ProductsByTagAllowCustomersToSelectPageSize_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductsByTagAllowCustomersToSelectPageSize, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductsByTagAllowCustomersToSelectPageSize, storeScope);

            if (model.ProductsByTagPageSizeOptions_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ProductsByTagPageSizeOptions, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ProductsByTagPageSizeOptions, storeScope);

            if (model.IncludeShortDescriptionInCompareProducts_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.IncludeShortDescriptionInCompareProducts, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.IncludeShortDescriptionInCompareProducts, storeScope);

            if (model.IncludeFullDescriptionInCompareProducts_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.IncludeFullDescriptionInCompareProducts, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.IncludeFullDescriptionInCompareProducts, storeScope);

            if (model.IgnoreDiscounts_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.IgnoreDiscounts, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.IgnoreDiscounts, storeScope);

            if (model.IgnoreFeaturedProducts_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.IgnoreFeaturedProducts, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.IgnoreFeaturedProducts, storeScope);

            if (model.IgnoreAcl_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.IgnoreAcl, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.IgnoreAcl, storeScope);

            if (model.IgnoreStoreLimitations_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.IgnoreStoreLimitations, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.IgnoreStoreLimitations, storeScope);

            if (model.CacheProductPrices_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.CacheProductPrices, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.CacheProductPrices, storeScope);

            if (model.ManufacturersBlockItemsToDisplay_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.ManufacturersBlockItemsToDisplay, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.ManufacturersBlockItemsToDisplay, storeScope);

            if (model.DisplayTaxShippingInfoFooter_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.DisplayTaxShippingInfoFooter, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.DisplayTaxShippingInfoFooter, storeScope);

            if (model.DisplayTaxShippingInfoProductDetailsPage_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.DisplayTaxShippingInfoProductDetailsPage, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.DisplayTaxShippingInfoProductDetailsPage, storeScope);

            if (model.DisplayTaxShippingInfoProductBoxes_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.DisplayTaxShippingInfoProductBoxes, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.DisplayTaxShippingInfoProductBoxes, storeScope);

            if (model.DisplayTaxShippingInfoWishlist_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.DisplayTaxShippingInfoWishlist, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.DisplayTaxShippingInfoWishlist, storeScope);

            if (model.DisplayTaxShippingInfoOrderDetailsPage_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(catalogSettings, x => x.DisplayTaxShippingInfoOrderDetailsPage, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(catalogSettings, x => x.DisplayTaxShippingInfoOrderDetailsPage, storeScope);

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

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

            SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));

            //selected tab
            SaveSelectedTabIndex();

            return RedirectToAction("Catalog");
        }