diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/BasketWidgetViewComponent.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/BasketWidgetViewComponent.cs index 409e5f2a..74898dcb 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/BasketWidgetViewComponent.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/BasketWidgetViewComponent.cs @@ -6,7 +6,12 @@ using EShopOnAbp.BasketService; namespace EShopOnAbp.PublicWeb.Components.Basket; -[Widget] +[Widget( + AutoInitialize = true, + RefreshUrl = "/Widgets/Basket", + StyleFiles = new[] { "/components/basket-widget.css" }, + ScriptFiles = new[] { "/components/basket-widget.js" } +)] public class BasketWidgetViewComponent : AbpViewComponent { private readonly IBasketAppService _basketAppService; @@ -15,7 +20,7 @@ public class BasketWidgetViewComponent : AbpViewComponent { _basketAppService = basketAppService; } - + public async Task InvokeAsync() { var basketDto = await _basketAppService.GetAsync(); diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/Default.cshtml b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/Default.cshtml index 1253bc8a..69e9b4f7 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/Default.cshtml +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Basket/Default.cshtml @@ -9,7 +9,7 @@
@foreach (var item in Model.Items) { -
+
@if (!item.ImageName.IsNullOrEmpty()) { @@ -24,6 +24,7 @@ (@("x" + item.Count)) } - $@item.TotalPrice.ToString("0.00") +
}
diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Controllers/WidgetsController.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Controllers/WidgetsController.cs new file mode 100644 index 00000000..c3f1098c --- /dev/null +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Controllers/WidgetsController.cs @@ -0,0 +1,16 @@ +using EShopOnAbp.PublicWeb.Components.Basket; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace EShopOnAbp.PublicWeb.Controllers; + +[Route("Widgets")] +public class WidgetsController : AbpController +{ + [HttpGet] + [Route("Basket")] + public IActionResult Counters() + { + return ViewComponent(typeof(BasketWidgetViewComponent)); + } +} \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml index 9d4c3980..927c036f 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml @@ -55,7 +55,7 @@

Your Basket

-
+
@await Component.InvokeAsync(typeof(BasketWidgetViewComponent))
diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml.js b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml.js index adeb9558..fefd8436 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml.js +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.cshtml.js @@ -1,13 +1,17 @@ (function(){ $(function(){ + + var basketWidget = new abp.WidgetManager('#BasketArea'); + $('.product-list-item').click(function(){ var $this = $(this); var productId = $this.attr('data-product-id'); eShopOnAbp.basketService.basket.addProduct({ productId: productId }).then(function(){ + basketWidget.refresh(); abp.notify.success("Added product to your basket.", "Successfully added"); }); }); - }) + }); })(); \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.css b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.css index 88f54acc..a1c374cc 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.css +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Catalog.css @@ -27,38 +27,4 @@ .product-info-box { min-height: 80px; -} - -.basket-list -{ - background-color: #fff; - padding: 1em; - border: 1px solid #666; - border-radius: 3px; - box-shadow: 0 0 10px rgba(0, 0, 0, .05); - margin-bottom: 0.5em; - transition: all .2s; -} - -.basket-list:hover { - box-shadow: 0 0 20px rgba(0, 0, 0, .1); - cursor: pointer; -} - -.basket-list-item { - margin-top: 1em; -} - -.basket-list-item:first-child{ - margin-top: 0; -} - -.basket-list-item img { - height: 1em; -} - -.basket-total-area -{ - margin-bottom: 1em; - font-weight: bold; } \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/basket-widget.css b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/basket-widget.css new file mode 100644 index 00000000..44989ae5 --- /dev/null +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/basket-widget.css @@ -0,0 +1,42 @@ +.basket-list +{ + background-color: #fff; + padding: 1em; + border: 1px solid #666; + border-radius: 3px; + box-shadow: 0 0 10px rgba(0, 0, 0, .05); + margin-bottom: 0.5em; + transition: all .2s; +} + +.basket-list:hover { + box-shadow: 0 0 20px rgba(0, 0, 0, .1); +} + +.basket-list-item { + margin-top: 1em; +} + +.basket-list-item:first-child{ + margin-top: 0; +} + +.basket-list-item img { + height: 1em; +} + +.basket-total-area +{ + margin-bottom: 1em; + font-weight: bold; +} + +.basket-item-remove { + cursor: pointer; + color: red; + opacity: 0.25; +} + +.basket-list-item:hover .basket-item-remove { + opacity: 1.0; +} \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/basket-widget.js b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/basket-widget.js new file mode 100644 index 00000000..b6ad9bcf --- /dev/null +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/basket-widget.js @@ -0,0 +1,25 @@ +(function (){ + abp.widgets.BasketWidget = function ($wrapper) { + var widgetManager = $wrapper.data('abp-widget-manager'); + + var init = function (filters) { + $wrapper + .find('.basket-item-remove') + .click(function(){ + var $this = $(this); + var productId = $this.parent('.basket-list-item').attr('data-product-id'); + eShopOnAbp.basketService.basket.removeProduct({ + productId: productId + }).then(function(){ + widgetManager.refresh(); + abp.notify.info("Removed the product from your basket.", "Removed basket item"); + }); + }); + }; + + return { + init: init + }; + }; + +})(); \ No newline at end of file