Skip to content

Commit

Permalink
#1882 Allow a store owner to add custom URLs to sitemap.xml file in a…
Browse files Browse the repository at this point in the history
…dmin area (use "commonsettings.sitemapcustomurls" setting).
  • Loading branch information
AndreiMaz committed Dec 12, 2016
1 parent 9367ae4 commit e89c152
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Libraries/Nop.Core/Domain/Common/CommonSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,35 @@ public class CommonSettings : ISettings
{
public CommonSettings()
{
SitemapCustomUrls = new List<string>();
IgnoreLogWordlist = new List<string>();
}

public bool SubjectFieldOnContactUsForm { get; set; }
public bool UseSystemEmailForContactUsForm { get; set; }

public bool UseStoredProceduresIfSupported { get; set; }


/// <summary>
/// Gets or sets a value indicating whether sitemap is enabled
/// </summary>
public bool SitemapEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to include categories to sitemap
/// </summary>
public bool SitemapIncludeCategories { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to include manufacturers to sitemap
/// </summary>
public bool SitemapIncludeManufacturers { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to include products to sitemap
/// </summary>
public bool SitemapIncludeProducts { get; set; }
/// <summary>
/// A list of custom URLs to be added to sitemap.xml (include page names only)
/// </summary>
public List<string> SitemapCustomUrls { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to display a warning if java-script is disabled
Expand Down
15 changes: 15 additions & 0 deletions src/Libraries/Nop.Services/Seo/SitemapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ protected virtual void GenerateUrlNodes(UrlHelper urlHelper)
}
//topics
WriteTopics(urlHelper);
//custom URLs
WriteCustomUrls();
}

protected virtual void WriteCategories(UrlHelper urlHelper, int parentCategoryId)
Expand Down Expand Up @@ -189,6 +191,19 @@ protected virtual void WriteTopics(UrlHelper urlHelper)
}
}

protected virtual void WriteCustomUrls()
{
foreach (var customUrl in _commonSettings.SitemapCustomUrls)
{
var url = _securitySettings.ForceSslForAllPages
? _storeContext.CurrentStore.SecureUrl
: _storeContext.CurrentStore.Url;
url += customUrl;
WriteUrlLocation(url, UpdateFrequency.Weekly, DateTime.UtcNow);
}
}


#endregion

#region Methods
Expand Down
10 changes: 10 additions & 0 deletions upgradescripts/3.80-the next version/upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3026,3 +3026,13 @@ BEGIN
DROP TABLE #tmp_guests
END
GO



--new setting
IF NOT EXISTS (SELECT 1 FROM [Setting] WHERE [name] = N'commonsettings.sitemapcustomurls')
BEGIN
INSERT [Setting] ([Name], [Value], [StoreId])
VALUES (N'commonsettings.sitemapcustomurls', N'', 0)
END
GO

0 comments on commit e89c152

Please sign in to comment.