Skip to content

Commit

Permalink
nopSolutions#601 Add an option to subscribe to nopCommerce newsletter…
Browse files Browse the repository at this point in the history
…s during installation
  • Loading branch information
DmitriyKulagin committed Mar 15, 2023
1 parent 6b30a97 commit ed4dbc7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Libraries/Nop.Services/Common/NopCommonDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ public static partial class NopCommonDefaults
/// </remarks>
public static string NopInstallationCompletedPath => "installation-completed?version={0}&local={1}&email={2}&url={3}&language={4}&culture={5}";

/// <summary>
/// Gets a path to request the nopCommerce official site to subscribe to the nopCommerce newsletters
/// </summary>
/// <remarks>
/// {0} : subscriber email
/// </remarks>
public static string NopSubscribeNewslettersPath => "subscribe-newsletters?&email={0}";

/// <summary>
/// Gets a path to request the nopCommerce official site for available categories of marketplace extensions
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions src/Libraries/Nop.Services/Common/NopHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ public virtual async Task<string> InstallationCompletedAsync(string email, strin
return await _httpClient.GetStringAsync(url);
}

/// <summary>
/// Subscribe to nopCommerce newsletters during installation
/// </summary>
/// <param name="email">Admin email</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the asynchronous task whose result contains the result string
/// </returns>
public virtual async Task<HttpResponseMessage> SubscribeNewslettersAsync(string email)
{
//prepare URL to request
var url = string.Format(NopCommonDefaults.NopSubscribeNewslettersPath,
WebUtility.UrlEncode(email))
.ToLowerInvariant();

return await _httpClient.GetAsync(url);
}

/// <summary>
/// Get a response regarding available categories of marketplace extensions
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<LocaleResource Name="StoreInformation">
<Value>Store information</Value>
</LocaleResource>
<LocaleResource Name="SubscribeNewsletters">
<Value>Subscribe to nopCommerce newsletters</Value>
</LocaleResource>
<LocaleResource Name="Title">
<Value>nopCommerce installation</Value>
</LocaleResource>
Expand Down
13 changes: 13 additions & 0 deletions src/Presentation/Nop.Web/Controllers/InstallController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public virtual IActionResult Index()
{
AdminEmail = "[email protected]",
InstallSampleData = false,
SubscribeNewsletters = true,
InstallRegionalResources = _appSettings.Get<InstallationConfig>().InstallRegionalResources,
DisableSampleDataOption = _appSettings.Get<InstallationConfig>().DisableSampleData,
CreateDatabaseIfNotExists = false,
Expand Down Expand Up @@ -225,6 +226,18 @@ public virtual async Task<IActionResult> Index(InstallModel model)

dataProvider.InitializeDatabase();

if (model.SubscribeNewsletters)
{
try
{
var resultRequest = await _nopHttpClient.Value.SubscribeNewslettersAsync(model.AdminEmail);
}
catch
{
// ignored
}
}

var cultureInfo = new CultureInfo(NopCommonDefaults.DefaultLanguageCulture);
var regionInfo = new RegionInfo(NopCommonDefaults.DefaultLanguageCulture);

Expand Down
1 change: 1 addition & 0 deletions src/Presentation/Nop.Web/Models/Install/InstallModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public InstallModel()
public bool ConnectionStringRaw { get; set; }

public bool InstallRegionalResources { get; set; }
public bool SubscribeNewsletters { get; set; }

public string DatabaseName { get; set; }
public string ServerName { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions src/Presentation/Nop.Web/Views/Install/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@
</div>
</div>
}
<div class="form-group row">
<div class="col-md-6 offset-md-3">
<div class="form-check">
<input class="form-check-input" asp-for="SubscribeNewsletters" />
<label class="form-check-label" for="@Html.IdFor(m => m.SubscribeNewsletters)">
@ILS.GetResource("SubscribeNewsletters")
</label>
</div>
</div>
</div>
</div>
</div>

Expand Down

0 comments on commit ed4dbc7

Please sign in to comment.