Skip to content

Commit ac52a11

Browse files
AndreiMazskoshelev
authored andcommitted
Initial commit
0 parents  commit ac52a11

15 files changed

+1532
-0
lines changed

.gitignore

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#################
2+
## Visual Studio
3+
#################
4+
5+
## Ignore Visual Studio temporary files, build results, and
6+
## files generated by popular Visual Studio add-ons.
7+
8+
# User-specific files
9+
*.suo
10+
*.user
11+
*.sln.docstates
12+
13+
# Build results
14+
15+
.vs/
16+
[Dd]ebug/
17+
[Rr]elease/
18+
x64/
19+
[Bb]in/
20+
[Oo]bj/
21+
22+
# MSTest test Results
23+
[Tt]est[Rr]esult*/
24+
[Bb]uild[Ll]og.*
25+
26+
*_i.c
27+
*_p.c
28+
*.ilk
29+
*.meta
30+
*.obj
31+
*.pch
32+
*.pdb
33+
*.pgc
34+
*.pgd
35+
*.rsp
36+
*.sbr
37+
*.tlb
38+
*.tli
39+
*.tlh
40+
*.tmp
41+
*.tmp_proj
42+
*.log
43+
*.vspscc
44+
*.vssscc
45+
.builds
46+
*.pidb
47+
*.log
48+
*.scc
49+
50+
# Visual C++ cache files
51+
ipch/
52+
*.aps
53+
*.ncb
54+
*.opensdf
55+
*.sdf
56+
*.cachefile
57+
58+
# Visual Studio profiler
59+
*.psess
60+
*.vsp
61+
*.vspx
62+
63+
# Guidance Automation Toolkit
64+
*.gpState
65+
66+
# ReSharper is a .NET coding add-in
67+
_ReSharper*/
68+
*.[Rr]e[Ss]harper
69+
70+
# TeamCity is a build add-in
71+
_TeamCity*
72+
73+
# DotCover is a Code Coverage Tool
74+
*.dotCover
75+
76+
# NCrunch
77+
*.ncrunch*
78+
.*crunch*.local.xml
79+
80+
# Installshield output folder
81+
[Ee]xpress/
82+
83+
# DocProject is a documentation generator add-in
84+
DocProject/buildhelp/
85+
DocProject/Help/*.HxT
86+
DocProject/Help/*.HxC
87+
DocProject/Help/*.hhc
88+
DocProject/Help/*.hhk
89+
DocProject/Help/*.hhp
90+
DocProject/Help/Html2
91+
DocProject/Help/html
92+
93+
# Click-Once directory
94+
publish/
95+
96+
# Publish Web Output
97+
*.Publish.xml
98+
*.pubxml
99+
100+
# NuGet Packages Directory
101+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
102+
#packages/
103+
104+
# Windows Azure Build Output
105+
csx
106+
*.build.csdef
107+
108+
# Windows Store app package directory
109+
AppPackages/
110+
111+
# Others
112+
sql/
113+
*.Cache
114+
ClientBin/
115+
[Ss]tyle[Cc]op.*
116+
~$*
117+
*~
118+
*.dbmdl
119+
*.[Pp]ublish.xml
120+
*.pfx
121+
*.publishsettings
122+
123+
# RIA/Silverlight projects
124+
Generated_Code/
125+
126+
# Backup & report files from converting an old project file to a newer
127+
# Visual Studio version. Backup files are not needed, because we have git ;-)
128+
_UpgradeReport_Files/
129+
Backup*/
130+
UpgradeLog*.XML
131+
UpgradeLog*.htm
132+
133+
# SQL Server files
134+
App_Data/*.mdf
135+
App_Data/*.ldf
136+
137+
#############
138+
## Windows detritus
139+
#############
140+
141+
# Windows image file caches
142+
Thumbs.db
143+
ehthumbs.db
144+
145+
# Folder config file
146+
Desktop.ini
147+
148+
# Recycle Bin used on file shares
149+
$RECYCLE.BIN/
150+
151+
# Mac crap
152+
.DS_Store
153+
154+
155+
#######################
156+
## nopCommerce specific
157+
###########
158+
glob:*.user
159+
*.patch
160+
*.hg
161+
src/Presentation/Nop.Web/Plugins/*
162+
src/Presentation/Nop.Web/Content/Images/Thumbs/*
163+
src/Presentation/Nop.Web/App_Data/InstalledPlugins.txt
164+
src/Presentation/Nop.Web/App_Data/Settings.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
using System;
2+
using System.Text;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Nop.Plugin.Shipping.USPS.Domain;
5+
using Nop.Plugin.Shipping.USPS.Models;
6+
using Nop.Services.Configuration;
7+
using Nop.Services.Localization;
8+
using Nop.Services.Security;
9+
using Nop.Web.Framework;
10+
using Nop.Web.Framework.Controllers;
11+
using Nop.Web.Framework.Mvc.Filters;
12+
13+
namespace Nop.Plugin.Shipping.USPS.Controllers
14+
{
15+
[AuthorizeAdmin]
16+
[Area(AreaNames.Admin)]
17+
public class ShippingUSPSController : BasePluginController
18+
{
19+
#region Fields
20+
21+
private readonly USPSSettings _uspsSettings;
22+
private readonly ISettingService _settingService;
23+
private readonly ILocalizationService _localizationService;
24+
private readonly IPermissionService _permissionService;
25+
26+
#endregion
27+
28+
#region Ctor
29+
30+
public ShippingUSPSController(USPSSettings uspsSettings,
31+
ISettingService settingService,
32+
ILocalizationService localizationService,
33+
IPermissionService permissionService)
34+
{
35+
this._uspsSettings = uspsSettings;
36+
this._settingService = settingService;
37+
this._localizationService = localizationService;
38+
this._permissionService = permissionService;
39+
}
40+
41+
#endregion
42+
43+
#region Methods
44+
45+
public IActionResult Configure()
46+
{
47+
if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
48+
return AccessDeniedView();
49+
50+
var model = new USPSShippingModel();
51+
model.Url = _uspsSettings.Url;
52+
model.Username = _uspsSettings.Username;
53+
model.Password = _uspsSettings.Password;
54+
model.AdditionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge;
55+
56+
// Load Domestic service names
57+
string carrierServicesOfferedDomestic = _uspsSettings.CarrierServicesOfferedDomestic;
58+
foreach (string service in USPSServices.DomesticServices)
59+
model.AvailableCarrierServicesDomestic.Add(service);
60+
61+
if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic))
62+
foreach (string service in USPSServices.DomesticServices)
63+
{
64+
string serviceId = USPSServices.GetServiceIdDomestic(service);
65+
if (!String.IsNullOrEmpty(serviceId))
66+
{
67+
// Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
68+
if (carrierServicesOfferedDomestic.Contains($"[{serviceId}]"))
69+
model.CarrierServicesOfferedDomestic.Add(service);
70+
}
71+
}
72+
73+
// Load Internation service names
74+
string carrierServicesOfferedInternational = _uspsSettings.CarrierServicesOfferedInternational;
75+
foreach (string service in USPSServices.InternationalServices)
76+
model.AvailableCarrierServicesInternational.Add(service);
77+
78+
if (!String.IsNullOrEmpty(carrierServicesOfferedInternational))
79+
foreach (string service in USPSServices.InternationalServices)
80+
{
81+
string serviceId = USPSServices.GetServiceIdInternational(service);
82+
if (!String.IsNullOrEmpty(serviceId))
83+
{
84+
// Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
85+
if (carrierServicesOfferedInternational.Contains($"[{serviceId}]"))
86+
model.CarrierServicesOfferedInternational.Add(service);
87+
}
88+
}
89+
return View("~/Plugins/Shipping.USPS/Views/Configure.cshtml", model);
90+
}
91+
92+
[HttpPost]
93+
[AdminAntiForgery]
94+
public IActionResult Configure(USPSShippingModel model)
95+
{
96+
if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
97+
return AccessDeniedView();
98+
99+
if (!ModelState.IsValid)
100+
return Configure();
101+
102+
//save settings
103+
_uspsSettings.Url = model.Url;
104+
_uspsSettings.Username = model.Username;
105+
_uspsSettings.Password = model.Password;
106+
_uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge;
107+
108+
109+
110+
// Save selected Domestic services
111+
var carrierServicesOfferedDomestic = new StringBuilder();
112+
int carrierServicesDomesticSelectedCount = 0;
113+
if (model.CheckedCarrierServicesDomestic != null)
114+
{
115+
foreach (var cs in model.CheckedCarrierServicesDomestic)
116+
{
117+
carrierServicesDomesticSelectedCount++;
118+
119+
string serviceId = USPSServices.GetServiceIdDomestic(cs);
120+
//unselect any other services if NONE is selected
121+
if (!String.IsNullOrEmpty(serviceId) && serviceId.Equals("NONE"))
122+
{
123+
carrierServicesOfferedDomestic.Clear();
124+
carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId);
125+
break;
126+
}
127+
128+
if (!String.IsNullOrEmpty(serviceId))
129+
{
130+
// Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
131+
carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId);
132+
}
133+
}
134+
}
135+
// Add default options if no services were selected
136+
if (carrierServicesDomesticSelectedCount == 0)
137+
_uspsSettings.CarrierServicesOfferedDomestic = "[1]:[3]:[4]:";
138+
else
139+
_uspsSettings.CarrierServicesOfferedDomestic = carrierServicesOfferedDomestic.ToString();
140+
141+
142+
143+
// Save selected International services
144+
var carrierServicesOfferedInternational = new StringBuilder();
145+
int carrierServicesInternationalSelectedCount = 0;
146+
if (model.CheckedCarrierServicesInternational != null)
147+
{
148+
foreach (var cs in model.CheckedCarrierServicesInternational)
149+
{
150+
carrierServicesInternationalSelectedCount++;
151+
string serviceId = USPSServices.GetServiceIdInternational(cs);
152+
// unselect other services if NONE is selected
153+
if (!String.IsNullOrEmpty(serviceId) && serviceId.Equals("NONE"))
154+
{
155+
carrierServicesOfferedInternational.Clear();
156+
carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId);
157+
break;
158+
}
159+
if (!String.IsNullOrEmpty(serviceId))
160+
{
161+
// Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
162+
carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId);
163+
}
164+
}
165+
}
166+
// Add default options if no services were selected
167+
if (carrierServicesInternationalSelectedCount == 0)
168+
_uspsSettings.CarrierServicesOfferedInternational = "[2]:[15]:[1]:";
169+
else
170+
_uspsSettings.CarrierServicesOfferedInternational = carrierServicesOfferedInternational.ToString();
171+
172+
173+
_settingService.SaveSetting(_uspsSettings);
174+
175+
SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));
176+
177+
return Configure();
178+
}
179+
180+
#endregion
181+
}
182+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//------------------------------------------------------------------------------
2+
// Contributor(s): RJH 08/07/2009.
3+
//------------------------------------------------------------------------------
4+
5+
namespace Nop.Plugin.Shipping.USPS.Domain
6+
{
7+
internal enum USPSPackageSize
8+
{
9+
Regular,
10+
Large,
11+
}
12+
}

0 commit comments

Comments
 (0)