Inheritance: Nop.Web.Framework.Mvc.BaseNopModel
コード例 #1
0
        public ActionResult Order(OrderSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
                _orderSettings = model.ToEntity(_orderSettings);

                //parse return request actions
                _orderSettings.ReturnRequestActions.Clear();
                foreach (var returnAction in model.ReturnRequestActionsParsed.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    _orderSettings.ReturnRequestActions.Add(returnAction);
                //parse return request reasons
                _orderSettings.ReturnRequestReasons.Clear();
                foreach (var returnReason in model.ReturnRequestReasonsParsed.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    _orderSettings.ReturnRequestReasons.Add(returnReason);

                _settingService.SaveSetting(_orderSettings);

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

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
            }
            else
            {
                foreach (var modelState in ModelState.Values)
                    foreach (var error in modelState.Errors)
                        ErrorNotification(error.ErrorMessage);
            }
            return RedirectToAction("Order");
        }
コード例 #2
0
        public ActionResult Order(OrderSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                //load settings for a chosen store scope
                var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
                var orderSettings = _settingService.LoadSetting<OrderSettings>(storeScope);
                orderSettings = model.ToEntity(orderSettings);

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

                if (model.MinOrderSubtotalAmount_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.MinOrderSubtotalAmount, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.MinOrderSubtotalAmount, storeScope);

                if (model.MinOrderTotalAmount_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.MinOrderTotalAmount, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.MinOrderTotalAmount, storeScope);

                if (model.AnonymousCheckoutAllowed_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.AnonymousCheckoutAllowed, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.AnonymousCheckoutAllowed, storeScope);

                if (model.TermsOfServiceOnShoppingCartPage_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.TermsOfServiceOnShoppingCartPage, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.TermsOfServiceOnShoppingCartPage, storeScope);

                if (model.TermsOfServiceOnOrderConfirmPage_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.TermsOfServiceOnOrderConfirmPage, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.TermsOfServiceOnOrderConfirmPage, storeScope);

                if (model.OnePageCheckoutEnabled_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.OnePageCheckoutEnabled, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.OnePageCheckoutEnabled, storeScope);

                if (model.OnePageCheckoutDisplayOrderTotalsOnPaymentInfoTab_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.OnePageCheckoutDisplayOrderTotalsOnPaymentInfoTab, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.OnePageCheckoutDisplayOrderTotalsOnPaymentInfoTab, storeScope);

                if (model.DisableBillingAddressCheckoutStep_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.DisableBillingAddressCheckoutStep, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.DisableBillingAddressCheckoutStep, storeScope);

                if (model.DisableOrderCompletedPage_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.DisableOrderCompletedPage, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.DisableOrderCompletedPage, storeScope);

                if (model.AttachPdfInvoiceToOrderPlacedEmail_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.AttachPdfInvoiceToOrderPlacedEmail, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.AttachPdfInvoiceToOrderPlacedEmail, storeScope);

                if (model.AttachPdfInvoiceToOrderPaidEmail_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.AttachPdfInvoiceToOrderPaidEmail, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.AttachPdfInvoiceToOrderPaidEmail, storeScope);

                if (model.AttachPdfInvoiceToOrderCompletedEmail_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.AttachPdfInvoiceToOrderCompletedEmail, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.AttachPdfInvoiceToOrderCompletedEmail, storeScope);

                if (model.ReturnRequestsEnabled_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.ReturnRequestsEnabled, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.ReturnRequestsEnabled, storeScope);

                if (model.NumberOfDaysReturnRequestAvailable_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.NumberOfDaysReturnRequestAvailable, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.NumberOfDaysReturnRequestAvailable, storeScope);

                _settingService.SaveSetting(orderSettings, x => x.GiftCards_Activated_OrderStatusId, 0, false);
                _settingService.SaveSetting(orderSettings, x => x.GiftCards_Deactivated_OrderStatusId, 0, false);

                if (model.ReturnRequestsEnabled_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(orderSettings, x => x.ReturnRequestsEnabled, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(orderSettings, x => x.ReturnRequestsEnabled, storeScope);

                //parse return request actions
                orderSettings.ReturnRequestActions.Clear();
                if (model.ReturnRequestActionsParsed != null)
                {
                    foreach (var returnAction in model.ReturnRequestActionsParsed.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        orderSettings.ReturnRequestActions.Add(returnAction);
                }
                //note that we do not store this setting for a store (cannot be overridden)
                //pass 0 as "storeScope" parameter
                _settingService.SaveSetting(orderSettings, x => x.ReturnRequestActions, 0, false);
                //parse return request reasons
                orderSettings.ReturnRequestReasons.Clear();
                if (model.ReturnRequestReasonsParsed != null)
                {
                    foreach (var returnReason in model.ReturnRequestReasonsParsed.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        orderSettings.ReturnRequestReasons.Add(returnReason);
                }
                //note that we do not store this setting for a store (cannot be overridden)
                //pass 0 as "storeScope" parameter
                _settingService.SaveSetting(orderSettings, x => x.ReturnRequestReasons, 0, false);

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

                //order ident
                if (model.OrderIdent.HasValue)
                {
                    try
                    {
                        _maintenanceService.SetTableIdent<Order>(model.OrderIdent.Value);
                    }
                    catch (Exception exc)
                    {
                        ErrorNotification(exc.Message);
                    }
                }

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

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
            }
            else
            {
                //If we got this far, something failed, redisplay form
                foreach (var modelState in ModelState.Values)
                    foreach (var error in modelState.Errors)
                        ErrorNotification(error.ErrorMessage);
            }

            //selected tab
            SaveSelectedTabIndex();

            return RedirectToAction("Order");
        }