Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Remove component SidebarShoppingCart - moved to the controller

KrzysztofPajak2f7df81c9f23
diff --git a/src/Web/Grand.Web/Components/SidebarShoppingCart.cs b/src/Web/Grand.Web/Components/SidebarShoppingCart.cs
deleted file mode 100644
index 3dc849dec..000000000
--- a/src/Web/Grand.Web/Components/SidebarShoppingCart.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using Grand.Business.Common.Interfaces.Security;
-using Grand.Business.Common.Services.Security;
-using Grand.Infrastructure;
-using Grand.Domain.Orders;
-using Grand.Web.Common.Components;
-using Grand.Web.Features.Models.ShoppingCart;
-using Grand.Web.Models.ShoppingCart;
-using MediatR;
-using Microsoft.AspNetCore.Mvc;
-using System.Threading.Tasks;
-
-namespace Grand.Web.ViewComponents
-{
- public class SidebarShoppingCartViewComponent : BaseViewComponent
- {
- private readonly IMediator _mediator;
- private readonly IPermissionService _permissionService;
- private readonly ShoppingCartSettings _shoppingCartSettings;
- private readonly IWorkContext _workContext;
-
- public SidebarShoppingCartViewComponent(IMediator mediator,
- IPermissionService permissionService,
- ShoppingCartSettings shoppingCartSettings,
- IWorkContext workContext)
- {
- _mediator = mediator;
- _permissionService = permissionService;
- _shoppingCartSettings = shoppingCartSettings;
- _workContext = workContext;
- }
-
- public async Task<IViewComponentResult> InvokeAsync(MiniShoppingCartModel model)
- {
- if (!_shoppingCartSettings.MiniShoppingCartEnabled)
- return Content("");
-
- if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
- return Content("");
-
- model ??= await _mediator.Send(new GetMiniShoppingCart()
- {
- Customer = _workContext.CurrentCustomer,
- Currency = _workContext.WorkingCurrency,
- Language = _workContext.WorkingLanguage,
- TaxDisplayType = _workContext.TaxDisplayType,
- Store = _workContext.CurrentStore
- });
- return View(model);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
index 08c78f4a5..1681b41d9 100644
--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
@@ -101,6 +101,24 @@ namespace Grand.Web.Controllers
#region Shopping cart
+ public async Task<IActionResult> SidebarShoppingCart()
+ {
+ if (!_shoppingCartSettings.MiniShoppingCartEnabled)
+ return Content("");
+
+ if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
+ return Content("");
+
+ var model = await _mediator.Send(new GetMiniShoppingCart() {
+ Customer = _workContext.CurrentCustomer,
+ Currency = _workContext.WorkingCurrency,
+ Language = _workContext.WorkingLanguage,
+ TaxDisplayType = _workContext.TaxDisplayType,
+ Store = _workContext.CurrentStore
+ });
+ return Json(model);
+ }
+
[HttpPost]
public virtual async Task<IActionResult> CheckoutAttributeChange(IFormCollection form,
[FromServices] ICheckoutAttributeParser checkoutAttributeParser,
diff --git a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs
index 317a1d976..895480597 100644
--- a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs
+++ b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs
@@ -91,7 +91,7 @@ namespace Grand.Web.Endpoints
// enable two factor authorization digit code page
endpointRouteBuilder.MapControllerRoute("EnableTwoFactorAuthorization",
- "account/enable-two-factor-authorization",
+ pattern + "account/enable-two-factor-authorization",
new { controller = "Account", action = "EnableTwoFactorAuthenticator" });
endpointRouteBuilder.MapControllerRoute("CustomerAddresses",
@@ -361,8 +361,8 @@ namespace Grand.Web.Endpoints
//Privacy Preference settings
endpointRouteBuilder.MapControllerRoute("PrivacyPreference",
- pattern + "privacypreference",
- new { controller = "Common", action = "PrivacyPreference" });
+ pattern + "privacypreference",
+ new { controller = "Common", action = "PrivacyPreference" });
// contact attributes with "upload file" type
endpointRouteBuilder.MapControllerRoute("UploadFileContactAttribute",
@@ -371,8 +371,8 @@ namespace Grand.Web.Endpoints
//CurrentPosition Save
endpointRouteBuilder.MapControllerRoute("CurrentPosition",
- pattern + "currentposition",
- new { controller = "Common", action = "SaveCurrentPosition" });
+ pattern + "currentposition",
+ new { controller = "Common", action = "SaveCurrentPosition" });
//robots.txt
endpointRouteBuilder.MapControllerRoute("robots.txt",
@@ -517,6 +517,12 @@ namespace Grand.Web.Endpoints
}
private void RegisterCartRoute(IEndpointRouteBuilder endpointRouteBuilder, string pattern)
{
+
+ //side bar shopping cart
+ endpointRouteBuilder.MapControllerRoute("SidebarShoppingCart",
+ $"{pattern}sidebarcart/",
+ new { controller = "ShoppingCart", action = "SidebarShoppingCart" });
+
//shopping cart
endpointRouteBuilder.MapControllerRoute("ShoppingCart",
$"{pattern}cart/",
@@ -647,7 +653,7 @@ namespace Grand.Web.Endpoints
new { controller = "Order", action = "CancelOrder" });
endpointRouteBuilder.MapControllerRoute("AddOrderNote",
- "orderdetails/ordernote/{orderId}",
+ pattern + "orderdetails/ordernote/{orderId}",
new { controller = "Order", action = "AddOrderNote" });
}
diff --git a/src/Web/Grand.Web/Views/Shared/SidebarShoppingCart.cshtml b/src/Web/Grand.Web/Views/Shared/SidebarShoppingCart.cshtml
index 8087feb13..6947ac863 100644
--- a/src/Web/Grand.Web/Views/Shared/SidebarShoppingCart.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/SidebarShoppingCart.cshtml
@@ -7,7 +7,7 @@
<ul class="sidebar-cart px-0">
<li class="nav-item">
<a href="#" target="_self" class="nav-link">
- <b-icon icon="cart" :variant="[darkMode ? 'white' : 'dark']" @@click="if(flycartfirstload){updateFly()}" v-b-toggle.sidebar-cart></b-icon>
+ <b-icon icon="cart" :variant="[darkMode ? 'white' : 'dark']" @@click="if(flycartfirstload){updateSidebarShoppingCart('@Url.RouteUrl("SidebarShoppingCart")')}" v-b-toggle.sidebar-cart></b-icon>
<span class="qty-indicator cart-qty">
<template v-if="flycartindicator == null">
@Loc["ShoppingCart.HeaderQuantity", Model]
diff --git a/src/Web/Grand.Web/Views/ShoppingCart/_ModelScript.cshtml b/src/Web/Grand.Web/Views/ShoppingCart/_ModelScript.cshtml
index 6968503c6..6dfc89da9 100644
--- a/src/Web/Grand.Web/Views/ShoppingCart/_ModelScript.cshtml
+++ b/src/Web/Grand.Web/Views/ShoppingCart/_ModelScript.cshtml
@@ -168,7 +168,7 @@
url: '@Url.RouteUrl("ChangeTypeCartItem")',
}).then(function (response) {
vmorder.cart = response.data.model;
- vm.updateFly();
+ vm.updateSidebarShoppingCart('@Url.RouteUrl("SidebarShoppingCart")');
}).then(function () {
this.vmorder.updateTotals();
});
diff --git a/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml b/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml
index 4022ae43d..7e3988200 100644
--- a/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml
+++ b/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml
@@ -32,7 +32,7 @@
}).then(function (response) {
if (response.data.success) {
vmwishlist.getModel();
- vm.updateFly();
+ vm.updateSidebarShoppingCart('@Url.RouteUrl("SidebarShoppingCart")');
vmwishlist.displayWarning('@Loc["Wishlist.AddedToCart"]', 'info', '@Loc["common.success"]');
} else {
vmwishlist.displayWarning(response.data.message, 'danger');
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/app.js b/src/Web/Grand.Web/wwwroot/theme/script/app.js
index 5d203ff5a..31b5052ec 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/app.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/app.js
@@ -223,9 +223,9 @@
this.compareProductsQty = 0;
}
},
- updateFly: function () {
+ updateSidebarShoppingCart: function (url) {
axios({
- baseURL: '/Component/Index?Name=SidebarShoppingCart',
+ baseURL: url,
method: 'get',
data: null,
headers: {