Browse Source

added cart widget

This is not done since it requires CurrentUserId to perform basket requests.
pull/41/head
Galip Tolga Erdem 5 years ago
parent
commit
205e68fa62
  1. 15
      apps/public-web/src/EShopOnAbp.PublicWeb/Components/Toolbar/Cart/CartWidgetScriptContributor.cs
  2. 29
      apps/public-web/src/EShopOnAbp.PublicWeb/Components/Toolbar/Cart/CartWidgetViewComponent.cs
  3. 10
      apps/public-web/src/EShopOnAbp.PublicWeb/Components/Toolbar/Cart/Default.cshtml
  4. 3
      apps/public-web/src/EShopOnAbp.PublicWeb/Menus/EShopOnAbpPublicWebToolbarContributor.cs
  5. 0
      apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/cart/cart-widget.css
  6. 32
      apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/cart/cart-widget.js

15
apps/public-web/src/EShopOnAbp.PublicWeb/Components/Toolbar/Cart/CartWidgetScriptContributor.cs

@ -0,0 +1,15 @@
using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.SignalR;
using Volo.Abp.Modularity;
namespace EShopOnAbp.PublicWeb.Components.Toolbar.Cart;
[DependsOn(typeof(SignalRBrowserScriptContributor))]
public class CartWidgetScriptContributor: BundleContributor
{
public override void ConfigureBundle(BundleConfigurationContext context)
{
context.Files.AddIfNotContains("/components/cart/cart-widget.js");
}
}

29
apps/public-web/src/EShopOnAbp.PublicWeb/Components/Toolbar/Cart/CartWidgetViewComponent.cs

@ -0,0 +1,29 @@
using System.Threading.Tasks;
using EShopOnAbp.BasketService;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
namespace EShopOnAbp.PublicWeb.Components.Toolbar.Cart;
[Widget(
AutoInitialize = true,
RefreshUrl = "/Widgets/Cart",
StyleFiles = new[] {"/components/cart/cart-widget.css"},
ScriptTypes = new[] {typeof(CartWidgetScriptContributor)}
)]
public class CartWidgetViewComponent : AbpViewComponent
{
private readonly IBasketAppService _basketAppService;
public CartWidgetViewComponent(IBasketAppService basketAppService)
{
_basketAppService = basketAppService;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var basketDto = await _basketAppService.GetAsync();
return View("~/Components/Toolbar/Cart/Default.cshtml", basketDto);
}
}

10
apps/public-web/src/EShopOnAbp.PublicWeb/Components/Toolbar/Cart/Default.cshtml

@ -0,0 +1,10 @@
@using EShopOnAbp.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@inject IHtmlLocalizer<EShopOnAbpResource> L
@model EShopOnAbp.BasketService.BasketDto
<div>
<abp-button button-type="Primary">
@L["Toolbar:Basket"] <span abp-badge="Light" data-cart-count-id>@Model.Items.Count</span>
</abp-button>
</div>

3
apps/public-web/src/EShopOnAbp.PublicWeb/Menus/EShopOnAbpPublicWebToolbarContributor.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using EShopOnAbp.PublicWeb.Components.Toolbar.Cart;
using EShopOnAbp.PublicWeb.Components.Toolbar.LoginLink;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
@ -19,6 +20,8 @@ namespace EShopOnAbp.PublicWeb.Menus
{
context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginLinkViewComponent)));
}
context.Toolbar.Items.Add(new ToolbarItem(typeof(CartWidgetViewComponent)));
return Task.CompletedTask;
}

0
apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/cart/cart-widget.css

32
apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/cart/cart-widget.js

@ -0,0 +1,32 @@
(function (){
var connection = new signalR.HubConnectionBuilder()
.withUrl("/signalr-hubs/cart")
.build();
connection.on("BasketProductUpdated", function (data) {
var widgetManager = $wrapper.data('abp-widget-manager');
debugger;
$('#data-cart-count-id').text(data);
widgetManager.refresh();
abp.notify.info('The product "' + data.productName + '" has been changed!', 'Your basket has been updated!');
// $('.basket-list')
// .closest('.abp-widget-wrapper')
// .each(function(){
// var $wrapper = $(this);
// if ($wrapper.find('[data-product-id=' + data.productId + ']').length){
// var widgetManager = new abp.WidgetManager({
// wrapper: $wrapper
// });
// widgetManager.refresh();
// abp.notify.info('The product "' + data.productName + '" has been changed!', 'Your basket has been updated!');
// }
// });
});
connection.start().then(function () {
}).catch(function (err) {
return console.error(err.toString());
});
})();
Loading…
Cancel
Save