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
2 changes: 1 addition & 1 deletion dxa.net/NuGet/Sdl.ECommerce.Dxa.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<dependency id="Sdl.Web.Delivery" version="8.5.0" />
<dependency id="Microsoft.AspNet.Mvc" version="5.2.3" />
<dependency id="RestSharp" version="105.2.3" />
<dependency id="Sdl.ECommerce.Formatting" version="1.2.0" />
</dependencies>
</metadata>
<files>
<file src="SDL.ECommerce.Dxa\bin\SDL.ECommerce.Dxa.dll" target="lib\net452" />
<file src="SDL.ECommerce.Dxa\bin\SDL.ECommerce.Formatting.dll" target="lib\net452" />
<file src="SDL.ECommerce.Dxa\bin\SDL.ECommerce.Api.dll" target="lib\net452" />
<file src="SDL.ECommerce.Dxa\bin\SDL.ECommerce.OData.dll" target="lib\net452" />
<file src="SDL.ECommerce.Dxa\bin\SDL.ECommerce.Rest.dll" target="lib\net452" />
Expand Down
17 changes: 17 additions & 0 deletions dxa.net/NuGet/Sdl.ECommerce.Formatting.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Sdl.ECommerce.Formatting</id>
<version>1.2.0</version>
<authors>Sdl</authors>
<owners>Sdl</owners>
<summary></summary>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Sdl ECommerce Formatting.</description>
<releaseNotes></releaseNotes>
<copyright>© Sdl 2018</copyright>
</metadata>
<files>
<file src="SDL.ECommerce.Dxa\bin\SDL.ECommerce.Formatting.dll" target="lib\net452" />
</files>
</package>
8 changes: 6 additions & 2 deletions dxa.net/NuGet/nuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ Param(
[string]$exampleViewsVersion = "0.0.1",

[Parameter(Mandatory=$false, HelpMessage="Sdl.Dxa.Modules.Navigation version.")]
[string]$modulesNavigationVersion = "0.0.1"
[string]$modulesNavigationVersion = "0.0.1",

[Parameter(Mandatory=$false, HelpMessage="Sdl.ECommerce.Formatting version.")]
[string]$formattingVersion = "0.0.1"
)

$ErrorActionPreference = 'Stop';
Expand All @@ -43,4 +46,5 @@ $nuGetFile = Get-ChildItem -Path (Join-Path $PSScriptRoot "packages") -Filter "n

& $nuGetFile.FullName pack 'Sdl.ECommerce.Dxa.nuspec' -version $dxaVersion -basepath $basePath -outputdirectory $outputDirectory
& $nuGetFile.FullName pack 'Sdl.ECommerce.Example.Views.nuspec' -version $exampleViewsVersion -basepath $basePath -outputdirectory $outputDirectory
& $nuGetFile.FullName pack 'Sdl.Dxa.Modules.Navigation.nuspec' -version $modulesNavigationVersion -basepath $basePath -outputdirectory $outputDirectory
& $nuGetFile.FullName pack 'Sdl.Dxa.Modules.Navigation.nuspec' -version $modulesNavigationVersion -basepath $basePath -outputdirectory $outputDirectory
& $nuGetFile.FullName pack 'Sdl.ECommerce.Formatting.nuspec' -version $formattingVersion -basepath $basePath -outputdirectory $outputDirectory
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ public interface ICategory
/// Get the category's path name which can based on the name of the category.
/// </summary>
string PathName { get; }

