module_settings_act_shop.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package modules
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. func (this *Modules) RegisterAction_SettingsShop() *Action {
  7. return this.newAction(AInfo{
  8. WantDB: true,
  9. Mount: "settings-shop",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_price_fomat := wrap.R.FormValue("price-fomat")
  13. pf_price_round := wrap.R.FormValue("price-round")
  14. if !utils.IsNumeric(pf_price_fomat) {
  15. wrap.MsgError(`Must be integer number`)
  16. return
  17. }
  18. if !utils.IsNumeric(pf_price_round) {
  19. wrap.MsgError(`Must be integer number`)
  20. return
  21. }
  22. pfi_price_fomat := utils.StrToInt(pf_price_fomat)
  23. pfi_price_round := utils.StrToInt(pf_price_round)
  24. // Correct values
  25. if pfi_price_fomat < 0 {
  26. pfi_price_fomat = 0
  27. }
  28. if pfi_price_fomat > 4 {
  29. pfi_price_fomat = 4
  30. }
  31. if pfi_price_round < 0 {
  32. pfi_price_round = 0
  33. }
  34. if pfi_price_round > 2 {
  35. pfi_price_round = 2
  36. }
  37. (*wrap.Config).Shop.Price.Format = pfi_price_fomat
  38. (*wrap.Config).Shop.Price.Round = pfi_price_round
  39. if err := wrap.ConfigSave(); err != nil {
  40. wrap.MsgError(err.Error())
  41. return
  42. }
  43. wrap.ResetCacheBlocks()
  44. // Reload current page
  45. wrap.Write(`window.location.reload(false);`)
  46. })
  47. }