|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
4 | 4 | using System.Web.Mvc; |
| 5 | +using SmartStore.Core; |
5 | 6 | using SmartStore.Plugin.Payments.Manual.Models; |
6 | 7 | using SmartStore.Plugin.Payments.Manual.Validators; |
7 | 8 | using SmartStore.Services.Configuration; |
8 | 9 | using SmartStore.Services.Localization; |
9 | 10 | using SmartStore.Services.Payments; |
| 11 | +using SmartStore.Services.Stores; |
10 | 12 | using SmartStore.Web.Framework; |
11 | 13 | using SmartStore.Web.Framework.Controllers; |
| 14 | +using SmartStore.Web.Framework.Settings; |
12 | 15 |
|
13 | 16 | namespace SmartStore.Plugin.Payments.Manual.Controllers |
14 | 17 | { |
15 | 18 | public class PaymentManualController : PaymentControllerBase |
16 | 19 | { |
| 20 | + private readonly IWorkContext _workContext; |
| 21 | + private readonly IStoreService _storeService; |
17 | 22 | private readonly ISettingService _settingService; |
18 | 23 | private readonly ILocalizationService _localizationService; |
19 | | - private readonly ManualPaymentSettings _manualPaymentSettings; |
20 | 24 |
|
21 | | - public PaymentManualController(ISettingService settingService, |
22 | | - ILocalizationService localizationService, ManualPaymentSettings manualPaymentSettings) |
| 25 | + public PaymentManualController(IWorkContext workContext, |
| 26 | + IStoreService storeService, |
| 27 | + ISettingService settingService, |
| 28 | + ILocalizationService localizationService) |
23 | 29 | { |
| 30 | + this._workContext = workContext; |
| 31 | + this._storeService = storeService; |
24 | 32 | this._settingService = settingService; |
25 | 33 | this._localizationService = localizationService; |
26 | | - this._manualPaymentSettings = manualPaymentSettings; |
27 | 34 | } |
28 | 35 |
|
29 | 36 | [AdminAuthorize] |
30 | 37 | [ChildActionOnly] |
31 | 38 | public ActionResult Configure() |
32 | 39 | { |
| 40 | + //load settings for a chosen store scope |
| 41 | + var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); |
| 42 | + var manualPaymentSettings = _settingService.LoadSetting<ManualPaymentSettings>(storeScope); |
| 43 | + |
33 | 44 | var model = new ConfigurationModel(); |
34 | | - model.TransactModeId = Convert.ToInt32(_manualPaymentSettings.TransactMode); |
35 | | - model.AdditionalFee = _manualPaymentSettings.AdditionalFee; |
36 | | - model.TransactModeValues = _manualPaymentSettings.TransactMode.ToSelectList(); |
37 | | - |
| 45 | + model.TransactMode = Convert.ToInt32(manualPaymentSettings.TransactMode); |
| 46 | + model.AdditionalFee = manualPaymentSettings.AdditionalFee; |
| 47 | + model.AdditionalFeePercentage = manualPaymentSettings.AdditionalFeePercentage; |
| 48 | + model.TransactModeValues = manualPaymentSettings.TransactMode.ToSelectList(); |
| 49 | + |
| 50 | + var storeDependingSettings = new StoreDependingSettingHelper(ViewData); |
| 51 | + storeDependingSettings.GetOverrideKeys(manualPaymentSettings, model, storeScope, _settingService); |
| 52 | + |
38 | 53 | return View("SmartStore.Plugin.Payments.Manual.Views.PaymentManual.Configure", model); |
39 | 54 | } |
40 | 55 |
|
41 | 56 | [HttpPost] |
42 | 57 | [AdminAuthorize] |
43 | 58 | [ChildActionOnly] |
44 | | - public ActionResult Configure(ConfigurationModel model) |
| 59 | + public ActionResult Configure(ConfigurationModel model, FormCollection form) |
45 | 60 | { |
46 | 61 | if (!ModelState.IsValid) |
47 | 62 | return Configure(); |
| 63 | + |
| 64 | + //load settings for a chosen store scope |
| 65 | + var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); |
| 66 | + var manualPaymentSettings = _settingService.LoadSetting<ManualPaymentSettings>(storeScope); |
48 | 67 |
|
49 | 68 | //save settings |
50 | | - _manualPaymentSettings.TransactMode = (TransactMode)model.TransactModeId; |
51 | | - _manualPaymentSettings.AdditionalFee = model.AdditionalFee; |
52 | | - _settingService.SaveSetting(_manualPaymentSettings); |
53 | | - |
54 | | - model.TransactModeValues = _manualPaymentSettings.TransactMode.ToSelectList(); |
| 69 | + manualPaymentSettings.TransactMode = (TransactMode)model.TransactMode; |
| 70 | + manualPaymentSettings.AdditionalFee = model.AdditionalFee; |
| 71 | + manualPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; |
| 72 | + model.TransactModeValues = manualPaymentSettings.TransactMode.ToSelectList(); |
| 73 | + |
| 74 | + var storeDependingSettings = new StoreDependingSettingHelper(ViewData); |
| 75 | + storeDependingSettings.UpdateSettings(manualPaymentSettings, form, storeScope, _settingService); |
| 76 | + |
| 77 | + //now clear settings cache |
| 78 | + _settingService.ClearCache(); |
55 | 79 |
|
56 | 80 | return View("SmartStore.Plugin.Payments.Manual.Views.PaymentManual.Configure", model); |
57 | 81 | } |
|
0 commit comments