|
1 | 1 | using System.Collections.Generic; |
2 | 2 | using System.Web.Mvc; |
| 3 | +using SmartStore.Core; |
3 | 4 | using SmartStore.Plugin.Payments.PayInStore.Models; |
4 | 5 | using SmartStore.Services.Configuration; |
5 | 6 | using SmartStore.Services.Localization; |
6 | 7 | using SmartStore.Services.Payments; |
| 8 | +using SmartStore.Services.Stores; |
7 | 9 | using SmartStore.Web.Framework.Controllers; |
| 10 | +using SmartStore.Web.Framework.Settings; |
8 | 11 |
|
9 | 12 | namespace SmartStore.Plugin.Payments.PayInStore.Controllers |
10 | 13 | { |
11 | 14 | public class PaymentPayInStoreController : PaymentControllerBase |
12 | 15 | { |
| 16 | + private readonly IWorkContext _workContext; |
| 17 | + private readonly IStoreService _storeService; |
| 18 | + private readonly IStoreContext _storeContext; |
13 | 19 | private readonly ISettingService _settingService; |
14 | | - private readonly PayInStorePaymentSettings _payInStorePaymentSettings; |
15 | 20 | private readonly ILocalizationService _localizationService; |
16 | 21 |
|
17 | | - public PaymentPayInStoreController(ISettingService settingService, |
18 | | - PayInStorePaymentSettings payInStorePaymentSettings, |
| 22 | + public PaymentPayInStoreController(IWorkContext workContext, |
| 23 | + IStoreService storeService, |
| 24 | + IStoreContext storeContext, |
| 25 | + ISettingService settingService, |
19 | 26 | ILocalizationService localizationService) |
20 | 27 | { |
| 28 | + this._workContext = workContext; |
| 29 | + this._storeService = storeService; |
| 30 | + this._storeContext = storeContext; |
21 | 31 | this._settingService = settingService; |
22 | | - this._payInStorePaymentSettings = payInStorePaymentSettings; |
23 | | - _localizationService = localizationService; |
| 32 | + this._localizationService = localizationService; |
24 | 33 | } |
25 | 34 |
|
26 | 35 | [AdminAuthorize] |
27 | 36 | [ChildActionOnly] |
28 | 37 | public ActionResult Configure() |
29 | 38 | { |
| 39 | + //load settings for a chosen store scope |
| 40 | + var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); |
| 41 | + var payInStorePaymentSettings = _settingService.LoadSetting<PayInStorePaymentSettings>(storeScope); |
| 42 | + |
30 | 43 | var model = new ConfigurationModel(); |
31 | | - model.DescriptionText = _payInStorePaymentSettings.DescriptionText; |
32 | | - model.AdditionalFee = _payInStorePaymentSettings.AdditionalFee; |
| 44 | + model.DescriptionText = payInStorePaymentSettings.DescriptionText; |
| 45 | + model.AdditionalFee = payInStorePaymentSettings.AdditionalFee; |
| 46 | + model.AdditionalFeePercentage = payInStorePaymentSettings.AdditionalFeePercentage; |
| 47 | + |
| 48 | + var storeDependingSettings = new StoreDependingSettingHelper(ViewData); |
| 49 | + storeDependingSettings.GetOverrideKeys(payInStorePaymentSettings, model, storeScope, _settingService); |
33 | 50 |
|
34 | 51 | return View("SmartStore.Plugin.Payments.PayInStore.Views.PaymentPayInStore.Configure", model); |
35 | 52 | } |
36 | 53 |
|
37 | 54 | [HttpPost] |
38 | 55 | [AdminAuthorize] |
39 | 56 | [ChildActionOnly] |
40 | | - public ActionResult Configure(ConfigurationModel model) |
| 57 | + public ActionResult Configure(ConfigurationModel model, FormCollection form) |
41 | 58 | { |
42 | 59 | if (!ModelState.IsValid) |
43 | 60 | return Configure(); |
44 | | - |
| 61 | + |
| 62 | + //load settings for a chosen store scope |
| 63 | + var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); |
| 64 | + var payInStorePaymentSettings = _settingService.LoadSetting<PayInStorePaymentSettings>(storeScope); |
| 65 | + |
45 | 66 | //save settings |
46 | | - _payInStorePaymentSettings.DescriptionText = model.DescriptionText; |
47 | | - _payInStorePaymentSettings.AdditionalFee = model.AdditionalFee; |
48 | | - _settingService.SaveSetting(_payInStorePaymentSettings); |
| 67 | + payInStorePaymentSettings.DescriptionText = model.DescriptionText; |
| 68 | + payInStorePaymentSettings.AdditionalFee = model.AdditionalFee; |
| 69 | + payInStorePaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; |
| 70 | + |
| 71 | + var storeDependingSettings = new StoreDependingSettingHelper(ViewData); |
| 72 | + storeDependingSettings.UpdateSettings(payInStorePaymentSettings, form, storeScope, _settingService); |
| 73 | + |
| 74 | + //now clear settings cache |
| 75 | + _settingService.ClearCache(); |
49 | 76 |
|
50 | 77 | return View("SmartStore.Plugin.Payments.PayInStore.Views.PaymentPayInStore.Configure", model); |
51 | 78 | } |
52 | 79 |
|
53 | 80 | [ChildActionOnly] |
54 | 81 | public ActionResult PaymentInfo() |
55 | 82 | { |
| 83 | + var payInStorePaymentSettings = _settingService.LoadSetting<PayInStorePaymentSettings>(_storeContext.CurrentStore.Id); |
| 84 | + |
56 | 85 | var model = new PaymentInfoModel(); |
57 | 86 |
|
58 | | - string desc = _payInStorePaymentSettings.DescriptionText; |
| 87 | + string desc = payInStorePaymentSettings.DescriptionText; |
59 | 88 |
|
60 | 89 | if (desc.StartsWith("@")) |
61 | 90 | { |
62 | 91 | model.DescriptionText = _localizationService.GetResource(desc.Substring(1)); |
63 | 92 | } |
64 | 93 | else |
65 | 94 | { |
66 | | - model.DescriptionText = _payInStorePaymentSettings.DescriptionText; |
| 95 | + model.DescriptionText = payInStorePaymentSettings.DescriptionText; |
67 | 96 | } |
68 | 97 |
|
69 | 98 | return View("SmartStore.Plugin.Payments.PayInStore.Views.PaymentPayInStore.PaymentInfo", model); |
|
0 commit comments