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 fix wishlist - add to cart from shared wishlist

KrzysztofPajak3bf92444030b
diff --git a/src/Web/Grand.Web/Controllers/WishlistController.cs b/src/Web/Grand.Web/Controllers/WishlistController.cs
index bfbfb5093..aca3f321e 100644
--- a/src/Web/Grand.Web/Controllers/WishlistController.cs
+++ b/src/Web/Grand.Web/Controllers/WishlistController.cs
@@ -86,7 +86,7 @@ namespace Grand.Web.Controllers
var model = await _mediator.Send(new GetWishlist() {
Cart = cart.ToList(),
- Customer = _workContext.CurrentCustomer,
+ Customer = customer,
Language = _workContext.WorkingLanguage,
Currency = _workContext.WorkingCurrency,
Store = _workContext.CurrentStore,
@@ -140,17 +140,21 @@ namespace Grand.Web.Controllers
}
[HttpPost]
- public virtual async Task<IActionResult> AddItemToCartFromWishlist(string shoppingcartId)
+ public virtual async Task<IActionResult> AddItemToCartFromWishlist(Guid? customerGuid, string shoppingcartId)
{
if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
return Json(new { success = false, message = "No permission" });
-
if (!await _permissionService.Authorize(StandardPermission.EnableWishlist))
return Json(new { success = false, message = "No permission" });
+ var pageCustomer = customerGuid.HasValue
+ ? await _customerService.GetCustomerByGuid(customerGuid.Value)
+ : _workContext.CurrentCustomer;
+ if (pageCustomer == null)
+ return Json(new { success = false, message = "Customer not found" });
- var itemCart = _workContext.CurrentCustomer.ShoppingCartItems
+ var itemCart = pageCustomer.ShoppingCartItems
.FirstOrDefault(sci => sci.ShoppingCartTypeId == ShoppingCartType.Wishlist && sci.Id == shoppingcartId);
if (itemCart == null)
diff --git a/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml b/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml
index 88febe94b..2609ed463 100644
--- a/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml
+++ b/src/Web/Grand.Web/Views/Wishlist/_ModelScript.cshtml
@@ -1,4 +1,7 @@
@model WishlistModel
+@{
+ var addToCartUrl = Model.EmailWishlistEnabled && !Model.IsEditable ? Url.RouteUrl("AddItemToCartFromWishlist", new { customerGuid = @Model.CustomerGuid }) + "&shoppingcartId=" : Url.RouteUrl("AddItemToCartFromWishlist") + "?shoppingcartId=";
+}
<script asp-location="Header">
var Wishlist = Vue.extend({
props: {
@@ -11,7 +14,7 @@
methods: {
deleteFromWishlist(id) {
axios({
- url: '@Url.RouteUrl("DeleteItemFromWishlist")'+'/'+ id +'',
+ url: '@Url.RouteUrl("DeleteItemFromWishlist")'+'/'+ id,
method: 'post',
headers: { 'Content-Type': 'application/json' }
}).then(function (response) {
@@ -24,7 +27,7 @@
},
addToCartFromWishlist(id) {
axios({
- url: '@Url.RouteUrl("AddItemToCartFromWishlist")'+'/' + id,
+ url: '@Html.Raw(addToCartUrl)' + id,
method: 'post',
headers: { 'Content-Type': 'application/json' }
}).then(function (response) {