Browse Source

Price formating in general settings

Vova Tkach 5 years ago
parent
commit
988bb38c5e

+ 4 - 0
engine/fetdata/shop_product.go

@@ -237,6 +237,10 @@ func (this *ShopProduct) Price() float64 {
 	}
 	}
 }
 }
 
 
+func (this *ShopProduct) PriceNice() string {
+	return ""
+}
+
 func (this *ShopProduct) PriceFormat(format string) string {
 func (this *ShopProduct) PriceFormat(format string) string {
 	return utils.Float64ToStrF(this.Price(), format)
 	return utils.Float64ToStrF(this.Price(), format)
 }
 }

+ 7 - 0
engine/wrapper/config/config.go

@@ -27,6 +27,10 @@ type Config struct {
 			Thumbnail3    [3]int
 			Thumbnail3    [3]int
 			ThumbnailFull [3]int
 			ThumbnailFull [3]int
 		}
 		}
+		Price struct {
+			Format int
+			Round  int
+		}
 	}
 	}
 	API struct {
 	API struct {
 		XML struct {
 		XML struct {
@@ -79,6 +83,9 @@ func (this *Config) configDefault() {
 	this.Shop.Thumbnails.ThumbnailFull[1] = 800
 	this.Shop.Thumbnails.ThumbnailFull[1] = 800
 	this.Shop.Thumbnails.ThumbnailFull[2] = 1
 	this.Shop.Thumbnails.ThumbnailFull[2] = 1
 
 
+	this.Shop.Price.Format = 2
+	this.Shop.Price.Round = 0
+
 	this.API.XML.Enabled = 0
 	this.API.XML.Enabled = 0
 	this.API.XML.Name = ""
 	this.API.XML.Name = ""
 	this.API.XML.Company = ""
 	this.API.XML.Company = ""

+ 73 - 0
modules/module_settings.go

@@ -64,6 +64,55 @@ func (this *Modules) RegisterModule_Settings() *Module {
 						}
 						}
 						modules_list += `>Shop</option>`
 						modules_list += `>Shop</option>`
 						modules_list += `</select>`
 						modules_list += `</select>`
+
+						price_format_list := ``
+						price_format_list += `<select class="form-control" id="lbl_price-fomat" name="price-fomat">`
+						price_format_list += `<option value="0"`
+						if (*wrap.Config).Shop.Price.Format == 0 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100 USD</option>`
+						price_format_list += `<option value="1"`
+						if (*wrap.Config).Shop.Price.Format == 1 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.0 USD</option>`
+						price_format_list += `<option value="2"`
+						if (*wrap.Config).Shop.Price.Format == 2 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.00 USD</option>`
+						price_format_list += `<option value="3"`
+						if (*wrap.Config).Shop.Price.Format == 3 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.000 USD</option>`
+						price_format_list += `<option value="4"`
+						if (*wrap.Config).Shop.Price.Format == 4 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.0000 USD</option>`
+						price_format_list += `</select>`
+
+						price_round_list := ``
+						price_round_list += `<select class="form-control" id="lbl_price-round" name="price-round">`
+						price_round_list += `<option value="0"`
+						if (*wrap.Config).Shop.Price.Round == 0 {
+							price_round_list += ` selected`
+						}
+						price_round_list += `>Don't round</option>`
+						price_round_list += `<option value="1"`
+						if (*wrap.Config).Shop.Price.Round == 1 {
+							price_round_list += ` selected`
+						}
+						price_round_list += `>Round to ceil</option>`
+						price_round_list += `<option value="2"`
+						if (*wrap.Config).Shop.Price.Round == 2 {
+							price_round_list += ` selected`
+						}
+						price_round_list += `>Round to floor</option>`
+						price_round_list += `</select>`
+
 						return `<div class="form-group n3">` +
 						return `<div class="form-group n3">` +
 							`<div class="row">` +
 							`<div class="row">` +
 							`<div class="col-md-3">` +
 							`<div class="col-md-3">` +
@@ -75,6 +124,30 @@ func (this *Modules) RegisterModule_Settings() *Module {
 							`</div>` +
 							`</div>` +
 							`</div>` +
 							`</div>` +
 							`</div>` +
 							`</div>` +
+							`</div>` +
+							`<div class="form-group n3">` +
+							`<div class="row">` +
+							`<div class="col-md-3">` +
+							`<label for="lbl_price-fomat">Price format</label>` +
+							`</div>` +
+							`<div class="col-md-9">` +
+							`<div>` +
+							price_format_list +
+							`</div>` +
+							`</div>` +
+							`</div>` +
+							`</div>` +
+							`<div class="form-group n3">` +
+							`<div class="row">` +
+							`<div class="col-md-3">` +
+							`<label for="lbl_price-round">Price round</label>` +
+							`</div>` +
+							`<div class="col-md-9">` +
+							`<div>` +
+							price_round_list +
+							`</div>` +
+							`</div>` +
+							`</div>` +
 							`</div>`
 							`</div>`
 					},
 					},
 				},
 				},

+ 31 - 3
modules/module_settings_act_general.go

@@ -1,8 +1,6 @@
 package modules
 package modules
 
 
 import (
 import (
-	"strconv"
-
 	"golang-fave/engine/wrapper"
 	"golang-fave/engine/wrapper"
 	"golang-fave/utils"
 	"golang-fave/utils"
 )
 )
@@ -14,13 +12,27 @@ func (this *Modules) RegisterAction_SettingsGeneral() *Action {
 		WantAdmin: true,
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 	}, func(wrap *wrapper.Wrapper) {
 		pf_module_at_home := wrap.R.FormValue("module-at-home")
 		pf_module_at_home := wrap.R.FormValue("module-at-home")
+		pf_price_fomat := wrap.R.FormValue("price-fomat")
+		pf_price_round := wrap.R.FormValue("price-round")
+
+		if !utils.IsNumeric(pf_module_at_home) {
+			wrap.MsgError(`Must be integer number`)
+			return
+		}
 
 
-		if _, err := strconv.Atoi(pf_module_at_home); err != nil {
+		if !utils.IsNumeric(pf_price_fomat) {
+			wrap.MsgError(`Must be integer number`)
+			return
+		}
+
+		if !utils.IsNumeric(pf_price_round) {
 			wrap.MsgError(`Must be integer number`)
 			wrap.MsgError(`Must be integer number`)
 			return
 			return
 		}
 		}
 
 
 		pfi_module_at_home := utils.StrToInt(pf_module_at_home)
 		pfi_module_at_home := utils.StrToInt(pf_module_at_home)
+		pfi_price_fomat := utils.StrToInt(pf_price_fomat)
+		pfi_price_round := utils.StrToInt(pf_price_round)
 
 
 		// Correct some values
 		// Correct some values
 		if pfi_module_at_home < 0 {
 		if pfi_module_at_home < 0 {
@@ -30,7 +42,23 @@ func (this *Modules) RegisterAction_SettingsGeneral() *Action {
 			pfi_module_at_home = 2
 			pfi_module_at_home = 2
 		}
 		}
 
 
+		if pfi_price_fomat < 0 {
+			pfi_price_fomat = 0
+		}
+		if pfi_price_fomat > 4 {
+			pfi_price_fomat = 4
+		}
+
+		if pfi_price_round < 0 {
+			pfi_price_round = 0
+		}
+		if pfi_price_round > 2 {
+			pfi_price_round = 2
+		}
+
 		(*wrap.Config).Engine.MainModule = pfi_module_at_home
 		(*wrap.Config).Engine.MainModule = pfi_module_at_home
+		(*wrap.Config).Shop.Price.Format = pfi_price_fomat
+		(*wrap.Config).Shop.Price.Round = pfi_price_round
 
 
 		if err := wrap.ConfigSave(); err != nil {
 		if err := wrap.ConfigSave(); err != nil {
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())