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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Changes with ActionCartController.cs
support91c0eaebbb0d
diff --git a/src/Web/Grand.Web/Controllers/ActionCartController.cs b/src/Web/Grand.Web/Controllers/ActionCartController.csindex c30a40afa..88c5c9343 100644--- a/src/Web/Grand.Web/Controllers/ActionCartController.cs+++ b/src/Web/Grand.Web/Controllers/ActionCartController.cs@@ -13,7 +13,6 @@ using Grand.Web.Common.Filters;using Grand.Web.Extensions;using Grand.Web.Features.Models.Products;using Grand.Web.Features.Models.ShoppingCart;-using Grand.Web.Models.Catalog;using Grand.Web.Models.ShoppingCart;using MediatR;using Microsoft.AspNetCore.Mvc;@@ -36,7 +35,6 @@ namespace Grand.Web.Controllersprivate readonly IShoppingCartValidator _shoppingCartValidator;private readonly ICustomerActivityService _customerActivityService;private readonly IMediator _mediator;-private readonly ShoppingCartSettings _shoppingCartSettings;#endregion@@ -68,9 +66,9 @@ namespace Grand.Web.Controllers#endregion- #region Methods+ #region Private methods- protected IActionResult RedirectToProduct(Product product, ShoppingCartType cartType, int quantity)+ private IActionResult RedirectToProduct(Product product, ShoppingCartType cartType, int quantity){//we can't add grouped productsif (product.ProductTypeId == ProductType.GroupedProduct)@@ -121,19 +119,74 @@ namespace Grand.Web.Controllersreturn null;}- protected string GetWarehouse(Product product)+ private string GetWarehouse(Product product){return product.UseMultipleWarehouses ? _workContext.CurrentStore.DefaultWarehouseId :string.IsNullOrEmpty(_workContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId : _workContext.CurrentStore.DefaultWarehouseId;}+ private IActionResult ReturnFailMessage(Product product, ShoppingCartType shoppingCartTypeId)+ {+ //you can't add group products+ if (product.ProductTypeId == ProductType.GroupedProduct)+ {+ return Json(new+ {+ success = false,+ message = "Grouped products couldn't be added to the cart"+ });+ }++ //you can't add reservation product to wishlist+ if (product.ProductTypeId == ProductType.Reservation && shoppingCartTypeId == ShoppingCartType.Wishlist)+ {+ return Json(new+ {+ success = false,+ message = "Reservation products couldn't be added to the wishlist"+ });+ }++ //you can't add auction product to wishlist+ if (product.ProductTypeId == ProductType.Auction && shoppingCartTypeId == ShoppingCartType.Wishlist)+ {+ return Json(new+ {+ success = false,+ message = "Auction products couldn't be added to the wishlist"+ });+ }+ //check available date+ if (product.AvailableEndDateTimeUtc.HasValue && product.AvailableEndDateTimeUtc.Value < DateTime.UtcNow)+ {+ return Json(new+ {+ success = false,+ message = _translationService.GetResource("ShoppingCart.NotAvailable")+ });+ }++ return null;+ }++ private async Task<double?> GetCustomerEnteredPrice(ProductDetailsCart model)+ {+ double? customerEnteredPriceConverted = null;+ if (double.TryParse(model.CustomerEnteredPrice, out var customerEnteredPrice))+ customerEnteredPriceConverted = await _currencyService.ConvertToPrimaryStoreCurrency(customerEnteredPrice, _workContext.WorkingCurrency);++ return customerEnteredPriceConverted;+ }+ #endregion++ #region Public methods+[HttpPost]- public virtual async Task<IActionResult> AddProductCatalog(string productId, int shoppingCartTypeId,- int quantity, bool forceredirection = false)+ public virtual async Task<IActionResult> AddProductCatalog(ProductCatalogCart model){- var cartType = (ShoppingCartType)shoppingCartTypeId;+ var cartType = (ShoppingCartType)model.ShoppingCartTypeId;- var product = await _productService.GetProductById(productId);+ var product = await _productService.GetProductById(model.ProductId);if (product == null)//no product foundreturn Json(new@@ -142,7 +195,7 @@ namespace Grand.Web.Controllersmessage = "No product found with the specified ID"});- var redirect = RedirectToProduct(product, cartType, quantity);+ var redirect = RedirectToProduct(product, cartType, model.Quantity);if (redirect != null)return redirect;@@ -157,7 +210,7 @@ namespace Grand.Web.Controllersvar shoppingCartItem = await _shoppingCartService.FindShoppingCartItem(cart, cartType, product.Id, warehouseId);//if we already have the same product in the cart, then use the total quantity to validate- var quantityToValidate = shoppingCartItem?.Quantity + quantity ?? quantity;+ var quantityToValidate = shoppingCartItem?.Quantity + model.Quantity ?? model.Quantity;var addToCartWarnings = await _shoppingCartValidator.GetShoppingCartItemWarnings(customer, new ShoppingCartItem {ShoppingCartTypeId = cartType,@@ -180,11 +233,11 @@ namespace Grand.Web.Controllers//try adding product to the cartvar addToCart = await _shoppingCartService.AddToCart(customer: customer,- productId: productId,+ productId: product.Id,shoppingCartType: cartType,storeId: _workContext.CurrentStore.Id,warehouseId: warehouseId,- quantity: quantity,+ quantity: model.Quantity,validator: new ShoppingCartValidatorOptions {GetRequiredProductWarnings = false,GetInventoryWarnings = cartType == ShoppingCartType.ShoppingCart || !_shoppingCartSettings.AllowOutOfStockItemsToBeAddedToWishlist,@@ -205,7 +258,7 @@ namespace Grand.Web.ControllersProduct = product,Customer = customer,ShoppingCartItem = addToCart.shoppingCartItem,- Quantity = quantity,+ Quantity = model.Quantity,CartType = cartType,Currency = _workContext.WorkingCurrency,Store = _workContext.CurrentStore,@@ -223,7 +276,7 @@ namespace Grand.Web.Controllers_workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(),_translationService.GetResource("ActivityLog.PublicStore.AddToWishlist"), product.Name);- if (_shoppingCartSettings.DisplayWishlistAfterAddingProduct || forceredirection)+ if (_shoppingCartSettings.DisplayWishlistAfterAddingProduct || model.ForceRedirection){//redirect to the wishlist pagereturn Json(new@@ -253,7 +306,7 @@ namespace Grand.Web.Controllers_workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(),_translationService.GetResource("ActivityLog.PublicStore.AddToShoppingCart"), product.Name);- if (_shoppingCartSettings.DisplayCartAfterAddingProduct || forceredirection)+ if (_shoppingCartSettings.DisplayCartAfterAddingProduct || model.ForceRedirection){//redirect to the shopping cart pagereturn Json(new@@ -294,63 +347,10 @@ namespace Grand.Web.Controllers}}- protected IActionResult ReturnFailMessage(Product product, ShoppingCartType shoppingCartTypeId)- {- //you can't add group products- if (product.ProductTypeId == ProductType.GroupedProduct)- {- return Json(new- {- success = false,- message = "Grouped products couldn't be added to the cart"- });- }-- //you can't add reservation product to wishlist- if (product.ProductTypeId == ProductType.Reservation && shoppingCartTypeId == ShoppingCartType.Wishlist)- {- return Json(new- {- success = false,- message = "Reservation products couldn't be added to the wishlist"- });- }-- //you can't add auction product to wishlist- if (product.ProductTypeId == ProductType.Auction && shoppingCartTypeId == ShoppingCartType.Wishlist)- {- return Json(new- {- success = false,- message = "Auction products couldn't be added to the wishlist"- });- }- //check available date- if (product.AvailableEndDateTimeUtc.HasValue && product.AvailableEndDateTimeUtc.Value < DateTime.UtcNow)- {- return Json(new- {- success = false,- message = _translationService.GetResource("ShoppingCart.NotAvailable")- });- }-- return null;- }-- private async Task<double?> GetCustomerEnteredPrice(ProductModel model)- {- double? customerEnteredPriceConverted = null;- if (double.TryParse(model.CustomerEnteredPrice, out var customerEnteredPrice))- customerEnteredPriceConverted = await _currencyService.ConvertToPrimaryStoreCurrency(customerEnteredPrice, _workContext.WorkingCurrency);-- return customerEnteredPriceConverted;- }[HttpPost]- public virtual async Task<IActionResult> AddProductDetails(string productId, int shoppingCartTypeId,- ProductModel model)+ public virtual async Task<IActionResult> AddProductDetails(ProductDetailsCart model){- var product = await _productService.GetProductById(productId);+ var product = await _productService.GetProductById(model.ProductId);if (product == null){return Json(new@@ -359,7 +359,7 @@ namespace Grand.Web.Controllers});}- var message = ReturnFailMessage(product, (ShoppingCartType)shoppingCartTypeId);+ var message = ReturnFailMessage(product, (ShoppingCartType)model.ShoppingCartTypeId);if (message != null)return message;@@ -368,16 +368,24 @@ namespace Grand.Web.Controllers{customerEnteredPriceConverted = await GetCustomerEnteredPrice(model);}-- //product and gift voucher attributes- var attributes = await _mediator.Send(new GetParseProductAttributes { Product = product, Model = model });-+ //product attributes+ var attributes = await _mediator.Send(new GetParseProductAttributes { Product = product, Attributes = model.Attributes });+ //gift voucher+ if (product.IsGiftVoucher)+ {+ attributes = GiftVoucherExtensions.AddGiftVoucherAttribute(attributes,+ model.RecipientName,+ model.RecipientEmail,+ model.SenderName,+ model.SenderEmail,+ model.Message).ToList();+ }//rental attributesDateTime? rentalStartDate = null;DateTime? rentalEndDate = null;if (product.ProductTypeId == ProductType.Reservation){- product.ParseReservationDates(model, out rentalStartDate, out rentalEndDate);+ product.ParseReservationDates(model.ReservationDatepickerFrom, model.ReservationDatepickerTo, out rentalStartDate, out rentalEndDate);}//product reservation@@ -427,7 +435,7 @@ namespace Grand.Web.Controllers}}- var cartType = (ShoppingCartType)shoppingCartTypeId;+ var cartType = (ShoppingCartType)model.ShoppingCartTypeId;//save itemvar addToCartWarnings = new List<string>();@@ -439,7 +447,7 @@ namespace Grand.Web.Controllers//add to the cartvar (warnings, shoppingCartItem) = await _shoppingCartService.AddToCart(_workContext.CurrentCustomer,- productId, cartType, _workContext.CurrentStore.Id, warehouseId,+ product.Id, cartType, _workContext.CurrentStore.Id, warehouseId,attributes, customerEnteredPriceConverted,rentalStartDate, rentalEndDate, model.EnteredQuantity, true, model.Reservation, parameter, duration,new ShoppingCartValidatorOptions {@@ -566,167 +574,10 @@ namespace Grand.Web.Controllers#endregion}- [HttpPost]- public virtual async Task<IActionResult> AddBid(AddBidModel model,- [FromServices] IAuctionService auctionService)- {- var customer = _workContext.CurrentCustomer;- if (!await _groupService.IsRegistered(customer))- {- return Json(new- {- success = false,- message = _translationService.GetResource("ShoppingCart.Mustberegisteredtobid")- });- }- double.TryParse(model.HighestBidValue, out var bid);- if (bid == 0)- double.TryParse(model.HighestBidValue, NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out bid);-- bid = Math.Round(bid, 2);-- if (bid <= 0)- {- return Json(new- {- success = false,- message = _translationService.GetResource("ShoppingCart.BidMustBeHigher")- });- }-- var product = await _productService.GetProductById(model.ProductId);- if (product == null)- throw new ArgumentNullException(nameof(product));-- if (product.HighestBidder == customer.Id)- {- return Json(new- {- success = false,- message = _translationService.GetResource("ShoppingCart.AlreadyHighestBidder")- });- }-- var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? model.WarehouseId : _workContext.CurrentStore.DefaultWarehouseId;-- var shoppingCartItem = new ShoppingCartItem {- Attributes = new List<CustomAttribute>(),- CreatedOnUtc = DateTime.UtcNow,- ProductId = product.Id,- WarehouseId = warehouseId,- ShoppingCartTypeId = ShoppingCartType.Auctions,- StoreId = _workContext.CurrentStore.Id,- EnteredPrice = bid,- Quantity = 1- };-- var warnings = (await _shoppingCartValidator.GetStandardWarnings(customer, product, shoppingCartItem)).ToList();- warnings.AddRange(await _shoppingCartValidator.GetAuctionProductWarning(bid, product, customer));-- if (warnings.Any())- {- var toReturn = "";- foreach (var warning in warnings)- {- toReturn += warning + "</br>";- }-- return Json(new- {- success = false,- message = toReturn- });- }-- //insert new bid- await auctionService.NewBid(customer, product, _workContext.CurrentStore, _workContext.WorkingLanguage, warehouseId, bid);-- //activity log- _ = _customerActivityService.InsertActivity("PublicStore.AddNewBid", product.Id,- _workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(),- _translationService.GetResource("ActivityLog.PublicStore.AddToBid"), product.Name);-- var addtoCartModel = await _mediator.Send(new GetAddToCart {- Product = product,- Customer = customer,- Quantity = 1,- CartType = ShoppingCartType.Auctions,- Currency = _workContext.WorkingCurrency,- Store = _workContext.CurrentStore,- Language = _workContext.WorkingLanguage,- TaxDisplayType = _workContext.TaxDisplayType- });-- return Json(new- {- success = true,- message = _translationService.GetResource("ShoppingCart.Yourbidhasbeenplaced"),- model = addtoCartModel- });- }-- public virtual async Task<IActionResult> GetItemCart(string shoppingcartId)- {- var cart = _workContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == shoppingcartId);- if (cart == null)- return Json(new- {- success = false,- message = "No item cart found with the specified ID"- });-- var product = await _productService.GetProductById(cart.ProductId);- if (product == null)- return Json(new- {- success = false,- message = "No product found with the specified ID"- });--- //availability dates- if (!product.IsAvailable() && product.ProductTypeId != ProductType.Auction)- return Json(new- {- success = false,- message = "No product found with the specified ID"- });-- //visible individually?- if (!product.VisibleIndividually)- {- //is this one an associated products?- var parentGroupedProduct = await _productService.GetProductById(product.ParentGroupedProductId);- if (parentGroupedProduct == null)- {- return Json(new- {- redirect = Url.RouteUrl("HomePage")- });- }- return Json(new- {- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContext.WorkingLanguage.Id) })- });- }-- //prepare the model- var model = await _mediator.Send(new GetProductDetailsPage {- Store = _workContext.CurrentStore,- Product = product,- UpdateCartItem = cart- });-- return Json(new- {- success = true, model- });- }-[HttpPost]- public virtual async Task<IActionResult> UpdateItemCart(string shoppingCartItemId, ProductModel model)+ public virtual async Task<IActionResult> UpdateItemCart(ProductDetailsCart model){- var cart = _workContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == shoppingCartItemId);+ var cart = _workContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == model.ShoppingCartItemId);if (cart == null)return Json(new{@@ -791,15 +642,26 @@ namespace Grand.Web.Controllers}#endregion- //product and gift voucher attributes- var attributes = await _mediator.Send(new GetParseProductAttributes { Product = product, Model = model });-+ //product attributes+ var attributes = await _mediator.Send(new GetParseProductAttributes { Product = product, Attributes = model.Attributes });++ //gift voucher+ if (product.IsGiftVoucher)+ {+ attributes = GiftVoucherExtensions.AddGiftVoucherAttribute(attributes,+ model.RecipientName,+ model.RecipientEmail,+ model.SenderName,+ model.SenderEmail,+ model.Message).ToList();+ }+//rental attributesDateTime? rentalStartDate = cart.RentalStartDateUtc;DateTime? rentalEndDate = cart.RentalEndDateUtc;if (product.ProductTypeId == ProductType.Reservation){- product.ParseReservationDates(model, out rentalStartDate, out rentalEndDate);+ product.ParseReservationDates(model.ReservationDatepickerFrom, model.ReservationDatepickerTo, out rentalStartDate, out rentalEndDate);}//product reservation@@ -870,6 +732,164 @@ namespace Grand.Web.Controllers}+ [HttpGet]+ public virtual async Task<IActionResult> GetItemCart(string shoppingCartId)+ {+ var cart = _workContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == shoppingCartId);+ if (cart == null)+ return Json(new+ {+ success = false,+ message = "No item cart found with the specified ID"+ });++ var product = await _productService.GetProductById(cart.ProductId);+ if (product == null)+ return Json(new+ {+ success = false,+ message = "No product found with the specified ID"+ });+++ //availability dates+ if (!product.IsAvailable() && product.ProductTypeId != ProductType.Auction)+ return Json(new+ {+ success = false,+ message = "No product found with the specified ID"+ });++ //visible individually?+ if (!product.VisibleIndividually)+ {+ //is this one an associated products?+ var parentGroupedProduct = await _productService.GetProductById(product.ParentGroupedProductId);+ if (parentGroupedProduct == null)+ {+ return Json(new+ {+ redirect = Url.RouteUrl("HomePage")+ });+ }+ return Json(new+ {+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContext.WorkingLanguage.Id) })+ });+ }++ //prepare the model+ var model = await _mediator.Send(new GetProductDetailsPage {+ Store = _workContext.CurrentStore,+ Product = product,+ UpdateCartItem = cart+ });++ return Json(new+ {+ success = true, model+ });+ }++ [HttpPost]+ public virtual async Task<IActionResult> AddBid(AddBidModel model,+ [FromServices] IAuctionService auctionService)+ {+ var customer = _workContext.CurrentCustomer;+ if (!await _groupService.IsRegistered(customer))+ {+ return Json(new+ {+ success = false,+ message = _translationService.GetResource("ShoppingCart.Mustberegisteredtobid")+ });+ }+ double.TryParse(model.HighestBidValue, out var bid);+ if (bid == 0)+ double.TryParse(model.HighestBidValue, NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out bid);++ bid = Math.Round(bid, 2);++ if (bid <= 0)+ {+ return Json(new+ {+ success = false,+ message = _translationService.GetResource("ShoppingCart.BidMustBeHigher")+ });+ }++ var product = await _productService.GetProductById(model.ProductId);+ if (product == null)+ throw new ArgumentNullException(nameof(product));++ if (product.HighestBidder == customer.Id)+ {+ return Json(new+ {+ success = false,+ message = _translationService.GetResource("ShoppingCart.AlreadyHighestBidder")+ });+ }++ var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? model.WarehouseId : _workContext.CurrentStore.DefaultWarehouseId;++ var shoppingCartItem = new ShoppingCartItem {+ Attributes = new List<CustomAttribute>(),+ CreatedOnUtc = DateTime.UtcNow,+ ProductId = product.Id,+ WarehouseId = warehouseId,+ ShoppingCartTypeId = ShoppingCartType.Auctions,+ StoreId = _workContext.CurrentStore.Id,+ EnteredPrice = bid,+ Quantity = 1+ };++ var warnings = (await _shoppingCartValidator.GetStandardWarnings(customer, product, shoppingCartItem)).ToList();+ warnings.AddRange(await _shoppingCartValidator.GetAuctionProductWarning(bid, product, customer));++ if (warnings.Any())+ {+ var toReturn = "";+ foreach (var warning in warnings)+ {+ toReturn += warning + "</br>";+ }++ return Json(new+ {+ success = false,+ message = toReturn+ });+ }++ //insert new bid+ await auctionService.NewBid(customer, product, _workContext.CurrentStore, _workContext.WorkingLanguage, warehouseId, bid);++ //activity log+ _ = _customerActivityService.InsertActivity("PublicStore.AddNewBid", product.Id,+ _workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(),+ _translationService.GetResource("ActivityLog.PublicStore.AddToBid"), product.Name);++ var addtoCartModel = await _mediator.Send(new GetAddToCart {+ Product = product,+ Customer = customer,+ Quantity = 1,+ CartType = ShoppingCartType.Auctions,+ Currency = _workContext.WorkingCurrency,+ Store = _workContext.CurrentStore,+ Language = _workContext.WorkingLanguage,+ TaxDisplayType = _workContext.TaxDisplayType+ });++ return Json(new+ {+ success = true,+ message = _translationService.GetResource("ShoppingCart.Yourbidhasbeenplaced"),+ model = addtoCartModel+ });+ }+#endregion}diff --git a/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs b/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.csindex 9f6fc0253..11f425142 100644--- a/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs+++ b/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs@@ -156,7 +156,7 @@ namespace Grand.Web.Controllersresource = _translationService.GetResource("OutOfStockSubscriptions.NotAllowed")});- var attributes = await _mediator.Send(new GetParseProductAttributes { Product = product, Model = model });+ var attributes = await _mediator.Send(new GetParseProductAttributes { Product = product, Attributes = model.Attributes });var subscriptionAttributes = await _outOfStockSubscriptionService.FindSubscription(customer.Id, product.Id, attributes, _workContext.CurrentStore.Id, warehouseId);diff --git a/src/Web/Grand.Web/Extensions/MappingExtensions.cs b/src/Web/Grand.Web/Extensions/MappingExtensions.csindex 7241a4e0f..39798c34e 100644--- a/src/Web/Grand.Web/Extensions/MappingExtensions.cs+++ b/src/Web/Grand.Web/Extensions/MappingExtensions.cs@@ -248,7 +248,7 @@ namespace Grand.Web.Extensionsreturn destination;}- public static void ParseReservationDates(this Product product, ProductModel model,+ public static void ParseReservationDates(this Product product, string reservationDatepickerFrom,string reservationDatepickerTo,out DateTime? startDate, out DateTime? endDate){startDate = null;@@ -258,8 +258,8 @@ namespace Grand.Web.Extensions{//currently we support only this format (as in the \Views\Product\_RentalInfo.cshtml file)const string datePickerFormat = "MM/dd/yyyy";- startDate = DateTime.ParseExact(model.ReservationDatepickerFrom, datePickerFormat, CultureInfo.InvariantCulture);- endDate = DateTime.ParseExact(model.ReservationDatepickerTo, datePickerFormat, CultureInfo.InvariantCulture);+ startDate = DateTime.ParseExact(reservationDatepickerFrom, datePickerFormat, CultureInfo.InvariantCulture);+ endDate = DateTime.ParseExact(reservationDatepickerTo, datePickerFormat, CultureInfo.InvariantCulture);}catch{diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsAttributeChangeHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsAttributeChangeHandler.csindex 1c3cb8d27..8098e7b65 100644--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsAttributeChangeHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsAttributeChangeHandler.cs@@ -65,7 +65,7 @@ namespace Grand.Web.Features.Handlers.Productsvar model = new ProductDetailsAttributeChangeModel();var customAttributes =- await _mediator.Send(new GetParseProductAttributes { Product = request.Product, Model = request.Model },+ await _mediator.Send(new GetParseProductAttributes { Product = request.Product, Attributes = request.Model.Attributes },cancellationToken);var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? request.Model.WarehouseId :@@ -78,7 +78,7 @@ namespace Grand.Web.Features.Handlers.ProductsDateTime? rentalEndDate = null;if (request.Product.ProductTypeId == ProductType.Reservation){- request.Product.ParseReservationDates(request.Model, out rentalStartDate, out rentalEndDate);+ request.Product.ParseReservationDates(request.Model.ReservationDatepickerFrom, request.Model.ReservationDatepickerTo, out rentalStartDate, out rentalEndDate);}model.Sku = request.Product.FormatSku(customAttributes);diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetParseProductAttributesHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetParseProductAttributesHandler.csindex c3dee651a..438ce2111 100644--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetParseProductAttributesHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetParseProductAttributesHandler.cs@@ -47,7 +47,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartcase AttributeControlType.ColorSquares:case AttributeControlType.ImageSquares:{- var ctrlAttributes = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ var ctrlAttributes = request.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){customAttributes = ProductExtensions.AddProductAttribute(customAttributes,@@ -57,7 +57,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartbreak;case AttributeControlType.Checkboxes:{- var cblAttributes = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ var cblAttributes = request.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(cblAttributes)){foreach (var item in cblAttributes.Split(','))@@ -87,7 +87,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartcase AttributeControlType.MultilineTextbox:case AttributeControlType.Datepicker:{- var ctrlAttributes = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ var ctrlAttributes = request.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){var enteredText = ctrlAttributes.Trim();@@ -98,7 +98,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartbreak;case AttributeControlType.FileUpload:{- var guid = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ var guid = request.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;Guid.TryParse(guid, out Guid downloadGuid);var download = await _downloadService.GetDownloadByGuid(downloadGuid);if (download != null)@@ -119,19 +119,6 @@ namespace Grand.Web.Features.Handlers.ShoppingCartcustomAttributes = ProductExtensions.RemoveProductAttribute(customAttributes, attribute).ToList();}}- #endregion- #region Gift vouchers-- if (request.Product.IsGiftVoucher)- {- customAttributes = GiftVoucherExtensions.AddGiftVoucherAttribute(customAttributes,- request.Model.RecipientName,- request.Model.RecipientEmail,- request.Model.SenderName,- request.Model.SenderEmail,- request.Model.Message).ToList();- }-#endregionreturn customAttributes;diff --git a/src/Web/Grand.Web/Features/Models/ShoppingCart/GetParseProductAttributes.cs b/src/Web/Grand.Web/Features/Models/ShoppingCart/GetParseProductAttributes.csindex 31be39ca8..47ed9e7dc 100644--- a/src/Web/Grand.Web/Features/Models/ShoppingCart/GetParseProductAttributes.cs+++ b/src/Web/Grand.Web/Features/Models/ShoppingCart/GetParseProductAttributes.cs@@ -1,6 +1,6 @@using Grand.Domain.Catalog;using Grand.Domain.Common;-using Grand.Web.Models.Catalog;+using Grand.Web.Common.Models;using MediatR;namespace Grand.Web.Features.Models.ShoppingCart@@ -8,6 +8,6 @@ namespace Grand.Web.Features.Models.ShoppingCartpublic class GetParseProductAttributes : IRequest<IList<CustomAttribute>>{public Product Product { get; set; }- public ProductModel Model { get; set; }+ public IList<CustomAttributeModel> Attributes { get; set; }}}diff --git a/src/Web/Grand.Web/Models/Catalog/ProductModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductModel.csindex fd647e966..019b32135 100644--- a/src/Web/Grand.Web/Models/Catalog/ProductModel.cs+++ b/src/Web/Grand.Web/Models/Catalog/ProductModel.cs@@ -10,15 +10,7 @@ public class ProductModelpublic string WarehouseId { get; set; }public string ReservationDatepickerFrom { get; set; }public string ReservationDatepickerTo { get; set; }- public string RecipientName{ get; set; }- public string RecipientEmail{ get; set; }- public string SenderName{ get; set; }- public string SenderEmail{ get; set; }- public string Message{ get; set; }-+[ModelBinder(BinderType = typeof(CustomAttributesBinder))]public IList<CustomAttributeModel> Attributes { get; set; }- public string Reservation { get; set; }- public string CustomerEnteredPrice { get; set; }- public int EnteredQuantity { get; set; }}\ No newline at end of filediff --git a/src/Web/Grand.Web/Models/ShoppingCart/ProductCatalogCart.cs b/src/Web/Grand.Web/Models/ShoppingCart/ProductCatalogCart.csnew file mode 100644index 000000000..d6fc6c530--- /dev/null+++ b/src/Web/Grand.Web/Models/ShoppingCart/ProductCatalogCart.cs@@ -0,0 +1,9 @@+namespace Grand.Web.Models.ShoppingCart;++public class ProductCatalogCart+{+ public string ProductId { get; set; }+ public int ShoppingCartTypeId { get; set; }+ public int Quantity { get; set; }+ public bool ForceRedirection { get; set; }+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Models/ShoppingCart/ProductDetailsCart.cs b/src/Web/Grand.Web/Models/ShoppingCart/ProductDetailsCart.csnew file mode 100644index 000000000..c11383437--- /dev/null+++ b/src/Web/Grand.Web/Models/ShoppingCart/ProductDetailsCart.cs@@ -0,0 +1,27 @@+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;+using Microsoft.AspNetCore.Mvc;++namespace Grand.Web.Models.ShoppingCart;++public class ProductDetailsCart+{+ public string ProductId { get; set; }+ public int ShoppingCartTypeId { get; set; }+ public string ShoppingCartItemId { get; set; }+ public string WarehouseId { get; set; }+ public string ReservationDatepickerFrom { get; set; }+ public string ReservationDatepickerTo { get; set; }+ public string RecipientName { get; set; }+ public string RecipientEmail { get; set; }+ public string SenderName { get; set; }+ public string SenderEmail { get; set; }+ public string Message { get; set; }++ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> Attributes { get; set; }++ public string Reservation { get; set; }+ public string CustomerEnteredPrice { get; set; }+ public int EnteredQuantity { get; set; }+}\ No newline at end of file