/// <summary>
/// Get the category's sanitized path name which can based on the name of the category.
/// </summary>
string SanitizedPathName { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ECommerceContext
private static readonly IDictionary<string, IECommerceClient> clients = new ConcurrentDictionary<string,IECommerceClient>();

private const int DEFAULT_CATEGORY_EXPIRY_TIMEOUT = 3600000;
private const bool DEFAULT_CATEGORY_USE_SANITIZED_PATHNAMES = false;


/// <summary>
Expand Down Expand Up @@ -82,16 +83,18 @@ private static IECommerceClient Create(string locale)
var clientType = WebConfigurationManager.AppSettings["ecommerce-service-client-type"] ?? "odata";
var categoryExpiryTimeoutStr = WebConfigurationManager.AppSettings["ecommerce-category-expiry-timeout"];
int categoryExpiryTimeout = categoryExpiryTimeoutStr != null ? int.Parse(categoryExpiryTimeoutStr) : DEFAULT_CATEGORY_EXPIRY_TIMEOUT;
var useSanitizedPathNamesStr = WebConfigurationManager.AppSettings["ecommerce-category-use-sanitized-pathnames"];
bool useSanitizedPathNames = useSanitizedPathNamesStr != null ? bool.Parse(useSanitizedPathNamesStr) : DEFAULT_CATEGORY_USE_SANITIZED_PATHNAMES;

if (clientType.Equals("odata"))
{
// TODO: Get token service data here as well
return new OData.ECommerceClient(endpointAddress, locale, DependencyResolver.Current.GetService);
return new OData.ECommerceClient(endpointAddress, locale, useSanitizedPathNames, DependencyResolver.Current.GetService);
}

if (clientType.Equals("rest"))
{
return new ECommerceClient(endpointAddress, locale, new DXACacheProvider(locale), categoryExpiryTimeout, DependencyResolver.Current.GetService);
return new ECommerceClient(endpointAddress, locale, new DXACacheProvider(locale), categoryExpiryTimeout, useSanitizedPathNames, DependencyResolver.Current.GetService);
}

throw new DxaException("Invalid client type configured for the E-Commerce service: " + clientType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SDL.ECommerce.Formatting</RootNamespace>
<AssemblyName>SDL.ECommerce.Formatting</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ECommerceClient : IECommerceClient
private IProductDetailService detailService;
private ICartService cartService;
private IEditService editService;
private readonly bool useSanitizedPathNames;

/// <summary>
/// Constructor
Expand All @@ -77,7 +78,8 @@ public class ECommerceClient : IECommerceClient
/// <param name="dependencies">Optional list of dependencies.</param>
public ECommerceClient(
string endpointAddress,
string locale,
string locale,
bool useSanitizedPathNames,
Func<Type, object> dependencies = null)
{
this.serviceConfiguration = new SimpleServiceConfiguration
Expand All @@ -86,6 +88,7 @@ public ECommerceClient(
Timeout = 1000
};

this.useSanitizedPathNames = useSanitizedPathNames;
this.dependencies = dependencies;
}

Expand All @@ -98,7 +101,7 @@ public IProductCategoryService CategoryService
{
if (categoryService == null)
{
categoryService = this.Resolve<IProductCategoryService>() ?? new ProductCategoryService(this);
categoryService = this.Resolve<IProductCategoryService>() ?? new ProductCategoryService(this, this.useSanitizedPathNames);
}

return categoryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ IList<ICategory> ICategory.Categories
}
}

public string SanitizedPathName { get; set; }

internal void SetParent(ICategory parent)
{
this.parent = parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public ICategory Parent
throw new NotImplementedException();
}
}

public string SanitizedPathName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@
<Project>{1030d0f7-9334-4864-b495-540e3ad7928c}</Project>
<Name>SDL.ECommerce.Api</Name>
</ProjectReference>
<ProjectReference Include="..\SDL.ECommerce.Formatting\SDL.ECommerce.Formatting.csproj">
<Project>{e2beacd6-4a49-43b4-8e84-2dc4df9a4690}</Project>
<Name>SDL.ECommerce.Formatting</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Sdl.Dxa.Framework.Web8.1.5.0\build\net452\Sdl.Dxa.Framework.Web8.targets" Condition="Exists('..\packages\Sdl.Dxa.Framework.Web8.1.5.0\build\net452\Sdl.Dxa.Framework.Web8.targets')" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SDL.ECommerce.Api.Model;
using SDL.ECommerce.Api.Service;
using SDL.ECommerce.Formatting.Servants;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -17,16 +18,20 @@ public class ProductCategoryService : IProductCategoryService
private ECommerceClient ecommerceClient;

private int categoryExpiryTimeout = 3600000; // TODO: Have this configurable
private bool useSanitizedPathNames = false;
private ICategory rootCategory = new Category();
private readonly ISanitizerServant _sanitizerServant;

/// <summary>
/// Constructor (only availably internally)
/// </summary>
/// <param name="service"></param>
internal ProductCategoryService(ECommerceClient ecommerceClient)
internal ProductCategoryService(ECommerceClient ecommerceClient, bool useSanitizedPathNames)
{
this.ecommerceClient = ecommerceClient;
this.GetTopLevelCategories();
this.useSanitizedPathNames = useSanitizedPathNames;
_sanitizerServant = new SanitizerServant(new SanitizerConfiguration());
this.GetTopLevelCategories();
}

/// <summary>
Expand Down Expand Up @@ -168,6 +173,12 @@ internal void LoadCategories(ICategory parent, IECommerceODataV4Service service)
else
{
((Category)category).SetParent(parent);

if (this.useSanitizedPathNames)
{
((Category)category).SanitizedPathName = SanitizePathName(category.PathName);
}

newCategoryList.Add(category);
}
}
Expand All @@ -179,6 +190,16 @@ internal void LoadCategories(ICategory parent, IECommerceODataV4Service service)

}

/// <summary>
/// Sanitize a path name
/// </summary>
/// <param name="categoryId"></param>
/// <returns></returns>
private string SanitizePathName(string pathName)
{
return _sanitizerServant.SanitizedUrlString(pathName);
}

