Skip to content

Commit c95a13b

Browse files
committed
Payment plugin "Manual" configuration per store
1 parent b11e050 commit c95a13b

3 files changed

Lines changed: 47 additions & 20 deletions

File tree

src/Plugins/Payments.Manual/Controllers/PaymentManualController.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,80 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Web.Mvc;
5+
using SmartStore.Core;
56
using SmartStore.Plugin.Payments.Manual.Models;
67
using SmartStore.Plugin.Payments.Manual.Validators;
78
using SmartStore.Services.Configuration;
89
using SmartStore.Services.Localization;
910
using SmartStore.Services.Payments;
11+
using SmartStore.Services.Stores;
1012
using SmartStore.Web.Framework;
1113
using SmartStore.Web.Framework.Controllers;
14+
using SmartStore.Web.Framework.Settings;
1215

1316
namespace SmartStore.Plugin.Payments.Manual.Controllers
1417
{
1518
public class PaymentManualController : PaymentControllerBase
1619
{
20+
private readonly IWorkContext _workContext;
21+
private readonly IStoreService _storeService;
1722
private readonly ISettingService _settingService;
1823
private readonly ILocalizationService _localizationService;
19-
private readonly ManualPaymentSettings _manualPaymentSettings;
2024

21-
public PaymentManualController(ISettingService settingService,
22-
ILocalizationService localizationService, ManualPaymentSettings manualPaymentSettings)
25+
public PaymentManualController(IWorkContext workContext,
26+
IStoreService storeService,
27+
ISettingService settingService,
28+
ILocalizationService localizationService)
2329
{
30+
this._workContext = workContext;
31+
this._storeService = storeService;
2432
this._settingService = settingService;
2533
this._localizationService = localizationService;
26-
this._manualPaymentSettings = manualPaymentSettings;
2734
}
2835

2936
[AdminAuthorize]
3037
[ChildActionOnly]
3138
public ActionResult Configure()
3239
{
40+
//load settings for a chosen store scope
41+
var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
42+
var manualPaymentSettings = _settingService.LoadSetting<ManualPaymentSettings>(storeScope);
43+
3344
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+
3853
return View("SmartStore.Plugin.Payments.Manual.Views.PaymentManual.Configure", model);
3954
}
4055

4156
[HttpPost]
4257
[AdminAuthorize]
4358
[ChildActionOnly]
44-
public ActionResult Configure(ConfigurationModel model)
59+
public ActionResult Configure(ConfigurationModel model, FormCollection form)
4560
{
4661
if (!ModelState.IsValid)
4762
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);
4867

4968
//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();
5579

5680
return View("SmartStore.Plugin.Payments.Manual.Views.PaymentManual.Configure", model);
5781
}

src/Plugins/Payments.Manual/Models/ConfigurationModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class ConfigurationModel : ModelBase
1212
[SmartResourceDisplayName("Plugins.Payments.Manual.Fields.AdditionalFee")]
1313
public decimal AdditionalFee { get; set; }
1414

15-
public int TransactModeId { get; set; }
16-
[SmartResourceDisplayName("Plugins.Payments.Manual.Fields.TransactMode")]
15+
[SmartResourceDisplayName("Plugins.Payments.Manual.Fields.TransactMode")]
16+
public int TransactMode { get; set; }
1717
public SelectList TransactModeValues { get; set; }
1818
}
1919
}

src/Plugins/Payments.Manual/Views/PaymentManual/Configure.cshtml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
}
44
@model SmartStore.Plugin.Payments.Manual.Models.ConfigurationModel
55
@using SmartStore.Web.Framework;
6+
7+
@Html.Action("StoreScopeConfiguration", "Setting", new { area = "Admin" })
68
@using (Html.BeginForm())
79
{
810
<table class="adminContent">
911
<tr>
1012
<td class="adminTitle">
11-
@Html.SmartLabelFor(model => model.TransactModeValues)
13+
@Html.SmartLabelFor(model => model.TransactMode)
1214
</td>
1315
<td class="adminData">
14-
@Html.DropDownList("TransactModeId", Model.TransactModeValues)
16+
@Html.SettingOverrideCheckbox(model => model.TransactMode)
17+
@Html.DropDownList("TransactMode", Model.TransactModeValues)
1518
</td>
1619
</tr>
1720
<tr>
1821
<td class="adminTitle">
1922
@Html.SmartLabelFor(model => model.AdditionalFee)
2023
</td>
2124
<td class="adminData">
22-
@Html.EditorFor(model => model.AdditionalFee)
25+
@Html.SettingEditorFor(model => model.AdditionalFee)
2326
@Html.ValidationMessageFor(model => model.AdditionalFee)
2427
</td>
2528
</tr>
@@ -28,7 +31,7 @@
2831
@Html.SmartLabelFor(model => model.AdditionalFeePercentage)
2932
</td>
3033
<td class="adminData">
31-
@Html.EditorFor(model => model.AdditionalFeePercentage)
34+
@Html.SettingEditorFor(model => model.AdditionalFeePercentage)
3235
@Html.ValidationMessageFor(model => model.AdditionalFeePercentage)
3336
</td>
3437
</tr>

0 commit comments

Comments
 (0)