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.

Refactor: Migrate IPriceFormatter method ResourceReservationProductPeriod to extensions

support8996dc66e0d2
diff --git a/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs b/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
index 832521f16..0e15ee3f4 100644
--- a/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
@@ -1,8 +1,6 @@
using Grand.Business.Core.Interfaces.Catalog.Prices;
-using Grand.Domain.Catalog;
using Grand.Domain.Directory;
using Grand.Infrastructure;
-using Grand.SharedKernel;
using System.Globalization;
namespace Grand.Business.Catalog.Services.Prices
@@ -89,30 +87,7 @@ namespace Grand.Business.Catalog.Services.Prices
var currencyString = GetCurrencyString(price, targetCurrency);
return currencyString;
}
-
- /// <summary>
- /// Resource name of rental product (rental period)
- /// </summary>
- /// <param name="product">Product</param>
- /// <returns>Rental product price with period</returns>
- public virtual string ResourceReservationProductPeriod(Product product)
- {
- if (product == null)
- throw new ArgumentNullException(nameof(product));
-
- if (product.ProductTypeId != ProductType.Reservation)
- return string.Empty;
-
- var result = product.IntervalUnitId switch {
- 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")
- };
-
- return result;
- }
-
+
/// <summary>
/// Formats a tax rate
/// </summary>
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 f334d0b24..3c3600fed 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Catalog/Prices/IPriceFormatter.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Catalog/Prices/IPriceFormatter.cs
@@ -1,4 +1,3 @@
-using Grand.Domain.Catalog;
using Grand.Domain.Directory;
namespace Grand.Business.Core.Interfaces.Catalog.Prices
@@ -20,14 +19,6 @@ namespace Grand.Business.Core.Interfaces.Catalog.Prices
/// <returns>Price</returns>
string FormatPrice(double price, Currency targetCurrency);
- /// <summary>
- /// Resource name of rental product (rental period)
- /// </summary>
- /// <param name="product">Product</param>
- /// <returns>Rental product price with period</returns>
- string ResourceReservationProductPeriod(Product product);
-
-
/// <summary>
/// Formats a tax rate
/// </summary>
diff --git a/src/Web/Grand.Web/Extensions/ProductExtensions.cs b/src/Web/Grand.Web/Extensions/ProductExtensions.cs
index ce64b711b..28a412053 100644
--- a/src/Web/Grand.Web/Extensions/ProductExtensions.cs
+++ b/src/Web/Grand.Web/Extensions/ProductExtensions.cs
@@ -3,6 +3,7 @@ using Grand.Business.Core.Interfaces.Storage;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Media;
+using Grand.SharedKernel;
namespace Grand.Web.Extensions
{
@@ -73,5 +74,26 @@ namespace Grand.Web.Extensions
return picture;
}
+
+ /// <summary>
+ /// Resource name of rental product (rental period)
+ /// </summary>
+ /// <param name="product">Product</param>
+ /// <returns>Rental product price with period</returns>
+ public static string ResourceReservationProductPeriod(this Product product)
+ {
+ if (product.ProductTypeId != ProductType.Reservation)
+ return string.Empty;
+
+ var result = product.IntervalUnitId switch {
+ 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")
+ };
+
+ return result;
+ }
+
}
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
index 112e845ba..8757aa309 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
@@ -730,7 +730,7 @@ namespace Grand.Web.Features.Handlers.Products
{
model.IsReservation = true;
var priceStr = _priceFormatter.FormatPrice(finalPriceWithDiscount);
- model.ReservationPrice = string.Format(_translationService.GetResource(_priceFormatter.ResourceReservationProductPeriod(product)), priceStr, product.Interval);
+ model.ReservationPrice = string.Format(_translationService.GetResource(product.ResourceReservationProductPeriod()), 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 5cad73321..731beb760 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
@@ -12,6 +12,7 @@ using Grand.Domain.Catalog;
using Grand.Domain.Media;
using Grand.Domain.Tax;
using Grand.Infrastructure;
+using Grand.Web.Extensions;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Features.Models.Products;
using Grand.Web.Models.Catalog;
@@ -424,9 +425,9 @@ namespace Grand.Web.Features.Handlers.Products
{
//rental product
if(!string.IsNullOrEmpty(priceModel.OldPrice))
- priceModel.OldPrice = string.Format(_translationService.GetResource(_priceFormatter.ResourceReservationProductPeriod(product)), priceModel.OldPrice, product.Interval);
+ priceModel.OldPrice = string.Format(_translationService.GetResource(product.ResourceReservationProductPeriod()), priceModel.OldPrice, product.Interval);
- priceModel.Price = string.Format(_translationService.GetResource(_priceFormatter.ResourceReservationProductPeriod(product)), priceModel.Price, product.Interval);
+ priceModel.Price = string.Format(_translationService.GetResource(product.ResourceReservationProductPeriod()), priceModel.Price, product.Interval);
}
//PAngV base price (used in Germany)