Skip to content

Commit f3ce0ea

Browse files
Merge branch 'issue-7907-Allow-to-rename-custom-wishlist-names' into develop
2 parents dfa118c + 793e3b2 commit f3ce0ea

File tree

12 files changed

+170
-8
lines changed

12 files changed

+170
-8
lines changed

src/Libraries/Nop.Core/Http/NopRouteNames.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ public static partial class Ajax
653653
/// </summary>
654654
public const string ADD_WISHLIST = "AddWishlist";
655655

656+
/// <summary>
657+
/// Gets the rename custom wishlist route name
658+
/// </summary>
659+
public const string RENAME_WISHLIST = "RenameWishlist";
660+
656661
/// <summary>
657662
/// Gets the back in stock subscribe send route name
658663
/// </summary>

src/Libraries/Nop.Services/Orders/CustomWishlistService.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public virtual async Task<IList<CustomWishlist>> GetAllCustomWishlistsAsync(int
5252
/// <param name="item">The custom wishlist item to add. Cannot be <see langword="null"/>.</param>
5353
public virtual async Task AddCustomWishlistAsync(CustomWishlist item)
5454
{
55-
5655
await _customWishlistRepository.InsertAsync(item);
5756
}
5857

@@ -69,6 +68,20 @@ public virtual async Task RemoveCustomWishlistAsync(int itemId)
6968
}
7069
}
7170

71+
/// <summary>
72+
/// Updates an existing custom wishlist in the data store if it exists.
73+
/// </summary>
74+
/// <param name="item">The custom wishlist to update. The wishlist must have a valid identifier corresponding to an existing entry.</param>
75+
/// <returns>A task that represents the asynchronous update operation.</returns>
76+
public virtual async Task UpdateCustomWishlistAsync(CustomWishlist item)
77+
{
78+
var customWishlist = await _customWishlistRepository.GetByIdAsync(item.Id);
79+
if (customWishlist != null)
80+
{
81+
await _customWishlistRepository.UpdateAsync(item);
82+
}
83+
}
84+
7285
/// <summary>
7386
/// Retrieves a custom wishlist by its unique identifier.
7487
/// </summary>

src/Libraries/Nop.Services/Orders/ICustomWishlistService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public partial interface ICustomWishlistService
2828
/// <param name="itemId">The unique identifier of the custom wishlist item to remove. Must be a valid identifier of an existing item.</param>
2929
Task RemoveCustomWishlistAsync(int itemId);
3030

31+
/// <summary>
32+
/// Updates an existing custom wishlist in the data store if it exists.
33+
/// </summary>
34+
/// <param name="item">The custom wishlist to update. The wishlist must have a valid identifier corresponding to an existing entry.</param>
35+
/// <returns>A task that represents the asynchronous update operation.</returns>
36+
Task UpdateCustomWishlistAsync(CustomWishlist item);
37+
3138
/// <summary>
3239
/// Retrieves a custom wishlist by its unique identifier.
3340
/// </summary>

src/Presentation/Nop.Web.Framework/Migrations/UpgradeTo500/LocalizationMigration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public override void Up()
166166

167167
//#7906
168168
["Wishlist.DuplicateName"] = "A wishlist with this name already exists.",
169+
170+
//#7907
171+
["Wishlist.RenameCustomWishlist"] = "Rename wishlist",
169172
});
170173

171174
#endregion

src/Presentation/Nop.Web/App_Data/Localization/defaultResources.nopres.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21059,6 +21059,9 @@
2105921059
<LocaleResource Name="Wishlist.NotFound">
2106021060
<Value>Wishlist not found.</Value>
2106121061
</LocaleResource>
21062+
<LocaleResource Name="Wishlist.RenameCustomWishlist">
21063+
<Value>Rename wishlist</Value>
21064+
</LocaleResource>
2106221065
<LocaleResource Name="Wishlist.SelectWishlist">
2106321066
<Value>Specify your wishlist</Value>
2106421067
</LocaleResource>

src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,18 @@ protected virtual async Task<string> GetGiftCardValidationErrorAsync(IList<Shopp
473473
return string.Empty;
474474
}
475475

