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.

CheckoutController - minor changes

support318d9c6abc59
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index 3be3771a4..d6ec61392 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -181,81 +181,9 @@ namespace Grand.Web.Controllers
#endregion
- public virtual async Task<IActionResult> Index()
- {
- var customer = _workContext.CurrentCustomer;
-
- var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id,
- ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
-
- if (!cart.Any())
- return RedirectToRoute("ShoppingCart");
-
- if (await _groupService.IsGuest(customer) && !_orderSettings.AnonymousCheckoutAllowed)
- return Challenge();
-
- //reset checkout data
- await _customerService.ResetCheckoutData(customer, _workContext.CurrentStore.Id);
-
- //validation (cart)
- 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 });
-
- //validation (each shopping cart item)
- foreach (ShoppingCartItem sci in cart)
- {
- var product = await _productService.GetProductById(sci.ProductId);
- var sciWarnings =
- await _shoppingCartValidator.GetShoppingCartItemWarnings(customer, sci, product,
- new ShoppingCartValidatorOptions());
- if (sciWarnings.Any())
- return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
- }
-
- return RedirectToRoute("Checkout");
- }
-
- public virtual async Task<IActionResult> Completed(string orderId)
- {
- //validation
- if (await _groupService.IsGuest(_workContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
- return Challenge();
-
- Order order = null;
- if (!string.IsNullOrEmpty(orderId))
- {
- order = await _orderService.GetOrderById(orderId);
- }
-
- order ??= (await _orderService.SearchOrders(storeId: _workContext.CurrentStore.Id,
- customerId: _workContext.CurrentCustomer.Id, pageSize: 1))
- .FirstOrDefault();
-
- if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId)
- {
- return RedirectToRoute("HomePage");
- }
-
- //disable "order completed" page?
- if (_orderSettings.DisableOrderCompletedPage)
- {
- return RedirectToRoute("OrderDetails", new { orderId = order.Id });
- }
-
- //model
- var model = new CheckoutCompletedModel {
- OrderId = order.Id,
- OrderNumber = order.OrderNumber,
- OrderCode = order.Code
- };
-
- return View(model);
- }
+ #region Private methods
+
private async Task CartValidate(IList<ShoppingCartItem> cart)
{
if (!cart.Any())
@@ -266,7 +194,7 @@ namespace Grand.Web.Controllers
}
[NonAction]
- protected async Task<JsonResult> LoadStepAfterBillingAddress(IList<ShoppingCartItem> cart)
+ private async Task<JsonResult> LoadStepAfterBillingAddress(IList<ShoppingCartItem> cart)
{
var shippingMethodModel = await _mediator.Send(new GetShippingMethod {
Cart = cart,
@@ -303,7 +231,7 @@ namespace Grand.Web.Controllers
}
[NonAction]
- protected async Task<JsonResult> LoadStepAfterShippingMethod(IList<ShoppingCartItem> cart)
+ private async Task<JsonResult> LoadStepAfterShippingMethod(IList<ShoppingCartItem> cart)
{
//Check whether payment workflow is required
//we ignore loyalty points during cart total calculation
@@ -375,17 +303,8 @@ namespace Grand.Web.Controllers
});
}
- public virtual async Task<IActionResult> GetShippingFormPartialView(string shippingOption)
- {
- var routeName = await GetShippingComputation(shippingOption).GetControllerRouteName();
- if (string.IsNullOrEmpty(routeName))
- return Content("");
-
- return RedirectToRoute(routeName, new { shippingOption });
- }
-
[NonAction]
- protected async Task<JsonResult> LoadStepAfterPaymentMethod(IPaymentProvider paymentMethod,
+ private async Task<JsonResult> LoadStepAfterPaymentMethod(IPaymentProvider paymentMethod,
IList<ShoppingCartItem> cart)
{
if (await paymentMethod.SkipPaymentInfo() ||
@@ -416,6 +335,91 @@ namespace Grand.Web.Controllers
});
}
+ #endregion
+ public virtual async Task<IActionResult> Index()
+ {
+ var customer = _workContext.CurrentCustomer;
+
+ var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id,
+ ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
+
+ if (!cart.Any())
+ return RedirectToRoute("ShoppingCart");
+
+ if (await _groupService.IsGuest(customer) && !_orderSettings.AnonymousCheckoutAllowed)
+ return Challenge();
+
+ //reset checkout data
+ await _customerService.ResetCheckoutData(customer, _workContext.CurrentStore.Id);
+
+ //validation (cart)
+ 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 });
+
+ //validation (each shopping cart item)
+ foreach (ShoppingCartItem sci in cart)
+ {
+ var product = await _productService.GetProductById(sci.ProductId);
+ var sciWarnings =
+ await _shoppingCartValidator.GetShoppingCartItemWarnings(customer, sci, product,
+ new ShoppingCartValidatorOptions());
+ if (sciWarnings.Any())
+ return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
+ }
+
+ return RedirectToRoute("Checkout");
+ }
+
+ public virtual async Task<IActionResult> Completed(string orderId)
+ {
+ //validation
+ if (await _groupService.IsGuest(_workContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
+ return Challenge();
+
+ Order order = null;
+ if (!string.IsNullOrEmpty(orderId))
+ {
+ order = await _orderService.GetOrderById(orderId);
+ }
+
+ order ??= (await _orderService.SearchOrders(storeId: _workContext.CurrentStore.Id,
+ customerId: _workContext.CurrentCustomer.Id, pageSize: 1))
+ .FirstOrDefault();
+
+ if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId)
+ {
+ return RedirectToRoute("HomePage");
+ }
+
+ //disable "order completed" page?
+ if (_orderSettings.DisableOrderCompletedPage)
+ {
+ return RedirectToRoute("OrderDetails", new { orderId = order.Id });
+ }
+
+ //model
+ var model = new CheckoutCompletedModel {
+ OrderId = order.Id,
+ OrderNumber = order.OrderNumber,
+ OrderCode = order.Code
+ };
+
+ return View(model);
+ }
+
+ public virtual async Task<IActionResult> GetShippingFormPartialView(string shippingOption)
+ {
+ var routeName = await GetShippingComputation(shippingOption).GetControllerRouteName();
+ if (string.IsNullOrEmpty(routeName))
+ return Content("");
+
+ return RedirectToRoute(routeName, new { shippingOption });
+ }
+
public virtual async Task<IActionResult> Start()
{
//validation
@@ -466,7 +470,7 @@ namespace Grand.Web.Controllers
return View(model);
}
-
+ [HttpPost]
public virtual async Task<IActionResult> SaveBilling(
[FromServices] AddressSettings addressSettings,
CheckoutBillingAddressModel model)
@@ -563,7 +567,7 @@ namespace Grand.Web.Controllers
return Json(new { error = 1, message = exc.Message });
}
}
-
+ [HttpPost]
public virtual async Task<IActionResult> SaveShipping(
[FromServices] AddressSettings addressSettings,
CheckoutShippingAddressModel model)
@@ -734,7 +738,8 @@ namespace Grand.Web.Controllers
return Json(new { error = 1, message = exc.Message });
}
}
-
+
+ [HttpPost]
public virtual async Task<IActionResult> SaveShippingMethod(CheckoutShippingMethodModel model)
{
try
@@ -818,7 +823,7 @@ namespace Grand.Web.Controllers
return Json(new { error = 1, message = exc.Message });
}
}
-
+ [HttpPost]
public virtual async Task<IActionResult> SavePaymentMethod(CheckoutPaymentMethodModel model)
{
try