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.

Minor changes - ProductDetailsModel add extra field RentalStartDateUtc/RentalEndDateUtc

KrzysztofPajakdab8ebe7ee3d
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
index 87973b5d7..f529325fc 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
@@ -327,7 +327,7 @@ namespace Grand.Web.Features.Handlers.Products
#region Product reservations
- await PrepareProductReservation(model, product);
+ await PrepareProductReservation(model, product, updateCartItem);
#endregion Product reservations
@@ -1000,51 +1000,60 @@ namespace Grand.Web.Features.Handlers.Products
return model;
}
- private async Task PrepareProductReservation(ProductDetailsModel model, Product product)
+ private async Task PrepareProductReservation(ProductDetailsModel model, Product product, ShoppingCartItem updateCartItem)
{
if (product.ProductTypeId == ProductType.Reservation)
{
- model.AddToCart.IsReservation = true;
- var reservations = await _productReservationService.GetProductReservationsByProductId(product.Id, true, null);
- var inCart = _workContext.CurrentCustomer.ShoppingCartItems.Where(x => !string.IsNullOrEmpty(x.ReservationId)).ToList();
- foreach (var cartItem in inCart)
+ if (updateCartItem == null)
{
- var matching = reservations.Where(x => x.Id == cartItem.ReservationId);
- if (matching.Any())
+ model.AddToCart.IsReservation = true;
+ var reservations = await _productReservationService.GetProductReservationsByProductId(product.Id, true, null);
+ var inCart = _workContext.CurrentCustomer.ShoppingCartItems.Where(x => !string.IsNullOrEmpty(x.ReservationId)).ToList();
+ foreach (var cartItem in inCart)
{
- reservations.Remove(matching.First());
+ var matching = reservations.Where(x => x.Id == cartItem.ReservationId);
+ if (matching.Any())
+ {
+ reservations.Remove(matching.First());
+ }
}
- }
- if (reservations.Any())
- {
- var first = reservations.Where(x => x.Date >= DateTime.UtcNow).OrderBy(x => x.Date).FirstOrDefault();
- if (first != null)
+ if (reservations.Any())
{
- model.StartDate = first.Date;
+ var first = reservations.Where(x => x.Date >= DateTime.UtcNow).OrderBy(x => x.Date).FirstOrDefault();
+ if (first != null)
+ {
+ model.StartDate = first.Date;
+ }
+ else
+ {
+ model.StartDate = DateTime.UtcNow;
+ }
}
- else
+
+ model.IntervalUnit = product.IntervalUnitId;
+ model.Interval = product.Interval;
+ model.IncBothDate = product.IncBothDate;
+
+ var list = reservations.GroupBy(x => x.Parameter).ToList().Select(x => x.Key);
+ foreach (var item in list)
{
- model.StartDate = DateTime.UtcNow;
+ if (!string.IsNullOrEmpty(item))
+ {
+ model.Parameters.Add(new SelectListItem { Text = item, Value = item });
+ }
}
- }
- model.IntervalUnit = product.IntervalUnitId;
- model.Interval = product.Interval;
- model.IncBothDate = product.IncBothDate;
-
- var list = reservations.GroupBy(x => x.Parameter).ToList().Select(x => x.Key);
- foreach (var item in list)
- {
- if (!string.IsNullOrEmpty(item))
+ if (model.Parameters.Any())
{
- model.Parameters.Add(new SelectListItem { Text = item, Value = item });
+ model.Parameters.Insert(0, new SelectListItem { Text = "", Value = "" });
}
}
-
- if (model.Parameters.Any())
+ else
{
- model.Parameters.Insert(0, new SelectListItem { Text = "", Value = "" });
+ model.RentalStartDateUtc = updateCartItem.RentalStartDateUtc;
+ model.RentalStartDateUtc = updateCartItem.RentalEndDateUtc;
+ model.RentalReservationId = updateCartItem.ReservationId;
}
}
}
diff --git a/src/Web/Grand.Web/Models/Catalog/ProductDetailsModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductDetailsModel.cs
index 377ee32f1..d2df41ba9 100644
--- a/src/Web/Grand.Web/Models/Catalog/ProductDetailsModel.cs
+++ b/src/Web/Grand.Web/Models/Catalog/ProductDetailsModel.cs
@@ -72,7 +72,9 @@ namespace Grand.Web.Models.Catalog
public bool IncBothDate { get; set; }
public List<SelectListItem> Parameters { get; set; }
public DateTime StartDate { get; set; }
-
+ public DateTime? RentalStartDateUtc { get; set; }
+ public DateTime? RentalEndDateUtc { get; set; }
+ public string RentalReservationId { get; set; }
public string StockAvailability { get; set; }
public bool DisplayOutOfStockSubscription { get; set; }
public bool EmailAFriendEnabled { get; set; }