diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js index c7f92a38..165df751 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js @@ -15,7 +15,8 @@ var $this = $(this); var productId = $this.attr('data-product-id'); eShopOnAbp.basketService.basket.addProduct({ - productId: productId + productId: productId, + anonymousId: anonymousId, }).then(function () { widgetManager.refresh(); abp.notify.success("Added product to your basket.", "Successfully added"); diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js index ec6cf88e..de10ce04 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js @@ -35,7 +35,7 @@ eShopOnAbp.basketService.basket.removeProduct = function(input, ajaxParams) { return abp.ajax($.extend(true, { - url: abp.appPath + 'api/basket/basket/product' + abp.utils.buildQueryString([{ name: 'productId', value: input.productId }, { name: 'count', value: input.count }]) + '', + url: abp.appPath + 'api/basket/basket/product' + abp.utils.buildQueryString([{ name: 'productId', value: input.productId }, { name: 'count', value: input.count }, { name: 'anonymousId', value: input.anonymousId }]) + '', type: 'DELETE' }, ajaxParams)); }; diff --git a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs index 890bb338..f569c44e 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs @@ -3,10 +3,12 @@ using System.ComponentModel.DataAnnotations; namespace EShopOnAbp.BasketService; -public class AddProductDto +public class AddProductDto : IHasAnonymousId { public Guid ProductId { get; set; } [Range(1, int.MaxValue)] public int Count { get; set; } = 1; + + public Guid? AnonymousId { get; set; } } \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IHasAnonymousId.cs b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IHasAnonymousId.cs new file mode 100644 index 00000000..64c27687 --- /dev/null +++ b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IHasAnonymousId.cs @@ -0,0 +1,9 @@ +using System; + +namespace EShopOnAbp.BasketService +{ + public interface IHasAnonymousId + { + Guid? AnonymousId { get; } + } +} diff --git a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs index b1b2ba2f..e8cf0a2f 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs @@ -2,9 +2,11 @@ using System; namespace EShopOnAbp.BasketService; -public class RemoveProductDto +public class RemoveProductDto : IHasAnonymousId { public Guid ProductId { get; set; } public int? Count { get; set; } + + public Guid? AnonymousId { get; set; } } \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs index c404ccb6..2aab9990 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs @@ -42,7 +42,9 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService public async Task AddProductAsync(AddProductDto input) { - Guid userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : _anonymousUserId; + Console.WriteLine("========================= AnonymousId: "+input.AnonymousId); + + Guid userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : input.AnonymousId.GetValueOrDefault(); var basket = await _basketRepository.GetAsync(userId); var product = await _basketProductService.GetAsync(input.ProductId); @@ -61,7 +63,9 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService public async Task RemoveProductAsync(RemoveProductDto input) { - var basket = await _basketRepository.GetAsync(CurrentUser.GetId()); + Guid userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : input.AnonymousId.GetValueOrDefault(); + + var basket = await _basketRepository.GetAsync(userId); var product = await _basketProductService.GetAsync(input.ProductId); basket.RemoveProduct(product.Id, input.Count); diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json index 0ff4ec2a..34f02bdc 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json @@ -152,6 +152,18 @@ "constraintTypes": null, "bindingSourceId": "ModelBinding", "descriptorName": "input" + }, + { + "nameOnMethod": "input", + "name": "AnonymousId", + "jsonName": null, + "type": "System.Guid?", + "typeSimple": "string?", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" } ], "returnValue": {