Skip to content

Commit 085c2df

Browse files
committed
Payment plugin "PayInStore" configuration per store. Added option AdditionalFeePercentage.
1 parent c95a13b commit 085c2df

8 files changed

Lines changed: 82 additions & 18 deletions

File tree

migrations/1.0.1-next/migrate-multistore.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,15 @@ set @resources='
612612
<T>Zusätzliche prozentuale Gebühr zum Gesamtbetrag. Es wird ein fester Wert verwendet, falls diese Option nicht aktiviert ist.</T>
613613
</LocaleResource>
614614
615+
<LocaleResource Name="Plugins.Payment.PayInStore.AdditionalFeePercentage">
616+
<Value>Additional fee. Use percentage</Value>
617+
<T>Zusätzliche Gebühren (prozentual)</T>
618+
</LocaleResource>
619+
<LocaleResource Name="Plugins.Payment.PayInStore.AdditionalFeePercentage.Hint">
620+
<Value>Determines whether to apply a percentage additional fee to the order total. If not enabled, a fixed value is used.</Value>
621+
<T>Zusätzliche prozentuale Gebühr zum Gesamtbetrag. Es wird ein fester Wert verwendet, falls diese Option nicht aktiviert ist.</T>
622+
</LocaleResource>
623+
615624
</Language>
616625
'
617626

src/Plugins/Payments.PayInStore/Controllers/PaymentPayInStoreController.cs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,98 @@
11
using System.Collections.Generic;
22
using System.Web.Mvc;
3+
using SmartStore.Core;
34
using SmartStore.Plugin.Payments.PayInStore.Models;
45
using SmartStore.Services.Configuration;
56
using SmartStore.Services.Localization;
67
using SmartStore.Services.Payments;
8+
using SmartStore.Services.Stores;
79
using SmartStore.Web.Framework.Controllers;
10+
using SmartStore.Web.Framework.Settings;
811

