Browse Source

PriceNice for templates

Vova Tkach 5 years ago
parent
commit
36ee72fe5b
1 changed files with 19 additions and 1 deletions
  1. 19 1
      engine/fetdata/shop_product.go

+ 19 - 1
engine/fetdata/shop_product.go

@@ -2,6 +2,7 @@ package fetdata
 
 import (
 	"html/template"
+	"math"
 	"strings"
 	"time"
 
@@ -238,7 +239,24 @@ func (this *ShopProduct) Price() float64 {
 }
 
 func (this *ShopProduct) PriceNice() string {
-	return ""
+	price := this.Price()
+	if (*this.wrap.Config).Shop.Price.Round == 1 {
+		price = math.Ceil(price)
+	} else if (*this.wrap.Config).Shop.Price.Round == 2 {
+		price = math.Floor(price)
+	}
+
+	if (*this.wrap.Config).Shop.Price.Format == 1 {
+		return utils.Float64ToStrF(price, "%.1f")
+	} else if (*this.wrap.Config).Shop.Price.Format == 2 {
+		return utils.Float64ToStrF(price, "%.2f")
+	} else if (*this.wrap.Config).Shop.Price.Format == 3 {
+		return utils.Float64ToStrF(price, "%.3f")
+	} else if (*this.wrap.Config).Shop.Price.Format == 4 {
+		return utils.Float64ToStrF(price, "%.4f")
+	}
+
+	return utils.Float64ToStrF(price, "%.0f")
 }
 
 func (this *ShopProduct) PriceFormat(format string) string {