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.

Change type - IShoppingCartValidator

KrzysztofPajak92ff7e704956
diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs
index f2686bb16..7577103ef 100644
--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs
+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs
@@ -465,7 +465,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Orders
throw new GrandException("Cart is empty");
//validate the entire shopping cart
- var warnings = await _shoppingCartValidator.GetShoppingCartWarnings(details.Cart, details.CheckoutAttributes.ToList(), true);
+ var warnings = await _shoppingCartValidator.GetShoppingCartWarnings(details.Cart, details.CheckoutAttributes, true);
if (warnings.Any())
{
var warningsSb = new StringBuilder();
diff --git a/src/Business/Grand.Business.Checkout/Extensions/ShoppingCartEventPublisherExtensions.cs b/src/Business/Grand.Business.Checkout/Extensions/ShoppingCartEventPublisherExtensions.cs
index 541b9b21c..b8c7dbdd1 100644
--- a/src/Business/Grand.Business.Checkout/Extensions/ShoppingCartEventPublisherExtensions.cs
+++ b/src/Business/Grand.Business.Checkout/Extensions/ShoppingCartEventPublisherExtensions.cs
@@ -11,7 +11,7 @@ namespace Grand.Business.Checkout.Extensions
{
public static class ShoppingCartEventPublisherExtensions
{
- public static async Task ShoppingCartWarningsAdd<T, U>(this IMediator eventPublisher, IList<T> warnings, IList<U> shoppingCartItems, List<CustomAttribute> checkoutAttributes, bool validateCheckoutAttributes) where U : ShoppingCartItem
+ public static async Task ShoppingCartWarningsAdd<T, U>(this IMediator eventPublisher, IList<T> warnings, IList<U> shoppingCartItems, IList<CustomAttribute> checkoutAttributes, bool validateCheckoutAttributes) where U : ShoppingCartItem
{
await eventPublisher.Publish(new ShoppingCartWarningsEvent<T, U>(warnings, shoppingCartItems, checkoutAttributes, validateCheckoutAttributes));
}
diff --git a/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartValidator.cs b/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartValidator.cs
index 727d692d4..82dd09edb 100644
--- a/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartValidator.cs
+++ b/src/Business/Grand.Business.Checkout/Interfaces/Orders/IShoppingCartValidator.cs
@@ -70,7 +70,7 @@ namespace Grand.Business.Checkout.Interfaces.Orders
/// <param name="validateCheckoutAttributes">A value indicating whether to validate checkout attributes</param>
/// <returns>Warnings</returns>
Task<IList<string>> GetShoppingCartWarnings(IList<ShoppingCartItem> shoppingCart,
- List<CustomAttribute> checkoutAttributes, bool validateCheckoutAttributes);
+ IList<CustomAttribute> checkoutAttributes, bool validateCheckoutAttributes);
/// <summary>
/// Validates shopping cart item for reservation products
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs
index eef0f087c..da1b98c5c 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs
@@ -498,8 +498,7 @@ namespace Grand.Business.Checkout.Services.Orders
if (associatedProduct != null)
{
var totalQty = shoppingCartItem.Quantity * attributeValue.Quantity;
- var associatedProductWarnings = await GetShoppingCartItemWarnings(customer, new ShoppingCartItem()
- {
+ var associatedProductWarnings = await GetShoppingCartItemWarnings(customer, new ShoppingCartItem() {
ShoppingCartTypeId = shoppingCartItem.ShoppingCartTypeId,
StoreId = _workContext.CurrentStore.Id,
Quantity = totalQty,
@@ -670,9 +669,11 @@ namespace Grand.Business.Checkout.Services.Orders
}
public virtual async Task<IList<string>> GetShoppingCartWarnings(IList<ShoppingCartItem> shoppingCart,
- List<CustomAttribute> checkoutAttributes, bool validateCheckoutAttributes)
+ IList<CustomAttribute> checkoutAttributes, bool validateCheckoutAttributes)
{
var warnings = new List<string>();
+ if (checkoutAttributes == null)
+ checkoutAttributes = new List<CustomAttribute>();
bool hasStandartProducts = false;
bool hasRecurringProducts = false;
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index 138ea4972..fbd506677 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -213,7 +213,8 @@ namespace Grand.Web.Controllers
await _customerService.ResetCheckoutData(customer, _workContext.CurrentStore.Id);
//validation (cart)
- var checkoutAttributes = await customer.GetUserField<List<CustomAttribute>>(_userFieldService, SystemCustomerFieldNames.CheckoutAttributes, _workContext.CurrentStore.Id);
+ var checkoutAttributes = await customer.GetUserField<List<CustomAttribute>>(_userFieldService, SystemCustomerFieldNames.CheckoutAttributes,
+ _workContext.CurrentStore.Id);
var scWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(cart, checkoutAttributes, true);
if (scWarnings.Any())
return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs
index 15af639d0..a67cda10f 100644
--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetWishlistHandler.cs
@@ -108,7 +108,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCart
model.ShowSku = _catalogSettings.ShowSkuOnProductDetailsPage;
//cart warnings
- var cartWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(request.Cart, new List<Domain.Common.CustomAttribute>(), false);
+ var cartWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(request.Cart, null, false);
foreach (var warning in cartWarnings)
model.Warnings.Add(warning);