grandnode / grandnode2

Open-Source eCommerce Platform on .NET Core, MongoDB, AWS DocumentDB, Azure CosmosDB, LiteDB & Vue.js
https://grandnode.com/
GNU General Public License v3.0
1.05k stars 431 forks source link

Discount System.NullReferenceException in SubTotal in Shopping Cart x.xx #491

Closed coffeepoweredcodemachine closed 3 weeks ago

coffeepoweredcodemachine commented 2 months ago

The SubTotal in Shopping Cart x.xx discount option throws a System.NullReferenceException when you attempt to use it. All other discount codes work as expected.

Reproduction:

1) Marketing > Discounts 2) Click the Add New button. 3) Enter a name, set discount amount to 15, check requires coupon code. 4) Click Save and Continue Edit. 5) Click COUPON CODES, then ADD NEW RECORD. 6) Enter a coupon code and then click SAVE. 7) Click REQUIREMENTS. Under Add a new discount requirement choose 'SubTotal in Shopping Cart x.xx'. 8) Set the required spend amount to anything. Click SAVE. 9) Click Save. in the top right to save the discount. 10) Go to your cart and try to use the code.

Expected Result:

Coupon is applied, or an error is shown.

Actual Result:

Nothing happens in the UI. Browser Console shows an exception being thrown.

Exception detail:

System.NullReferenceException: Object reference not set to an instance of an object.\n at DiscountRules.Standard.Providers.ShoppingCartDiscountRule.CheckRequirement(DiscountRuleValidationRequest request)\n at Grand.Business.Catalog.Services.Discounts.DiscountValidationService.ValidateDiscount(Discount discount, Customer customer, Store store, Currency currency, String[] couponCodesToValidate) in /home/web/grandnode/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountValidationService.cs:line 211\n at Grand.Web.Validators.ShoppingCart.DiscountCouponValidator.<>cDisplayClass0_0.<<-ctor>b2>d.MoveNext()\n--- End of stack trace from previous location ---\n at FluentValidation.DefaultValidatorExtensions.<>cDisplayClass70_0`2.<b0>d.MoveNext() in //src/FluentValidation/DefaultValidatorExtensions.cs:line 1150\n--- End of stack trace from previous location ---\n at FluentValidation.Internal.RuleComponent2.ValidateAsync(ValidationContext1 context, TProperty value, Boolean useAsync, CancellationToken cancellation) in //src/FluentValidation/Internal/RuleComponent.cs:line 71\n at FluentValidation.Internal.PropertyRule2.ValidateAsync(ValidationContext1 context, Boolean useAsync, CancellationToken cancellation) in //src/FluentValidation/Internal/PropertyRule.cs:line 156\n at FluentValidation.AbstractValidator1.ValidateInternalAsync(ValidationContext1 context, Boolean useAsync, CancellationToken cancellation) in //src/FluentValidation/AbstractValidator.cs:line 246\n at FluentValidation.AbstractValidator1.ValidateAsync(ValidationContext1 context, CancellationToken cancellation) in /_/src/FluentValidation/AbstractValidator.cs:line 220\n at Grand.Infrastructure.Validators.ValidationFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) in /home/web/grandnode/src/Core/Grand.Infrastructure/Validators/ValidationFilter.cs:line 53\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gLogged|17_1(ResourceInvoker invoker)\n at Microsoft.AspNetCore.Routing.EndpointMiddleware.gAwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)\n at Grand.Web.Common.Middleware.ContextLoggingMiddleware.InvokeAsync(HttpContext context) in /home/web/grandnode/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs:line 34\n at Grand.Web.Common.Middleware.CultureSettingMiddleware.InvokeAsync(HttpContext context, IWorkContext workContext) in /home/web/grandnode/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs:line 32\n at Grand.Web.Common.Middleware.WorkContextMiddleware.InvokeAsync(HttpContext context, IWorkContextSetter workContext) in /home/web/grandnode/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs:line 47\n at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\n at Grand.Web.Common.Middleware.PoweredByMiddleware.InvokeAsync(HttpContext context, IPoweredByMiddlewareOptions options) in /home/web/grandnode/src/Web/Grand.Web.Common/Middleware/PoweredByMiddleware.cs:line 23\n at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)\n at Grand.Web.Common.Middleware.InstallUrlMiddleware.InvokeAsync(HttpContext context) in /home/web/grandnode/src/Web/Grand.Web.Common/Middleware/InstallUrlMiddleware.cs:line 46\n at Grand.Web.Common.Middleware.DbVersionCheckMiddleware.Invoke(HttpContext context, ICacheBase cacheBase, IRepository`1 repository) in /home/web/grandnode/src/Web/Grand.Web.Common/Middleware/DbVersionCheckMiddleware.cs:line 37\n at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)\n at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)\n at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.gAwaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)\n at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

KrzysztofPajak commented 2 months ago

@coffeepoweredcodemachine thanks for reporting, fixed https://github.com/grandnode/grandnode2/pull/492