476+
protected virtual async Task<string> CheckDuplicateWishlistNameAsync(int customerId, string wishlistName, IList<CustomWishlist> selectedWishlists = null)
477+
{
478+
var currentWishlists = selectedWishlists ?? await _customWishlistService.GetAllCustomWishlistsAsync(customerId);
479+
if (currentWishlists.Any(wishlist => string.Equals(wishlist.Name, wishlistName, StringComparison.InvariantCultureIgnoreCase)))
480+
{
481+
var errorMessage = await _localizationService.GetResourceAsync("Wishlist.DuplicateName");
482+
return errorMessage;
483+
}
484+
485+
return string.Empty;
486+
}
487+
476488
#endregion
477489

478490
#region Shopping cart
@@ -1794,17 +1806,18 @@ public virtual async Task<IActionResult> AddWishlist(string name, int productId)
17941806
var normalizedName = name.Trim();
17951807

17961808
// Check if a wishlist with the same name already exists
1797-
if (currentWishlists.Any(wishlist => string.Equals(wishlist.Name, normalizedName, StringComparison.InvariantCultureIgnoreCase)))
1809+
var errorMessage = await CheckDuplicateWishlistNameAsync(customer.Id, normalizedName, currentWishlists);
1810+
if (!string.IsNullOrEmpty(errorMessage))
17981811
{
17991812
return Json(new
18001813
{
18011814
success = false,
1802-
message = await _localizationService.GetResourceAsync("Wishlist.DuplicateName")
1815+
message = errorMessage
18031816
});
18041817
}
18051818

18061819
// Check if customer has reached the maximum number of custom wishlists allowed
1807-
var maximumNumberOfCustomWishlist = _shoppingCartSettings.MaximumNumberOfCustomWishlist;
1820+
var maximumNumberOfCustomWishlist = _shoppingCartSettings.MaximumNumberOfCustomWishlist;
18081821
if (currentWishlists.Count >= maximumNumberOfCustomWishlist)
18091822
{
18101823
return Json(new
@@ -1916,6 +1929,45 @@ public virtual async Task<IActionResult> MoveToCustomWishlist(int shoppingCartIt
19161929
});
19171930
}
19181931

1932+
[HttpPost]
1933+
public virtual async Task<IActionResult> RenameWishlist(string wishlistName, int wishlistId)
1934+
{
1935+
var customer = await _workContext.GetCurrentCustomerAsync();
1936+
var wishlist = await _customWishlistService.GetCustomWishlistByIdAsync(wishlistId);
1937+
1938+
if (wishlist == null || wishlist.CustomerId != customer.Id)
1939+
{
1940+
return Json(new
1941+
{
1942+
success = false,
1943+
message = await _localizationService.GetResourceAsync("Wishlist.NotFound")
1944+
});
1945+
}
1946+
1947+
var normalizedName = wishlistName.Trim();
1948+
1949+
// Check if a wishlist with the same name already exists
1950+
var errorMessage = await CheckDuplicateWishlistNameAsync(customer.Id, normalizedName);
1951+
if (!string.IsNullOrEmpty(errorMessage))
1952+
{
1953+
return Json(new
1954+
{
1955+
success = false,
1956+
message = errorMessage
1957+
});
1958+
}
1959+
1960+
// rename a wishlist
1961+
wishlist.Name = normalizedName;
1962+
await _customWishlistService.UpdateCustomWishlistAsync(wishlist);
1963+
1964+
return Json(new
1965+
{
1966+
success = true,
1967+
redirect = Url.RouteUrl(NopRouteNames.General.WISHLIST, new { list = wishlistId })
1968+
});
1969+
}
1970+
19191971
[HttpPost]
19201972
public virtual async Task<IActionResult> DeleteWishlist(int wishlistId)
19211973
{

src/Presentation/Nop.Web/Infrastructure/RouteProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ public virtual void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
221221
pattern: $"addcustomwishlist",
222222
defaults: new { controller = "ShoppingCart", action = "AddWishlist" });
223223

