currency convert and format
This commit is contained in:
parent
7246d86e76
commit
919e5e699f
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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<IOrderProcessingService, OrderProcessingService>();
|
||||
services.AddScoped<IShoppingCartService, ShoppingCartService>();
|
||||
services.AddScoped<IStoreContext, WebStoreContext>();
|
||||
services.AddScoped<ICurrencyService, CurrencyService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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() { }
|
||||
|
|
|
|||
|
|
@ -24,4 +24,9 @@
|
|||
|
||||
|
||||
<div class="announcementPage">
|
||||
<style>
|
||||
.old-product-price {
|
||||
text-decoration: unset !important;
|
||||
}
|
||||
</style>
|
||||
</div>
|
||||
|
|
@ -4,11 +4,16 @@
|
|||
|
||||
|
||||
<script asp-location="Footer">
|
||||
|
||||
let currencyCode = @Html.Raw(Model.WorkingCurrencyCode.ToJson());
|
||||
let currencyRate = @Html.Raw(Model.WorkingCurrencyRate.ToJson());
|
||||
console.log(currencyCode);
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
console.log("PublicInfo ready enter; ProductId: " + @Model.ProductId);
|
||||
let auctionDto = @Html.Raw(Model.AuctionDto.ToJson());
|
||||
|
||||
|
||||
initialize@(Model.ProductId)(auctionDto);
|
||||
});
|
||||
|
||||
|
|
@ -45,7 +50,13 @@
|
|||
//console.log("widgetPriceElements:", widgetPriceElements);
|
||||
|
||||
if (widgetPriceElements && widgetPriceElements.length > 0) {
|
||||
widgetPriceElements[0].textContent = HUFFormatter.format(productToAuctionDto.currentPrice); // Update the price
|
||||
if(currencyCode == "EUR") {
|
||||
widgetPriceElements[0].textContent = EURFormatter.format(productToAuctionDto.currentPrice * currencyRate);
|
||||
}
|
||||
else {
|
||||
|
||||
widgetPriceElements[0].textContent = HUFFormatter.format(productToAuctionDto.currentPrice); // Update the price
|
||||
}
|
||||
}
|
||||
|
||||
let myDate = auctionDto.startDateUtc;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,29 @@
|
|||
@using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums
|
||||
@using Nop.Web.Framework.TagHelpers.Shared
|
||||
@using System.Globalization
|
||||
@model ProductBidBoxViewModel
|
||||
@* @inject IJsonHelper JsonHelper; *@
|
||||
|
||||
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
|
||||
|
||||
<style>
|
||||
.old-product-price {
|
||||
text-decoration: unset !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@{
|
||||
if (!Model.IsGuest)
|
||||
{
|
||||
if (Model.FirstProductToAuction != null)
|
||||
{
|
||||
|
||||
var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
|
||||
var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin);
|
||||
var auctionStatus = Model.FirstProductToAuction.AuctionStatus;
|
||||
var lastBidIsMine = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId;
|
||||
|
||||
|
||||
|
||||
var title = auctionStatus switch
|
||||
{
|
||||
AuctionStatus.Sold => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YouWin") : @T("Plugins.Misc.AuctionPlugin.Sold"),
|
||||
|
|
@ -58,25 +66,65 @@
|
|||
|
||||
</div>
|
||||
<div id="publicProductBidBox" class="p-3 @bgClass text-white">
|
||||
<div class="col-3"><strong>#@(Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().SortIndex)</strong></div>
|
||||
<div class="col-9"><a href="https://youtube.com/live/6yfnmyQE7Uw?feature=share">Youtube live</a></div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-3"><strong>#@(Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().SortIndex)</strong></div>
|
||||
<div class="col-9"><a target="_blank" class="btn btn-secondary btn-sm float-end" href="https://youtube.com/live/6yfnmyQE7Uw?feature=share"><i class="fa-brands fa-youtube"></i> Youtube live</a></div>
|
||||
</div>
|
||||
|
||||
<h4 id="bidBoxTitle">@title</h4>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="m-auto">
|
||||
<strong>Base Price:</strong>
|
||||
<span class="value">
|
||||
@($"{Model.BasePrice:c}")
|
||||
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
|
||||
</span>
|
||||
@{
|
||||
if(Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
|
||||
<span class="value">@($"{((decimal)Model.BasePriceInWorkingCurrency).ToString("C", new CultureInfo("de-DE"))}")</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="value">@($"{((decimal)Model.BasePrice).ToString("C", new CultureInfo("hu-HU"))}")</span>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<div class="m-auto">
|
||||
<strong>Bid Step:</strong>
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStepInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}")</span>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStep.ToString("C", new CultureInfo("hu-HU"))}")</span>
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<div class="m-auto">
|
||||
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPrice:c}")
|
||||
<button id="signalRBidButton" class="btn btn-success float-end" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPriceInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}")
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPrice.ToString("C", new CultureInfo("hu-HU"))}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
|
||||
|
|
@ -300,6 +348,8 @@
|
|||
// data.AuctionDto.
|
||||
// }
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var currency = bidBoxPageViewModel.WorkingCurrency;
|
||||
console.log(currency);
|
||||
var bidButtonElement = document.getElementById("signalRBidButton");
|
||||
var licitStepElement = document.getElementById("licitStepText");
|
||||
var bidBox = document.getElementById("publicProductBidBox");
|
||||
|
|
@ -335,10 +385,15 @@
|
|||
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
|
||||
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
|
||||
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
|
||||
if(bidBoxPageViewModel.WorkingCurrency.CurrencyCode == "EUR") {
|
||||
widgetPriceElement.textContent = EURFormatter.format(data.currentPrice * bidBoxPageViewModel.WorkingCurrency.Rate); // Update the price
|
||||
licitStepElement.textContent = EURFormatter.format(data.nextStepAmount * bidBoxPageViewModel.WorkingCurrency.Rate);
|
||||
}
|
||||
else {
|
||||
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
|
||||
}
|
||||
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
|
||||
bidButtonElement.disabled = false;
|
||||
var list;
|
||||
if (isMyBid) {
|
||||
|
|
@ -362,7 +417,14 @@
|
|||
list.add("bg-primary");
|
||||
list.remove("bg-success");
|
||||
bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? "@(T("Plugins.Misc.AuctionPlugin.Sold"))" : "@(T("Plugins.Misc.AuctionPlugin.PlaceABid"))";
|
||||
bidButtonElement.textContent = "@(T("Plugins.Misc.AuctionPlugin.BidButtonPrefix")) " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
||||
if(bidBoxPageViewModel.WorkingCurrency.CurrencyCode == "EUR") {
|
||||
bidButtonElement.textContent = "@(T("Plugins.Misc.AuctionPlugin.BidButtonPrefix")) " + EURFormatter.format(bidBoxPageViewModel.NextBidPriceInWorkingCurrency);
|
||||
}
|
||||
else {
|
||||
bidButtonElement.textContent = "@(T("Plugins.Misc.AuctionPlugin.BidButtonPrefix")) " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,3 +27,4 @@
|
|||
@using Nop.Plugin.Misc.AuctionPlugin
|
||||
@using Nop.Plugin.Misc.AuctionPlugin.Models
|
||||
@using Nop.Plugin.Misc.AuctionPlugin.Services
|
||||
@using Nop.Core.Domain.Directory;
|
||||
|
|
|
|||
Loading…
Reference in New Issue