Browse Source
This is not done since it requires CurrentUserId to perform basket requests.pull/41/head
6 changed files with 89 additions and 0 deletions
@ -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"); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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…
Reference in new issue