224+
// rename custom wishlist. (AJAX)
225+
endpointRouteBuilder.MapControllerRoute(name: NopRouteNames.Ajax.RENAME_WISHLIST,
226+
pattern: $"renamecustomwishlist",
227+
defaults: new { controller = "ShoppingCart", action = "RenameWishlist" });
228+
224229
//comparing products (AJAX)
225230
endpointRouteBuilder.MapControllerRoute(name: NopRouteNames.Ajax.ADD_PRODUCT_TO_COMPARE,
226231
pattern: $"compareproducts/add/{{productId:min(0)}}",

src/Presentation/Nop.Web/Themes/DefaultClean/Content/css/styles.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,6 +3432,15 @@ label, label + * {
34323432
background-color: #e1133e;
34333433
}
34343434

3435+
.wishlist-content .rename-wishlist-button {
3436+
background-color: var(--accent-blue-color);
3437+
}
3438+
3439+
.wishlist-content .rename-wishlist-button:hover,
3440+
.wishlist-content .rename-wishlist-button:focus {
3441+
background-color: var(--accent-blue-active-color);
3442+
}
3443+
34353444
.wishlist-page .share-info {
34363445
text-align: center;
34373446
}
@@ -3465,7 +3474,8 @@ label, label + * {
34653474
display: inline-block;
34663475
}
34673476

3468-
.add-wishlist-content .wishlist-add-custom-button {
3477+
.add-wishlist-content .wishlist-add-custom-button,
3478+
.rename-wishlist-content .wishlist-rename-custom-button {
34693479
width: auto;
34703480
min-width: 64px;
34713481
min-height: 36px;
@@ -3480,7 +3490,9 @@ label, label + * {
34803490
}
34813491

34823492
.add-wishlist-content .wishlist-add-custom-button:hover,
3483-
.add-wishlist-content .wishlist-add-custom-button:focus {
3493+
.add-wishlist-content .wishlist-add-custom-button:focus,
3494+
.rename-wishlist-content .wishlist-rename-custom-button:hover,
3495+
.rename-wishlist-content .wishlist-rename-custom-button:focus {
34843496
background-color: var(--accent-blue-active-color);
34853497
}
34863498

src/Presentation/Nop.Web/Themes/DefaultClean/Content/css/styles.rtl.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,15 @@ label, label + * {
34753475
background-color: #e1133e;
34763476
}
34773477

3478+
.wishlist-content .rename-wishlist-button {
3479+
background-color: var(--accent-blue-color);
3480+
}
3481+
3482+
.wishlist-content .rename-wishlist-button:hover,
3483+
.wishlist-content .rename-wishlist-button:focus {
3484+
background-color: var(--accent-blue-active-color);
3485+
}
3486+
34783487
.wishlist-page .share-info {
34793488
text-align: center;
34803489
}
@@ -3508,7 +3517,8 @@ label, label + * {
35083517
display: inline-block;
35093518
}
35103519

3511-
.add-wishlist-content .wishlist-add-custom-button {
3520+
.add-wishlist-content .wishlist-add-custom-button,
3521+
.rename-wishlist-content .wishlist-rename-custom-button {
35123522
width: auto;
35133523
min-width: 64px;
35143524
min-height: 36px;
@@ -3522,7 +3532,9 @@ label, label + * {
35223532
}
35233533

35243534
.add-wishlist-content .wishlist-add-custom-button:hover,
3525-
.add-wishlist-content .wishlist-add-custom-button:focus {
3535+
.add-wishlist-content .wishlist-add-custom-button:focus,
3536+
.rename-wishlist-content .wishlist-rename-custom-button:hover,
3537+
.rename-wishlist-content .wishlist-rename-custom-button:focus {
35263538
background-color: var(--accent-blue-active-color);
35273539
}
35283540

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@model (int id, string name)
2+
3+
<div id="renameWishlistModal_@Model.id" title="@T("Wishlist.RenameCustomWishlist")" style="display:none;">
4+
<div class="rename-wishlist-content">
5+
<input type="text" id="wishlistName_@Model.id" value="@Model.name" placeholder="@T("Wishlist.EnterWishlistName")" />
6+
<button type="button" class="wishlist-rename-custom-button" onclick="renameWishlist(@Model.id)">@T("Common.OK")</button>
7+
</div>
8+
</div>
9+
10+
<script asp-location="Footer">
11+
function showRenameWishlistModal(wishlistId) {
12+
$('#renameWishlistModal_' + wishlistId).dialog();
13+
}
14+
15+
function closeRenameWishlistModal(wishlistId) {
16+
$('#renameWishlistModal_' + wishlistId).dialog('close');
17+
}
18+
19+
function renameWishlist(wishlistId) {
20+
const wishlistName = document.getElementById('wishlistName_' + wishlistId).value;
21+
if (!wishlistName) {
22+
alert('@T("Wishlist.NameRequired")');
23+
return;
24+
}
25+
26+
AjaxCart.renameCustomWishlist('@Url.RouteUrl(NopRouteNames.Ajax.RENAME_WISHLIST)', wishlistName, wishlistId);
27+
$('#renameWishlistModal_' + wishlistId).dialog('close');
28+
}
29+
</script>

0 commit comments

Comments
 (0)