From 919e5e699fde2b444d3bba887f912a88b912c84c Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 1 Dec 2024 11:44:14 +0100 Subject: [PATCH] currency convert and format --- .../Components/AuctionPublicViewComponent.cs | 42 ++++++++- .../Components/AuctionViewComponent.cs | 5 +- .../Content/Js/LiveAnnouncement.js | 4 + .../Infrastructure/PluginNopStartup.cs | 2 + .../Models/AuctionPublicInfoModel.cs | 4 + .../Models/ProductBidBoxViewModel.cs | 8 ++ .../Views/LiveAnnouncement.cshtml | 5 + .../Views/PublicInfo.cshtml | 15 ++- .../Views/PublicProductBidBox.cshtml | 94 +++++++++++++++---- .../Views/_ViewImports.cshtml | 1 + 10 files changed, 158 insertions(+), 22 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index 0407c07..bf26cbc 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -13,6 +13,8 @@ using Nop.Web.Framework.Infrastructure; using Nop.Web.Models.Catalog; using Nop.Web.Framework.Mvc.Routing; using Nop.Services.Catalog; +using Nop.Web.Framework; +using Nop.Services.Directory; namespace Nop.Plugin.Misc.AuctionPlugin.Components; @@ -24,6 +26,8 @@ public class AuctionPublicViewComponent : NopViewComponent //private readonly IGenericAttributeService _genericAttributeService; private readonly IWidgetPluginManager _widgetPluginManager; private readonly IWorkContext _workContext; + private readonly IStoreContext _storeContext; + private readonly ICurrencyService _currencyService; private readonly AuctionService _auctionService; //private readonly AuctionSettings _auctionSettings; private readonly ICustomerService _customerService; @@ -41,6 +45,8 @@ public class AuctionPublicViewComponent : NopViewComponent //IGenericAttributeService genericAttributeService, IWidgetPluginManager widgetPluginManager, IWorkContext workContext, + IStoreContext storeContext, + ICurrencyService currencyService, AuctionService auctionService, //AuctionSettings auctionSettings, ICustomerService customerService, @@ -53,6 +59,8 @@ public class AuctionPublicViewComponent : NopViewComponent //_genericAttributeService = genericAttributeService; _widgetPluginManager = widgetPluginManager; _workContext = workContext; + _storeContext = storeContext; + _currencyService = currencyService; _auctionService = auctionService; //_auctionSettings = auctionSettings; _customerService = customerService; @@ -83,7 +91,11 @@ public class AuctionPublicViewComponent : NopViewComponent //ensure that widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); - await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}"); + var currency = await _workContext.GetWorkingCurrencyAsync(); + var store = await _storeContext.GetCurrentStoreAsync(); + //var allCurrencies = await _currencyService.GetAllCurrenciesAsync(); + //var baseCurrency = allCurrencies.Where(x => x.Rate == 1); + await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}"); if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer)) return Content(string.Empty); @@ -185,11 +197,14 @@ public class AuctionPublicViewComponent : NopViewComponent productBidBoxViewModel.AuctionClosed = auctionDto.Closed; productBidBoxViewModel.AuctionStatus = status; productBidBoxViewModel.WidgetZone = widgetZone; + //comes in WORKINGCURRENCY productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; - productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; + //comes in WORKINGCURRENCY + productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; //productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id; //productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.CustomerId = customer.Id; + productBidBoxViewModel.WorkingCurrency = currency; productBidBoxViewModel.ProductId = productDetailsModel.Id; //productBidBoxViewModel.NextProductUrl = Url.RouteUrl("Product", productDetailsModel.SeName); productBidBoxViewModel.NextProductUrl = nextUrl; @@ -198,8 +213,31 @@ public class AuctionPublicViewComponent : NopViewComponent productBidBoxViewModel.NextProductImageUrl = nextImageUrl; productBidBoxViewModel.LastProductName = lastProductName; productBidBoxViewModel.NextProductName = nextProductName; + //comes in HUF productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation + //comes IN HUF + productBidBoxViewModel.LicitStepInWorkingCurrency = AuctionService.GetStepAmount(productToAuction.CurrentPrice) * currency.Rate; + //comes in HUF productBidBoxViewModel.NextBidPrice = AuctionService.GetNextBidPrice(productToAuction.CurrentPrice, productBidBoxViewModel.LicitStep); + productBidBoxViewModel.NextBidPriceInWorkingCurrency = productBidBoxViewModel.NextBidPrice * currency.Rate; + if(productBidBoxViewModel.BasePrice != null) + { + //comes in WORKINGCURRENCY + + + productBidBoxViewModel.BasePriceInWorkingCurrency = productBidBoxViewModel.BasePrice; + + + + } + else + { + //basprice null, we use the baseprice in PTA that comes in HUF + productBidBoxViewModel.BasePrice = productToAuction.StartingPrice * currency.Rate; + productBidBoxViewModel.BasePriceInWorkingCurrency = productBidBoxViewModel.BasePrice; + + } + productBidBoxViewModel.CurrentPriceInWorkingCurrency = productBidBoxViewModel.CurrentPrice; return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs index a2dbbd8..aacbe72 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs @@ -58,7 +58,7 @@ public class AuctionViewComponent : NopViewComponent //ensure that a widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); - + var currency = await _workContext.GetWorkingCurrencyAsync(); //if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer)) // return Content(string.Empty); @@ -98,7 +98,8 @@ public class AuctionViewComponent : NopViewComponent auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); var model = new AuctionPublicInfoModel(auctionDto); - + model.WorkingCurrencyCode = currency.CurrencyCode; + model.WorkingCurrencyRate = currency.Rate; //model.ProductToAuctionMappingId = productToAuctionMapping.Id; //var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuctionMapping.Id); //model.StartDate = auction.StartDateUtc; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js index 83b3d15..eb5abb4 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js @@ -18,6 +18,10 @@ style: "currency", currency: "HUF", }); + window.EURFormatter = new Intl.NumberFormat("eu-EU", { + style: "currency", + currency: "EUR", + }); // SignalR connection setup var connection = new signalR.HubConnectionBuilder() diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs index de618f9..8081ffe 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs @@ -20,6 +20,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Hubs; using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Services.Catalog; using Nop.Services.Configuration; +using Nop.Services.Directory; using Nop.Services.Localization; using Nop.Services.Orders; using Nop.Web.Framework; @@ -73,6 +74,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } /// diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionPublicInfoModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionPublicInfoModel.cs index 5023697..e2fa763 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionPublicInfoModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionPublicInfoModel.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Nop.Core.Domain.Directory; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Web.Framework.Models; @@ -19,6 +20,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models public DateTime StartDate => AuctionDto?.StartDateUtc ?? DateTime.MinValue; public bool IsActive => FirstProductToAuction?.IsActiveItem ?? false; + public string WorkingCurrencyCode { get; set; } + public decimal WorkingCurrencyRate { get; set; } + public AuctionPublicInfoModel() { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs index 4da5749..77d3ac3 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs @@ -1,5 +1,6 @@ using ExCSS; using Newtonsoft.Json; +using Nop.Core.Domain.Directory; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Web.Framework.Models; @@ -41,12 +42,15 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models public int CustomerId { get; set; } + public Currency WorkingCurrency { get; set; } + public string WidgetZone { get; set; } #region debug fields to be removed public decimal? BasePrice { get; set; } + public decimal? BasePriceInWorkingCurrency { get; set; } #endregion @@ -55,6 +59,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models public decimal? CurrentPrice { get; set; } public decimal NextBidPrice { get; set; } + public decimal LicitStepInWorkingCurrency { get; set; } + public decimal? CurrentPriceInWorkingCurrency { get; set; } + public decimal NextBidPriceInWorkingCurrency { get; set; } + #endregion visible public ProductBidBoxViewModel() { } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml index 3a65eee..4463351 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml @@ -24,4 +24,9 @@
+
\ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicInfo.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicInfo.cshtml index c546a8e..ac164f8 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicInfo.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicInfo.cshtml @@ -4,11 +4,16 @@