912
namespace SmartStore.Plugin.Payments.PayInStore.Controllers
1013
{
1114
public class PaymentPayInStoreController : PaymentControllerBase
1215
{
16+
private readonly IWorkContext _workContext;
17+
private readonly IStoreService _storeService;
18+
private readonly IStoreContext _storeContext;
1319
private readonly ISettingService _settingService;
14-
private readonly PayInStorePaymentSettings _payInStorePaymentSettings;
1520
private readonly ILocalizationService _localizationService;
1621

17-
public PaymentPayInStoreController(ISettingService settingService,
18-
PayInStorePaymentSettings payInStorePaymentSettings,
22+
public PaymentPayInStoreController(IWorkContext workContext,
23+
IStoreService storeService,
24+
IStoreContext storeContext,
25+
ISettingService settingService,
1926
ILocalizationService localizationService)
2027
{
28+
this._workContext = workContext;
29+
this._storeService = storeService;
30+
this._storeContext = storeContext;
2131
this._settingService = settingService;
22-
this._payInStorePaymentSettings = payInStorePaymentSettings;
23-
_localizationService = localizationService;
32+
this._localizationService = localizationService;
2433
}
2534

2635
[AdminAuthorize]
2736
[ChildActionOnly]
2837
public ActionResult Configure()
2938
{
39+
//load settings for a chosen store scope
40+
var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
41+
var payInStorePaymentSettings = _settingService.LoadSetting<PayInStorePaymentSettings>(storeScope);
42+
3043
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);
3350

3451
return View("SmartStore.Plugin.Payments.PayInStore.Views.PaymentPayInStore.Configure", model);
3552
}
3653

3754
[HttpPost]
3855
[AdminAuthorize]
3956
[ChildActionOnly]
40-
public ActionResult Configure(ConfigurationModel model)
57+
public ActionResult Configure(ConfigurationModel model, FormCollection form)
4158
{
4259
if (!ModelState.IsValid)
4360
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+
4566
//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();
4976

5077
return View("SmartStore.Plugin.Payments.PayInStore.Views.PaymentPayInStore.Configure", model);
5178
}
5279

5380
[ChildActionOnly]
5481
public ActionResult PaymentInfo()
5582
{
83+
var payInStorePaymentSettings = _settingService.LoadSetting<PayInStorePaymentSettings>(_storeContext.CurrentStore.Id);
84+
5685
var model = new PaymentInfoModel();
5786

58-
string desc = _payInStorePaymentSettings.DescriptionText;
87+
string desc = payInStorePaymentSettings.DescriptionText;
5988

6089
if (desc.StartsWith("@"))
6190
{
6291
model.DescriptionText = _localizationService.GetResource(desc.Substring(1));
6392
}
6493
else
6594
{
66-
model.DescriptionText = _payInStorePaymentSettings.DescriptionText;
95+
model.DescriptionText = payInStorePaymentSettings.DescriptionText;
6796
}
6897

6998
return View("SmartStore.Plugin.Payments.PayInStore.Views.PaymentPayInStore.PaymentInfo", model);

src/Plugins/Payments.PayInStore/Description.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FriendlyName: Pay In Store
22
SystemName: Payments.PayInStore
3-
Version: 1.00
3+
Version: 1.01
44
SupportedVersions: 1.0
55
DisplayOrder: 1
66
FileName: SmartStore.Plugin.Payments.PayInStore.dll

src/Plugins/Payments.PayInStore/Localization/resources.de-de.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
<LocaleResource Name="AdditionalFee.Hint">
2222
<Value>Bestimmt die Gebühr die dem Kunden für die Nutzung dieser Zahlart berechnet wird.</Value>
2323
</LocaleResource>
24-
<LocaleResource Name="PaymentInfoDescription">
24+
<LocaleResource Name="AdditionalFeePercentage">
25+
<Value>Zusätzliche Gebühren (prozentual)</Value>
26+
</LocaleResource>
27+
<LocaleResource Name="AdditionalFeePercentage.Hint">
28+
<Value>Zusätzliche prozentuale Gebühr zum Gesamtbetrag. Es wird ein fester Wert verwendet, falls diese Option nicht aktiviert ist.</Value>
29+
</LocaleResource>
30+
<LocaleResource Name="PaymentInfoDescription">
2531
<Value>
2632
<![CDATA[
2733
<p>Reservieren Sie Produkte und zahlen Sie an der Kasse in unserem Ladenlokal.<br />Und Hier finden Sie uns: Dortmund, Westenhellweg 88,...</p>

src/Plugins/Payments.PayInStore/Localization/resources.en-us.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
<LocaleResource Name="AdditionalFee.Hint">
2222
<Value>Determines the additional fee.</Value>
2323
</LocaleResource>
24-
24+
<LocaleResource Name="AdditionalFeePercentage">
25+
<Value>Additional fee. Use percentage</Value>
26+
</LocaleResource>
27+
<LocaleResource Name="AdditionalFeePercentage.Hint">
28+
<Value>Determines whether to apply a percentage additional fee to the order total. If not enabled, a fixed value is used.</Value>
29+
</LocaleResource>
2530
<LocaleResource Name="PaymentInfoDescription">
2631
<Value>
2732
<![CDATA[

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public class ConfigurationModel : ModelBase
1212

1313
[SmartResourceDisplayName("Plugins.Payment.PayInStore.AdditionalFee")]
1414
public decimal AdditionalFee { get; set; }
15+
16+
[SmartResourceDisplayName("Plugins.Payment.PayInStore.AdditionalFeePercentage")]
17+
public bool AdditionalFeePercentage { get; set; }
1518
}
1619
}

src/Plugins/Payments.PayInStore/PayInStorePaymentSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public class PayInStorePaymentSettings : ISettings
66
{
77
public string DescriptionText { get; set; }
88
public decimal AdditionalFee { get; set; }
9+
public bool AdditionalFeePercentage { get; set; }
910
}
1011
}

src/Plugins/Payments.PayInStore/Views/PaymentPayInStore/Configure.cshtml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
}
44
@model SmartStore.Plugin.Payments.PayInStore.Models.ConfigurationModel
55
@using SmartStore.Web.Framework;
6+
@Html.Action("StoreScopeConfiguration", "Setting", new { area = "Admin" })
67
@using (Html.BeginForm())
78
{
89
<table class="adminContent">
@@ -11,6 +12,7 @@
1112
@Html.SmartLabelFor(model => model.DescriptionText)
1213
</td>
1314
<td class="adminData">
15+
@Html.SettingOverrideCheckbox(model => model.DescriptionText)
1416
@Html.TextAreaFor(model => Model.DescriptionText, new { style = "Width: 550px; Height: 350px;" })
1517
@Html.ValidationMessageFor(model => model.DescriptionText)
1618
</td>
@@ -20,10 +22,19 @@
2022
@Html.SmartLabelFor(model => model.AdditionalFee)
2123
</td>
2224
<td class="adminData">
23-
@Html.EditorFor(model => model.AdditionalFee)
25+
@Html.SettingEditorFor(model => model.AdditionalFee)
2426
@Html.ValidationMessageFor(model => model.AdditionalFee)
2527
</td>
2628
</tr>
29+
<tr>
30+
<td class="adminTitle">
31+
@Html.SmartLabelFor(model => model.AdditionalFeePercentage)
32+
</td>
33+
<td class="adminData">
34+
@Html.SettingEditorFor(model => model.AdditionalFeePercentage)
35+
@Html.ValidationMessageFor(model => model.AdditionalFeePercentage)
36+
</td>
37+
</tr>
2738
<tr>
2839
<td>&nbsp;</td>
2940
<td style="padding-top:10px">

0 commit comments

Comments
 (0)