/// <summary> /// Handle model received event /// </summary> /// <param name="eventMessage">Event message</param> /// <returns>A task that represents the asynchronous operation</returns> public async Task HandleEventAsync(ModelReceivedEvent <BaseNopModel> eventMessage) { if (eventMessage.Model is not CheckoutBillingAddressModel && eventMessage.Model is not CheckoutShippingAddressModel) { return; } var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _widgetPluginManager.IsPluginActiveAsync(What3wordsDefaults.SystemName, customer)) { return; } if (!_what3WordsSettings.Enabled) { return; } //cache the value within the request, we save it to the address later var form = _httpContextAccessor.HttpContext.Request.Form; if (form.TryGetValue(What3wordsDefaults.ComponentName, out var addressValue) && !StringValues.IsNullOrEmpty(addressValue)) { _httpContextAccessor.HttpContext.Items[What3wordsDefaults.AddressValueAttribute] = addressValue.ToString().TrimStart('/'); } }
/// <summary> /// Invoke the widget view component /// </summary> /// <param name="widgetZone">Widget zone</param> /// <param name="additionalData">Additional parameters</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { //ensure that what3words widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _widgetPluginManager.IsPluginActiveAsync(What3wordsDefaults.SystemName, customer)) { return(Content(string.Empty)); } if (!_what3WordsSettings.Enabled) { return(Content(string.Empty)); } var summaryModel = additionalData as ShoppingCartModel.OrderReviewDataModel; var detailsModel = additionalData as OrderDetailsModel; if (summaryModel is null && detailsModel is null) { return(Content(string.Empty)); } var addressId = 0; if (widgetZone.Equals(PublicWidgetZones.OrderSummaryBillingAddress)) { addressId = summaryModel.BillingAddress.Id; } if (widgetZone.Equals(PublicWidgetZones.OrderSummaryShippingAddress)) { addressId = summaryModel.ShippingAddress.Id; } if (widgetZone.Equals(PublicWidgetZones.OrderDetailsBillingAddress)) { addressId = detailsModel.BillingAddress.Id; } if (widgetZone.Equals(PublicWidgetZones.OrderDetailsShippingAddress)) { addressId = detailsModel.ShippingAddress.Id; } var address = await _addressService.GetAddressByIdAsync(addressId); var addressValue = address is not null ? await _genericAttributeService.GetAttributeAsync <string>(address, What3wordsDefaults.AddressValueAttribute) : null; if (string.IsNullOrEmpty(addressValue)) { return(Content(string.Empty)); } return(View("~/Plugins/Widgets.What3words/Views/PublicOrderAddress.cshtml", addressValue)); }
private async Task <CartSlideoutInfo> GetSlideoutInfoAsync(Product product) { var isSlideoutActive = await _widgetPluginManager.IsPluginActiveAsync("Widgets.CartSlideout"); if (!isSlideoutActive) { return(null); } return(new CartSlideoutInfo() { ProductInfoHtml = await RenderViewComponentToStringAsync("CartSlideoutProductInfo", new { productId = product.Id }), SubtotalHtml = await RenderViewComponentToStringAsync("CartSlideoutSubtotal", new { price = product.Price }), HasDeliveryOptions = false // this needs to check product - maybe just get the attributes ready? }); }
/// <summary> /// Invoke the widget view component /// </summary> /// <param name="widgetZone">Widget zone</param> /// <param name="additionalData">Additional parameters</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { if (!widgetZone.Equals(PublicWidgetZones.AddressBottom)) { return(Content(string.Empty)); } //ensure that what3words widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _widgetPluginManager.IsPluginActiveAsync(What3wordsDefaults.SystemName, customer)) { return(Content(string.Empty)); } if (!_what3WordsSettings.Enabled) { return(Content(string.Empty)); } if (string.IsNullOrEmpty(_what3WordsSettings.ApiKey)) { await _logger.ErrorAsync("what3words error: API key is not set", customer : customer); return(Content(string.Empty)); } //display this on the checkout pages only if (ViewData.TemplateInfo.HtmlFieldPrefix != What3wordsDefaults.BillingAddressPrefix && ViewData.TemplateInfo.HtmlFieldPrefix != What3wordsDefaults.ShippingAddressPrefix) { return(Content(string.Empty)); } var model = new What3wordsAddressModel { ApiKey = _what3WordsSettings.ApiKey, Prefix = ViewData.TemplateInfo.HtmlFieldPrefix }; return(View("~/Plugins/Widgets.What3words/Views/PublicInfo.cshtml", model)); }
/// <summary> /// Invoke the widget view component /// </summary> /// <param name="widgetZone">Widget zone</param> /// <param name="additionalData">Additional parameters</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { //ensure that what3words widget is active and enabled if (!await _widgetPluginManager.IsPluginActiveAsync(What3wordsDefaults.SystemName)) { return(Content(string.Empty)); } if (!_what3WordsSettings.Enabled) { return(Content(string.Empty)); } if (additionalData is not OrderModel model) { return(Content(string.Empty)); } var addressId = 0; if (widgetZone.Equals(AdminWidgetZones.OrderBillingAddressDetailsBottom)) { addressId = model.BillingAddress.Id; } if (widgetZone.Equals(AdminWidgetZones.OrderShippingAddressDetailsBottom)) { addressId = model.ShippingAddress.Id; } var address = await _addressService.GetAddressByIdAsync(addressId); var addressValue = address is not null ? await _genericAttributeService.GetAttributeAsync <string>(address, What3wordsDefaults.AddressValueAttribute) : null; if (string.IsNullOrEmpty(addressValue)) { return(Content(string.Empty)); } return(View("~/Plugins/Widgets.What3words/Views/AdminOrderAddress.cshtml", addressValue)); }
private async Task <bool> IsPluginEnabledAsync() { return(await _widgetPluginManager.IsPluginActiveAsync("Widgets.GoogleAnalytics")); }