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.

GetShoppingCart set as Task - prevent for exceptions when product does not exist

KrzysztofPajakc2df21f59bff
diff --git a/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartService.cs b/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartService.cs
index 4cc84f9e5..530442094 100644
--- a/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartService.cs
+++ b/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartService.cs
@@ -21,7 +21,7 @@ namespace Grand.Business.Checkout.Interfaces.Orders
/// <param name="storeId">Store identifier; pass null to load all records</param>
/// <param name="shoppingCartType">Shopping cart type; pass null to load all records</param>
/// <returns>Shopping Cart</returns>
- IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params ShoppingCartType[] shoppingCartType);
+ Task<IList<ShoppingCartItem>> GetShoppingCart(string storeId = null, params ShoppingCartType[] shoppingCartType);
/// <summary>
/// Finds a shopping cart item in the cart
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
index b5d70fb0b..af6cff727 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
@@ -6,6 +6,7 @@ using Grand.Business.Checkout.Interfaces.CheckoutAttributes;
using Grand.Business.Checkout.Interfaces.Orders;
using Grand.Business.Common.Extensions;
using Grand.Business.Common.Interfaces.Directory;
+using Grand.Business.Common.Interfaces.Security;
using Grand.Business.Customers.Interfaces;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
@@ -34,6 +35,7 @@ namespace Grand.Business.Checkout.Services.Orders
private readonly IProductAttributeParser _productAttributeParser;
private readonly ICheckoutAttributeParser _checkoutAttributeParser;
private readonly ICustomerService _customerService;
+ private readonly IAclService _aclService;
private readonly IMediator _mediator;
private readonly IUserFieldService _userFieldService;
private readonly IProductReservationService _productReservationService;
@@ -49,6 +51,7 @@ namespace Grand.Business.Checkout.Services.Orders
IProductAttributeParser productAttributeParser,
ICheckoutAttributeParser checkoutAttributeParser,
ICustomerService customerService,
+ IAclService aclService,
IMediator mediator,
IUserFieldService userFieldService,
IProductReservationService productReservationService,
@@ -60,6 +63,7 @@ namespace Grand.Business.Checkout.Services.Orders
_productAttributeParser = productAttributeParser;
_checkoutAttributeParser = checkoutAttributeParser;
_customerService = customerService;
+ _aclService = aclService;
_mediator = mediator;
_userFieldService = userFieldService;
_productReservationService = productReservationService;
@@ -77,17 +81,28 @@ namespace Grand.Business.Checkout.Services.Orders
/// <param name="storeId">Store identifier; pass null to load all records</param>
/// <param name="shoppingCartType">Shopping cart type; pass null to load all records</param>
/// <returns>Shopping Cart</returns>
- public IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params ShoppingCartType[] shoppingCartType)
+ public virtual async Task<IList<ShoppingCartItem>> GetShoppingCart(string storeId = null, params ShoppingCartType[] shoppingCartType)
{
- IEnumerable<ShoppingCartItem> cart = _workContext.CurrentCustomer.ShoppingCartItems;
+ var model = new List<ShoppingCartItem>();
+ var cart = _workContext.CurrentCustomer.ShoppingCartItems.ToList();
if (!string.IsNullOrEmpty(storeId))
- cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, storeId);
+ cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, storeId).ToList();
if (shoppingCartType.Length > 0)
- cart = cart.Where(sci => shoppingCartType.Contains(sci.ShoppingCartTypeId));
+ cart = cart.Where(sci => shoppingCartType.Contains(sci.ShoppingCartTypeId)).ToList();
- return cart.ToList();
+ foreach (var item in cart)
+ {
+ var product = await _productService.GetProductById(item.ProductId);
+ if (product == null || !product.Published || !_aclService.Authorize(product, _workContext.CurrentCustomer))
+ continue;
+
+ model.Add(item);
+ }
+
+
+ return model;
}
/// <summary>
diff --git a/src/Plugins/Payments.BrainTree/Components/PaymentBrainTreeViewComponent.cs b/src/Plugins/Payments.BrainTree/Components/PaymentBrainTreeViewComponent.cs
index 1ea19bddf..bd679e66c 100644
--- a/src/Plugins/Payments.BrainTree/Components/PaymentBrainTreeViewComponent.cs
+++ b/src/Plugins/Payments.BrainTree/Components/PaymentBrainTreeViewComponent.cs
@@ -43,7 +43,7 @@ namespace Payments.BrainTree.Components
if (_brainTreePaymentSettings.Use3DS)
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart);
if (!cart.Any())
throw new Exception("Your cart is empty");
diff --git a/src/Web/Grand.Web/Components/EmailWishlist.cs b/src/Web/Grand.Web/Components/EmailWishlist.cs
index 1c885cd87..6d91431ca 100644
--- a/src/Web/Grand.Web/Components/EmailWishlist.cs
+++ b/src/Web/Grand.Web/Components/EmailWishlist.cs
@@ -40,7 +40,7 @@ namespace Grand.Web.ViewComponents
if (!await _permissionService.Authorize(StandardPermission.EnableWishlist) || !_shoppingCartSettings.EmailWishlistEnabled)
return Content("");
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist);
if (!cart.Any())
return Content("");
diff --git a/src/Web/Grand.Web/Components/EstimateShipping.cs b/src/Web/Grand.Web/Components/EstimateShipping.cs
index e8545d53a..af5f6b0e1 100644
--- a/src/Web/Grand.Web/Components/EstimateShipping.cs
+++ b/src/Web/Grand.Web/Components/EstimateShipping.cs
@@ -24,7 +24,7 @@ namespace Grand.Web.ViewComponents
public async Task<IViewComponentResult> InvokeAsync()
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart);
var model = await _mediator.Send(new GetEstimateShipping()
{
diff --git a/src/Web/Grand.Web/Components/OrderSummary.cs b/src/Web/Grand.Web/Components/OrderSummary.cs
index 39212d64a..8edf17bcb 100644
--- a/src/Web/Grand.Web/Components/OrderSummary.cs
+++ b/src/Web/Grand.Web/Components/OrderSummary.cs
@@ -27,7 +27,7 @@ namespace Grand.Web.ViewComponents
if (overriddenModel != null)
return View(overriddenModel);
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var model = await _mediator.Send(new GetShoppingCart()
{
diff --git a/src/Web/Grand.Web/Components/OrderTotals.cs b/src/Web/Grand.Web/Components/OrderTotals.cs
index cb3207c7f..7b3e8d827 100644
--- a/src/Web/Grand.Web/Components/OrderTotals.cs
+++ b/src/Web/Grand.Web/Components/OrderTotals.cs
@@ -27,7 +27,7 @@ namespace Grand.Web.ViewComponents
public async Task<IViewComponentResult> InvokeAsync(bool isEditable)
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var model = await _mediator.Send(new GetOrderTotals()
{
diff --git a/src/Web/Grand.Web/Controllers/ActionCartController.cs b/src/Web/Grand.Web/Controllers/ActionCartController.cs
index 36541ef3a..84e07ddf4 100644
--- a/src/Web/Grand.Web/Controllers/ActionCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ActionCartController.cs
@@ -152,7 +152,7 @@ namespace Grand.Web.Controllers
string warehouseId = GetWarehouse(product);
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, cartType);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, cartType);
if (cartType != ShoppingCartType.Wishlist)
{
@@ -235,7 +235,7 @@ namespace Grand.Web.Controllers
}
//display notification message and update appropriate blocks
- var qty = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist).Sum(x => x.Quantity);
+ var qty = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist)).Sum(x => x.Quantity);
var updatetopwishlistsectionhtml = string.Format(_translationService.GetResource("Wishlist.HeaderQuantity"), qty);
return Json(new
@@ -272,7 +272,7 @@ namespace Grand.Web.Controllers
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
var updatetopcartsectionhtml = string.Format(_translationService.GetResource("ShoppingCart.HeaderQuantity"),
- _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray())
+ (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
.Sum(x => x.Quantity));
var miniShoppingCartmodel = _shoppingCartSettings.MiniShoppingCartEnabled ? await _mediator.Send(new GetMiniShoppingCart() {
@@ -546,7 +546,7 @@ namespace Grand.Web.Controllers
}
//display notification message and update appropriate blocks
- var qty = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist).Sum(x => x.Quantity);
+ var qty = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist)).Sum(x => x.Quantity);
var updatetopwishlistsectionhtml = string.Format(_translationService.GetResource("Wishlist.HeaderQuantity"), qty);
return Json(new
@@ -583,7 +583,7 @@ namespace Grand.Web.Controllers
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
var updatetopcartsectionhtml = string.Format(_translationService.GetResource("ShoppingCart.HeaderQuantity"),
- _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray())
+ (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
.Sum(x => x.Quantity));
var miniShoppingCartmodel = _shoppingCartSettings.MiniShoppingCartEnabled ? await _mediator.Send(new GetMiniShoppingCart() {
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index 053612a7a..44b6b6a9b 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -202,7 +202,7 @@ namespace Grand.Web.Controllers
{
var customer = _workContext.CurrentCustomer;
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
if (!cart.Any())
return RedirectToRoute("ShoppingCart");
@@ -440,7 +440,7 @@ namespace Grand.Web.Controllers
public virtual async Task<IActionResult> Start()
{
//validation
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
if (!cart.Any())
return RedirectToRoute("ShoppingCart");
@@ -492,7 +492,7 @@ namespace Grand.Web.Controllers
try
{
//validation
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
string billingAddressId = form["billing_address_id"];
@@ -594,7 +594,7 @@ namespace Grand.Web.Controllers
try
{
//validation
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
if (!cart.RequiresShipping())
@@ -773,7 +773,7 @@ namespace Grand.Web.Controllers
var customer = _workContext.CurrentCustomer;
var store = _workContext.CurrentStore;
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
if (!cart.RequiresShipping())
@@ -844,7 +844,7 @@ namespace Grand.Web.Controllers
try
{
//validation
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
string paymentmethod = form["paymentmethod"];
@@ -917,7 +917,7 @@ namespace Grand.Web.Controllers
try
{
//validation
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
var paymentMethodSystemName = await _workContext.CurrentCustomer.GetUserField<string>(
@@ -976,7 +976,7 @@ namespace Grand.Web.Controllers
try
{
//validation
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
//prevent 2 orders being placed within an X seconds time frame
diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.cs
index 5c06e0bb4..15b3349e8 100644
--- a/src/Web/Grand.Web/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web/Controllers/ProductController.cs
@@ -134,7 +134,7 @@ namespace Grand.Web.Controllers
ShoppingCartItem updatecartitem = null;
if (_shoppingCartSettings.AllowCartItemEditing && !String.IsNullOrEmpty(updatecartitemid))
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id);
updatecartitem = cart.FirstOrDefault(x => x.Id == updatecartitemid);
//not found?
@@ -850,7 +850,7 @@ namespace Grand.Web.Controllers
}
var reservations = query.ToList();
- var inCart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id)
+ var inCart = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id))
.Where(x => !string.IsNullOrEmpty(x.ReservationId)).ToList();
foreach (var cartItem in inCart)
{
diff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
index 1681b41d9..faa4b6c53 100644
--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
@@ -124,7 +124,7 @@ namespace Grand.Web.Controllers
[FromServices] ICheckoutAttributeParser checkoutAttributeParser,
[FromServices] ICheckoutAttributeFormatter checkoutAttributeFormatter)
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var checkoutAttributes = await _mediator.Send(new SaveCheckoutAttributesCommand()
{
@@ -271,7 +271,7 @@ namespace Grand.Web.Controllers
if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
return RedirectToRoute("HomePage");
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var model = await _mediator.Send(new GetShoppingCart()
{
Cart = cart,
@@ -296,7 +296,7 @@ namespace Grand.Web.Controllers
warnings = "No permission",
});
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes())
+ var cart = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes()))
.FirstOrDefault(x => x.Id == shoppingcartId);
if (cart == null)
{
@@ -323,7 +323,7 @@ namespace Grand.Web.Controllers
warnings.AddRange(currSciWarnings);
var model = await _mediator.Send(new GetShoppingCart() {
- Cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes()),
+ Cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes()),
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
Language = _workContext.WorkingLanguage,
@@ -346,7 +346,7 @@ namespace Grand.Web.Controllers
if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
return RedirectToRoute("HomePage");
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
foreach (var sci in cart)
{
@@ -368,7 +368,7 @@ namespace Grand.Web.Controllers
if (_shoppingCartSettings.AllowOnHoldCart)
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
- var item = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray())
+ var item = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
.FirstOrDefault(sci => sci.Id == id);
if (item != null)
@@ -394,7 +394,7 @@ namespace Grand.Web.Controllers
}
else
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var shoppingcartmodel = await _mediator.Send(new GetShoppingCart()
{
Cart = cart,
@@ -428,7 +428,7 @@ namespace Grand.Web.Controllers
if (_shoppingCartSettings.AllowOnHoldCart)
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
- var item = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray())
+ var item = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
.FirstOrDefault(sci => sci.Id == id);
if (item != null)
@@ -446,7 +446,7 @@ namespace Grand.Web.Controllers
Store = _workContext.CurrentStore
});
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var shoppingcartmodel = await _mediator.Send(new GetShoppingCart()
{
Cart = cart,
@@ -480,7 +480,7 @@ namespace Grand.Web.Controllers
public virtual async Task<IActionResult> StartCheckout(IFormCollection form = null)
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var checkoutAttributes = new List<CustomAttribute>();
//parse and save checkout attributes
if (form != null && form.Count > 0)
@@ -520,7 +520,7 @@ namespace Grand.Web.Controllers
[HttpPost]
public virtual async Task<IActionResult> ApplyDiscountCoupon(string discountcouponcode)
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var message = string.Empty;
var isApplied = false;
@@ -623,7 +623,7 @@ namespace Grand.Web.Controllers
if (giftvouchercouponcode != null)
giftvouchercouponcode = giftvouchercouponcode.Trim();
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var message = string.Empty;
var isApplied = false;
@@ -676,7 +676,7 @@ namespace Grand.Web.Controllers
[HttpPost]
public virtual async Task<IActionResult> GetEstimateShipping(string countryId, string stateProvinceId, string zipPostalCode, IFormCollection form)
{
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var model = await _mediator.Send(new GetEstimateShippingResult()
{
@@ -711,7 +711,7 @@ namespace Grand.Web.Controllers
}
}
}
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var model = await _mediator.Send(new GetShoppingCart()
{
@@ -743,7 +743,7 @@ namespace Grand.Web.Controllers
await _userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, result);
}
}
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
var model = await _mediator.Send(new GetShoppingCart()
{
diff --git a/src/Web/Grand.Web/Controllers/WishlistController.cs b/src/Web/Grand.Web/Controllers/WishlistController.cs
index 093d0331f..073a402b4 100644
--- a/src/Web/Grand.Web/Controllers/WishlistController.cs
+++ b/src/Web/Grand.Web/Controllers/WishlistController.cs
@@ -77,10 +77,7 @@ namespace Grand.Web.Controllers
if (customer == null)
return RedirectToRoute("HomePage");
- var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartTypeId == ShoppingCartType.Wishlist);
-
- if (!string.IsNullOrEmpty(_workContext.CurrentStore.Id))
- cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _workContext.CurrentStore.Id);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist);
var model = await _mediator.Send(new GetWishlist() {
Cart = cart.ToList(),
@@ -102,7 +99,7 @@ namespace Grand.Web.Controllers
if (!await _permissionService.Authorize(StandardPermission.EnableWishlist))
return RedirectToRoute("HomePage");
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist).FirstOrDefault(x => x.Id == shoppingcartId);
+ var cart = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist)).FirstOrDefault(x => x.Id == shoppingcartId);
if (cart == null)
{
return Json(new
@@ -132,7 +129,7 @@ namespace Grand.Web.Controllers
{
success = !warnings.Any(),
warnings = string.Join(", ", warnings),
- totalproducts = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist).Sum(x => x.Quantity),
+ totalproducts = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist)).Sum(x => x.Quantity),
});
}
@@ -206,7 +203,7 @@ namespace Grand.Web.Controllers
if (!await _permissionService.Authorize(StandardPermission.EnableWishlist) || !_shoppingCartSettings.EmailWishlistEnabled)
return Content("");
- var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist);
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist);
if (!cart.Any())
return Content("");
diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetAddToCartHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetAddToCartHandler.cs
index d9bc0e906..44b52f398 100644
--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetAddToCartHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetAddToCartHandler.cs
@@ -134,7 +134,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCart
model.Picture = await PrepareCartItemPicture(request);
}
- var cart = _shoppingCartService.GetShoppingCart(request.Store.Id, request.CartType);
+ var cart = await _shoppingCartService.GetShoppingCart(request.Store.Id, request.CartType);
if (request.CartType != ShoppingCartType.Auctions)
{
diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetMiniShoppingCartHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetMiniShoppingCartHandler.cs
index 6cfb5b741..18599ee56 100644
--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetMiniShoppingCartHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetMiniShoppingCartHandler.cs
@@ -113,7 +113,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCart
if (_shoppingCartSettings.AllowOnHoldCart)
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
- var cart = _shoppingCartService.GetShoppingCart(request.Store.Id, shoppingCartTypes.ToArray());
+ var cart = await _shoppingCartService.GetShoppingCart(request.Store.Id, shoppingCartTypes.ToArray());
model.TotalProducts = cart.Sum(x => x.Quantity);
if (cart.Any())
{
diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs
index 32cee7d5a..3d6c077a6 100644
--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs
@@ -119,7 +119,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCart
foreach (var sci in request.Cart)
{
var product = await _productService.GetProductById(sci.ProductId);
- if (!_aclService.Authorize(product, request.Customer))
+ if (product == null)
continue;
var sename = product.GetSeName(request.Language.Id);
diff --git a/src/Web/Grand.Web/Views/Shared/_ShoppingCartLinks.cshtml b/src/Web/Grand.Web/Views/Shared/_ShoppingCartLinks.cshtml
index c5ed42f80..6fc3cd9f4 100644
--- a/src/Web/Grand.Web/Views/Shared/_ShoppingCartLinks.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/_ShoppingCartLinks.cshtml
@@ -1,9 +1,9 @@
@inject IWorkContext workContext
@inject Grand.Business.Common.Interfaces.Security.IPermissionService permissionService
+@inject Grand.Business.Checkout.Interfaces.Orders.IShoppingCartService shoppingCartService
@inject ShoppingCartSettings shoppingCartSettings
@inject CatalogSettings catalogSettings
@using Grand.Business.Common.Services.Security
-@using Grand.Business.Checkout.Extensions
@{
var shoppingCartTypes = new List<ShoppingCartType>();
@@ -15,16 +15,16 @@
var shoppingCartEnabled = await permissionService.Authorize(StandardPermission.EnableShoppingCart);
var wishlistEnabled = await permissionService.Authorize(StandardPermission.EnableWishlist);
var miniShoppingCartEnabled = shoppingCartSettings.MiniShoppingCartEnabled;
- var shoppingCartItems = workContext.CurrentCustomer.ShoppingCartItems.Any() ? workContext.CurrentCustomer.ShoppingCartItems
- .Where(sci => shoppingCartTypes.Contains(sci.ShoppingCartTypeId))
- .LimitPerStore(shoppingCartSettings.SharedCartBetweenStores, workContext.CurrentStore.Id)
- .Sum(x => x.Quantity) : 0;
+ var shoppingCartItems =
+ workContext.CurrentCustomer.ShoppingCartItems.Any() ?
+ (await shoppingCartService.GetShoppingCart(workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions))
+ .Sum(x => x.Quantity) : 0;
- var wishlistItems = workContext.CurrentCustomer.ShoppingCartItems.Any() ? workContext.CurrentCustomer.ShoppingCartItems
- .Where(sci => sci.ShoppingCartTypeId == ShoppingCartType.Wishlist)
- .LimitPerStore(shoppingCartSettings.SharedCartBetweenStores, workContext.CurrentStore.Id)
- .Sum(x => x.Quantity) : 0;
+
+ var wishlistItems = workContext.CurrentCustomer.ShoppingCartItems.Any() ?
+ (await shoppingCartService.GetShoppingCart(workContext.CurrentStore.Id, ShoppingCartType.Wishlist))
+ .Sum(x => x.Quantity) : 0;
}
@if (catalogSettings.CompareProductsEnabled)