Skip to content

Commit

Permalink
Return index page on 404 error when the store.IsSpa flag is activated
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed Oct 7, 2019
1 parent 872bf25 commit 4cad7f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions VirtoCommerce.Storefront.Model/Stores/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ public string Host

public bool TaxCalculationEnabled { get; set; }

/// <summary>
/// This flag restricts anonymous store access
/// </summary>
public bool AnonymousUsersAllowed { get; set; }

/// <summary>
/// This flag enables the SPA fallback routing for a store
/// </summary>
public bool IsSpa { get; set; }

public decimal FixedTaxRate { get; set; }


Expand Down
16 changes: 15 additions & 1 deletion VirtoCommerce.Storefront/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Net;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VirtoCommerce.Storefront.Infrastructure;
using VirtoCommerce.Storefront.Model;
using VirtoCommerce.Storefront.Model.Common.Exceptions;

namespace VirtoCommerce.Storefront.Controllers
Expand All @@ -10,15 +12,27 @@ namespace VirtoCommerce.Storefront.Controllers
[StorefrontRoute("error")]
public class ErrorController : Controller
{
private readonly IWorkContextAccessor _workContextAccessor;
public ErrorController(IWorkContextAccessor workContextAccessor)
{
_workContextAccessor = workContextAccessor;
}

[Route("{errCode}")]
public IActionResult Error(int? errCode)
{
//Returns index page on 404 error when the store.IsSpa flag is activated
if (errCode == StatusCodes.Status404NotFound && _workContextAccessor.WorkContext.CurrentStore.IsSpa)
{
Response.StatusCode = StatusCodes.Status200OK;
return View("index");
}
var exceptionFeature = base.HttpContext.Features.Get<IExceptionHandlerFeature>();
if (exceptionFeature != null && exceptionFeature.Error is StorefrontException storefrontException && storefrontException.View != null)
{
return View(storefrontException.View);
}
if (errCode == 404 || errCode == 500)
if (errCode == StatusCodes.Status404NotFound || errCode == StatusCodes.Status500InternalServerError)
{
return View(errCode.ToString());
}
Expand Down
1 change: 1 addition & 0 deletions VirtoCommerce.Storefront/Domain/Stores/StoreConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static Store ToStore(this storeDto.Store storeDto)
result.SubscriptionEnabled = result.Settings.GetSettingValue("Subscription.EnableSubscriptions", false);
result.TaxCalculationEnabled = result.Settings.GetSettingValue("Stores.TaxCalculationEnabled", true);
result.AnonymousUsersAllowed = result.Settings.GetSettingValue("Stores.AllowAnonymousUsers", true);
result.IsSpa = result.Settings.GetSettingValue("Stores.IsSpa", false);

return result;
}
Expand Down

0 comments on commit 4cad7f4

Please sign in to comment.