/// <summary>
/// Get category by Id via the cache. If setting the optional parameter 'refresh=true', then checks
/// will be done on the categories while navigating if anyone needs to be refreshed.
Expand Down Expand Up @@ -225,9 +246,19 @@ private ICategory GetCategoryByPathName(IList<ICategory> categories, String path
{
foreach (var category in categories)
{
if (category.PathName.Equals(pathName))
if (this.useSanitizedPathNames)
{
return category;
if (category.SanitizedPathName != null && category.SanitizedPathName.Equals(pathName))
{
return category;
}
}
else
{
if (category.PathName.Equals(pathName))
{
return category;
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ECommerceClient : IECommerceClient
private readonly RestClient restClient;
private readonly IECommerceCacheProvider cacheProvider;
private readonly int categoryExpiryTimeout;
private readonly bool useSanitizedPathNames;

private IProductCategoryService categoryService;
private IProductDetailService productDetailService;
Expand All @@ -23,11 +24,13 @@ public ECommerceClient(string endpointAddress,
string locale,
IECommerceCacheProvider cacheProvider,
int categoryExpiryTimeout,
bool useSanitizedPathNames,
Func<Type, object> dependencies = null)
{
this.restClient = new RestClient(endpointAddress + "/rest/v1/" + locale);
this.cacheProvider = cacheProvider;
this.categoryExpiryTimeout = categoryExpiryTimeout;
this.useSanitizedPathNames = useSanitizedPathNames;
this.dependencies = dependencies;
}

Expand All @@ -49,7 +52,7 @@ public IProductCategoryService CategoryService
{
if ( categoryService == null )
{
categoryService = Resolve<IProductCategoryService>() ?? new ProductCategoryService(this.restClient, this.categoryExpiryTimeout);
categoryService = Resolve<IProductCategoryService>() ?? new ProductCategoryService(this.restClient, this.categoryExpiryTimeout, this.useSanitizedPathNames);
}
return categoryService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Category : ICategory
public string Id { get; set; }
public string Name { get; set; }
public string PathName { get; set; }
public string SanitizedPathName { get; set; }
public List<string> ParentIds { get; set; }

IList<ICategory> ICategory.Categories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,13 @@ public string PathName
return GetCategory().PathName;
}
}

public string SanitizedPathName
{
get
{
return GetCategory().SanitizedPathName;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
<Project>{1030d0f7-9334-4864-b495-540e3ad7928c}</Project>
<Name>SDL.ECommerce.Api</Name>
</ProjectReference>
<ProjectReference Include="..\SDL.ECommerce.Formatting\SDL.ECommerce.Formatting.csproj">
<Project>{e2beacd6-4a49-43b4-8e84-2dc4df9a4690}</Project>
<Name>SDL.ECommerce.Formatting</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using RestSharp;
using SDL.ECommerce.Rest.Model;
using SDL.ECommerce.Api;
using SDL.ECommerce.Formatting.Servants;

namespace SDL.ECommerce.Rest.Service
{
Expand All @@ -15,14 +16,18 @@ namespace SDL.ECommerce.Rest.Service
class ProductCategoryService : IProductCategoryService
{
private RestClient restClient;
private int categoryExpiryTimeout = 3600000;
private int categoryExpiryTimeout = 3600000;
private bool useSanitizedPathNames = false;
private ICategory rootCategory = new Category();
private readonly ISanitizerServant _sanitizerServant;

public ProductCategoryService(RestClient restClient, int categoryExpiryTimeout)
public ProductCategoryService(RestClient restClient, int categoryExpiryTimeout, bool useSanitizedPathNames)
{
this.restClient = restClient;
this.useSanitizedPathNames = useSanitizedPathNames;
_sanitizerServant = new SanitizerServant(new SanitizerConfiguration());
this.GetTopLevelCategories();
this.categoryExpiryTimeout = categoryExpiryTimeout;
this.categoryExpiryTimeout = categoryExpiryTimeout;
}

/// <summary>
Expand Down Expand Up @@ -163,6 +168,12 @@ internal void LoadCategories(ICategory parent)
else
{
((Category)category).SetParent(parent);

if (this.useSanitizedPathNames)
{
((Category)category).SanitizedPathName = SanitizePathName(category.PathName);
}

newCategoryList.Add(category);
}
}
Expand All @@ -174,6 +185,16 @@ internal void LoadCategories(ICategory parent)

}

/// <summary>
/// Sanitize a path name
/// </summary>
/// <param name="categoryId"></param>
/// <returns></returns>
private string SanitizePathName(string pathName)
{
return _sanitizerServant.SanitizedUrlString(pathName);
}

/// <summary>
/// Get categories from service
/// </summary>
Expand Down Expand Up @@ -248,9 +269,19 @@ private ICategory GetCategoryByPathName(IList<ICategory> categories, String path
{
foreach (var category in categories)
{
if (category.PathName.Equals(pathName))
if (this.useSanitizedPathNames)
{
if (category.SanitizedPathName != null && category.SanitizedPathName.Equals(pathName))
{
return category;
}
}
else
{
return category;
if (category.PathName.Equals(pathName))
{
return category;
}
}
}
return null;
Expand Down
Loading