Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

PriceFormatter.cs - changes with FormatReservationProductPeriod

supporte9c619f16298
diff --git a/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs b/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
index d43dad512..7b2beacfd 100644
--- a/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
@@ -243,29 +243,22 @@ namespace Grand.Business.Catalog.Services.Prices
}
/// <summary>
- /// Formats the price of rental product (with rental period)
+ /// Resource name of rental product (rental period)
/// </summary>
/// <param name="product">Product</param>
- /// <param name="price">Price</param>
/// <returns>Rental product price with period</returns>
- public virtual string FormatReservationProductPeriod(Product product, string price)
+ public virtual string ResourceReservationProductPeriod(Product product)
{
if (product == null)
throw new ArgumentNullException(nameof(product));
if (product.ProductTypeId != ProductType.Reservation)
- return price;
-
- if (string.IsNullOrWhiteSpace(price))
- return price;
+ return string.Empty;
var result = product.IntervalUnitId switch {
- IntervalUnit.Day => string.Format(_translationService.GetResource("Products.Price.Reservation.Days"),
- price, product.Interval),
- IntervalUnit.Hour => string.Format(_translationService.GetResource("Products.Price.Reservation.Hour"),
- price, product.Interval),
- IntervalUnit.Minute => string.Format(
- _translationService.GetResource("Products.Price.Reservation.Minute"), price, product.Interval),
+ IntervalUnit.Day => "Products.Price.Reservation.Days",
+ IntervalUnit.Hour => "Products.Price.Reservation.Hour",
+ IntervalUnit.Minute => "Products.Price.Reservation.Minute",
_ => throw new GrandException("Not supported reservation period")
};
diff --git a/src/Business/Grand.Business.Core/Interfaces/Catalog/Prices/IPriceFormatter.cs b/src/Business/Grand.Business.Core/Interfaces/Catalog/Prices/IPriceFormatter.cs
index 31305d2d3..3010410ff 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Catalog/Prices/IPriceFormatter.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Catalog/Prices/IPriceFormatter.cs
@@ -71,12 +71,11 @@ namespace Grand.Business.Core.Interfaces.Catalog.Prices
string FormatPrice(double price, Currency targetCurrency, Language language, bool priceIncludesTax, bool showTax);
/// <summary>
- /// Formats the price of rental product (with rental period)
+ /// Resource name of rental product (rental period)
/// </summary>
/// <param name="product">Product</param>
- /// <param name="price">Price</param>
/// <returns>Rental product price with period</returns>
- string FormatReservationProductPeriod(Product product, string price);
+ string ResourceReservationProductPeriod(Product product);
/// <summary>
/// Formats the shipping price
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
index 150459c1c..756311f68 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
@@ -723,7 +723,7 @@ namespace Grand.Web.Features.Handlers.Products
{
model.IsReservation = true;
var priceStr = _priceFormatter.FormatPrice(finalPriceWithDiscount);
- model.ReservationPrice = _priceFormatter.FormatReservationProductPeriod(product, priceStr);
+ model.ReservationPrice = string.Format(_translationService.GetResource(_priceFormatter.ResourceReservationProductPeriod(product)), priceStr, product.Interval);
}
if (product.ProductTypeId != ProductType.Auction) return model;
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
index 95f874bf6..cae30f877 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
@@ -442,10 +442,10 @@ namespace Grand.Web.Features.Handlers.Products
if (product.ProductTypeId == ProductType.Reservation)
{
//rental product
- priceModel.OldPrice =
- _priceFormatter.FormatReservationProductPeriod(product, priceModel.OldPrice);
- priceModel.Price =
- _priceFormatter.FormatReservationProductPeriod(product, priceModel.Price);
+ if(!string.IsNullOrEmpty(priceModel.OldPrice))
+ priceModel.OldPrice = string.Format(_translationService.GetResource(_priceFormatter.ResourceReservationProductPeriod(product)), priceModel.OldPrice, product.Interval);
+
+ priceModel.Price = string.Format(_translationService.GetResource(_priceFormatter.ResourceReservationProductPeriod(product)), priceModel.Price, product.Interval);
}
//PAngV base price (used in Germany)