Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LiquidBlogComment(BlogComment blogComment, BlogPost blogPost, Store store
_host = host;
_language = language;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LiquidCustomer(Customer customer, Store store, DomainHost host, CustomerN
_customerNote = customerNote;
_store = store;
_host = host;
url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');
AdditionalTokens = new Dictionary<string, string>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LiquidKnowledgebase(KnowledgebaseArticle article, KnowledgebaseArticleCom
_host = host;
_language = language;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LiquidMerchandiseReturn(MerchandiseReturn merchandiseReturn, Store store,
_host = host;
_merchandiseReturnNote = merchandiseReturnNote;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

Items = new List<LiquidMerchandiseReturnItem>();
AdditionalTokens = new Dictionary<string, string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LiquidNewsComment(NewsItem newsItem, NewsComment newsComment, Store store
_language = language;
_host = host;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public LiquidNewsLetterSubscription(NewsLetterSubscription subscription, Store s
_store = store;
_host = host;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LiquidOrder(Order order, Customer customer, Language language, Currency c
_vendor = vendor;
_host = host;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');


OrderItems = new List<LiquidOrderItem>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public LiquidOrderItem(OrderItem orderItem, Product product, Language language,
_vendor = vendor;
_host = host;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LiquidOutOfStockSubscription(Product product, OutOfStockSubscription outO
_language = language;
_host = host;

url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public LiquidProduct(Product product, Language language, Store store, DomainHost
_language = language;
_store = store;
_host = host;
url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

AdditionalTokens = new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LiquidShipment(Shipment shipment, Order order, Store store, DomainHost ho
_store = store;
_order = order;
_host = host;
url = _host?.Url.Trim('/') ?? (_store.SslEnabled ? _store.SecureUrl.Trim('/') : _store.Url.Trim('/'));
url = _host?.Url.Trim('/') ?? _store.Url.Trim('/');

ShipmentItems = new List<LiquidShipmentItem>();
AdditionalTokens = new Dictionary<string, string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LiquidStore(Store store, Language language, EmailAccount emailAccount = n

public string Shortcut => _store.Shortcut;

public string URL => _store.SslEnabled ? _store.SecureUrl : _store.Url;
public string URL => _store.Url;

public string Email => _emailAccount.Email;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async Task Generate(Stream stream, Language language, Store store)
/// <returns>Protocol name as string</returns>
private string GetHttpProtocol()
{
return _request.Store.SslEnabled ? "https" : "http";
return GetStoreUri().Scheme;
}

/// <summary>
Expand All @@ -115,9 +115,7 @@ private string GetHttpProtocol()
/// <returns>Protocol name as string</returns>
private HostString GetHost()
{
return _request.Store.SslEnabled
? new HostString(_request.Store.SecureUrl.Replace("https://", "").Trim('/'))
: new HostString(_request.Store.Url.Replace("http://", "").Trim('/'));
return new HostString(GetStoreUri().Authority);
}

/// <summary>
Expand All @@ -126,7 +124,12 @@ private HostString GetHost()
/// <returns>Store url</returns>
private string GetStoreLocation()
{
return _request.Store.SslEnabled ? _request.Store.SecureUrl : _request.Store.Url;
return _request.Store.Url;
}

private Uri GetStoreUri()
{
return new Uri(_request.Store.Url);
}

private async Task<IList<SitemapUrl>> GenerateUrls(Language language, Store store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async Task ProductList()
product.ProductPictures.OrderByDescending(p => p.IsDefault)
.ThenBy(p => p.DisplayOrder)
.FirstOrDefault()?.PictureId, 100,
storeLocation: request.Store.SslEnabled ? request.Store.SecureUrl : request.Store.Url);
storeLocation: request.Store.Url);

//attributes
if (item.Attributes != null && item.Attributes.Any())
Expand Down
12 changes: 1 addition & 11 deletions src/Core/Grand.Domain/Stores/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@ public class Store : BaseEntity, ITranslationEntity
public string Shortcut { get; set; }

/// <summary>
/// Gets or sets the store URL
/// Gets or sets the store URL, including the scheme
/// </summary>
public string Url { get; set; }

/// <summary>
/// Gets or sets a value indicating whether SSL is enabled
/// </summary>
public bool SslEnabled { get; set; }

/// <summary>
/// Gets or sets the store secure URL (HTTPS)
/// </summary>
public string SecureUrl { get; set; }

/// <summary>
/// Gets or sets the list of domains
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Modules/Grand.Module.Api/DTOs/Common/StoreDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public class StoreDto : BaseApiEntityModel
{
public string Name { get; set; }
public string Url { get; set; }
public bool SslEnabled { get; set; }
public string SecureUrl { get; set; }
public string Hosts { get; set; }
public string DefaultLanguageId { get; set; }
public string DefaultWarehouseId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class InstallationService
protected virtual async Task InstallDataRobotsTxt(
Store store)
{
var url = store.SslEnabled ? store.SecureUrl : store.Url;
var url = store.Url;

var robotsTxt = new RobotsTxt {
Name = "RobotsTXT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ protected virtual async Task InstallStores(
new Store {
Name = "Your store name",
Shortcut = "Store",
Url = $"http://{host}/",
SecureUrl = $"https://{host}/",
SslEnabled = httpscheme.ToLowerInvariant() == "https",
Url = $"{httpscheme}://{host}/",
DisplayOrder = 1,
CompanyName = companyName,
CompanyAddress = companyAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public bool UpgradeProcess(IServiceProvider serviceProvider)
if (!store.Domains.Any())
{
var storeUri = new Uri(store.Url);
var httpscheme = store.SslEnabled ? "https" : "http";
var domain = new DomainHost {
HostName = storeUri.Authority,
Url = $"{httpscheme}://{storeUri.Authority}",
Url = $"{storeUri.Scheme}://{storeUri.Authority}",
Primary = true
};
store.Domains.Add(domain);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Grand.Data;
using Grand.Domain.Stores;
using Grand.Infrastructure.Migrations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Grand.Module.Migration.Migrations._2._4;

/// <summary>
/// Collapses the store address onto a single <see cref="Store.Url" />. Until 2.4 a store carried
/// <c>Url</c>, <c>SecureUrl</c> and <c>SslEnabled</c>, and every consumer resolved the effective
/// address as <c>SslEnabled ? SecureUrl : Url</c>. Both extra fields are gone - <c>Url</c> now holds
/// the full address including the scheme, and forcing HTTPS belongs to the host (UseHttpsRedirection,
/// UseHsts, the reverse proxy), not to the store record.
/// The effective address of an existing installation is already stored on the primary
/// <see cref="DomainHost" />: the installer, the admin store editor and the 1.1 domains migration all
/// wrote exactly that resolved value there. This copies it back onto <c>Url</c>, so a store that ran on
/// HTTPS keeps generating HTTPS links in emails, sitemap.xml and robots.txt.
/// The now unmapped <c>SslEnabled</c> and <c>SecureUrl</c> elements are left in the documents - the
/// global IgnoreExtraElementsConvention skips them on read, and they disappear the next time the store
/// is saved.
/// </summary>
public class MigrationStoreSingleUrl : IMigration
{
public int Priority => 1;
public DbVersion Version => new(2, 4);
public Guid Identity => new("9E3C7A21-08B4-4F6D-B5A2-7D14C6E39F80");
public string Name => "Collapse store Url/SecureUrl/SslEnabled onto a single Url 2.4";

/// <summary>
/// Upgrade process
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public bool UpgradeProcess(IServiceProvider serviceProvider)
{
var repository = serviceProvider.GetRequiredService<IRepository<Store>>();
var logService = serviceProvider.GetRequiredService<ILogger<MigrationStoreSingleUrl>>();

try
{
foreach (var store in repository.Table.ToList())
{
var effectiveUrl = store.Domains?.FirstOrDefault(x => x.Primary)?.Url;
if (string.IsNullOrWhiteSpace(effectiveUrl) ||
!Uri.TryCreate(effectiveUrl.Trim(), UriKind.Absolute, out _))
{
//nothing reliable to fall back to - the store keeps whatever Url it had
logService.LogWarning(
"Store {StoreName} has no usable primary domain - its Url was left as {StoreUrl}. Verify it in the admin area, it is used to build links in emails and sitemap.xml",
store.Name, store.Url);
continue;
}

//the 1.1 domains migration wrote the primary domain without a trailing slash, while the store
//url is concatenated with relative paths (robots.txt, sitemap.xml)
effectiveUrl = effectiveUrl.Trim();
if (!effectiveUrl.EndsWith("/"))
effectiveUrl += "/";

if (effectiveUrl == store.Url)
continue;

store.Url = effectiveUrl;
repository.Update(store);
}
}
catch (Exception ex)
{
logService.LogError(ex, "UpgradeProcess - MigrationStoreSingleUrl (2.4)");
}
Comment on lines +68 to +71

return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
Name: Grand Store,
Url: https://grandstore.com,
SslEnabled: true,
DefaultLanguageId: lang-001,
DisplayOrder: 1,
CompanyName: Grand LLC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
Name: Grand Store,
Url: https://grandstore.com,
SslEnabled: true,
DisplayOrder: 1,
CompanyName: Grand LLC,
CompanyAddress: 123 Commerce St,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ public Task Store_ToModel()
Id = "store-001",
Name = "Grand Store",
Url = "https://grandstore.com",
SslEnabled = true,
CompanyName = "Grand LLC",
CompanyAddress = "123 Commerce St",
CompanyPhoneNumber = "+1-555-9999",
Expand All @@ -362,7 +361,6 @@ public Task StoreModel_ToDomain()
var model = new StoreModel {
Name = "Grand Store",
Url = "https://grandstore.com",
SslEnabled = true,
CompanyName = "Grand LLC",
DefaultLanguageId = "lang-001",
DisplayOrder = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,6 @@
<span asp-validation-for="Url"></span>
</div>
</div>
<div class="form-group">
<admin-label asp-for="SslEnabled"/>
<div class="col-md-9 col-sm-9">
<label class="mt-checkbox mt-checkbox-outline control control-checkbox">
<admin-input asp-for="SslEnabled"/>
<div class="control__indicator"></div>
</label>
<span asp-validation-for="SslEnabled"></span>
</div>
</div>
<div class="form-group">
<div class="note note-info">
<em>@Loc["Admin.Configuration.Stores.Fields.SslEnabled.Hint2"]</em>
</div>
</div>
<div class="form-group" id="pnlSecureUrl">
<admin-label asp-for="SecureUrl"/>
<div class="col-md-9 col-sm-9">
<admin-input asp-for="SecureUrl"/>
<span asp-validation-for="SecureUrl"></span>
</div>
</div>
<div class="form-group">
<admin-label asp-for="DefaultLanguageId"/>
<div class="col-md-9 col-sm-9">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
@model StoreModel

<script>
$(document).ready(function () {

$("#@Html.IdFor(model => model.SslEnabled)").click(toggleSslEnabled);

toggleSslEnabled();
});

function toggleSslEnabled() {
if ($('#@Html.IdFor(model => model.SslEnabled)').is(':checked')) {
$('#pnlSecureUrl').show();
}
else {
$('#pnlSecureUrl').hide();
}
}
</script>
<vc:admin-widget widget-zone="store_details_top" additional-data="Model"/>

<div asp-validation-summary="All"></div>
Expand Down
6 changes: 0 additions & 6 deletions src/Web/Grand.Web.AdminShared/Models/Stores/StoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public class StoreModel : BaseEntityModel, ILocalizedModel<StoreLocalizedModel>
[GrandResourceDisplayName("Admin.Configuration.Stores.Fields.Url")]
public string Url { get; set; }

[GrandResourceDisplayName("Admin.Configuration.Stores.Fields.SslEnabled")]
public virtual bool SslEnabled { get; set; }

[GrandResourceDisplayName("Admin.Configuration.Stores.Fields.SecureUrl")]
public virtual string SecureUrl { get; set; }

[GrandResourceDisplayName("Admin.Configuration.Stores.Fields.DisplayOrder")]
public int DisplayOrder { get; set; }

Expand Down
Loading
Loading