module_settings_act_shop.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. pf_require_last_name := wrap.R.FormValue("require-last-name")
  15. pf_require_first_name := wrap.R.FormValue("require-first-name")
  16. pf_require_middle_name := wrap.R.FormValue("require-middle-name")
  17. pf_require_mobile_phone := wrap.R.FormValue("require-mobile-phone")
  18. pf_require_email_address := wrap.R.FormValue("require-email-address")
  19. pf_require_delivery := wrap.R.FormValue("require-delivery")
  20. pf_require_comment := wrap.R.FormValue("require-comment")
  21. if !utils.IsNumeric(pf_price_fomat) {
  22. wrap.MsgError(`Must be integer number`)
  23. return
  24. }
  25. if !utils.IsNumeric(pf_price_round) {
  26. wrap.MsgError(`Must be integer number`)
  27. return
  28. }
  29. pfi_price_fomat := utils.StrToInt(pf_price_fomat)
  30. pfi_price_round := utils.StrToInt(pf_price_round)
  31. // Correct values
  32. if pfi_price_fomat < 0 {
  33. pfi_price_fomat = 0
  34. }
  35. if pfi_price_fomat > 4 {
  36. pfi_price_fomat = 4
  37. }
  38. if pfi_price_round < 0 {
  39. pfi_price_round = 0
  40. }
  41. if pfi_price_round > 2 {
  42. pfi_price_round = 2
  43. }
  44. if pf_require_last_name == "" {
  45. pf_require_last_name = "0"
  46. }
  47. if pf_require_first_name == "" {
  48. pf_require_first_name = "0"
  49. }
  50. if pf_require_middle_name == "" {
  51. pf_require_middle_name = "0"
  52. }
  53. if pf_require_mobile_phone == "" {
  54. pf_require_mobile_phone = "0"
  55. }
  56. if pf_require_email_address == "" {
  57. pf_require_email_address = "0"
  58. }
  59. if pf_require_delivery == "" {
  60. pf_require_delivery = "0"
  61. }
  62. if pf_require_comment == "" {
  63. pf_require_comment = "0"
  64. }
  65. (*wrap.Config).Shop.Price.Format = pfi_price_fomat
  66. (*wrap.Config).Shop.Price.Round = pfi_price_round
  67. (*wrap.Config).Shop.Orders.RequiredFields.LastName = utils.StrToInt(pf_require_last_name)
  68. (*wrap.Config).Shop.Orders.RequiredFields.FirstName = utils.StrToInt(pf_require_first_name)
  69. (*wrap.Config).Shop.Orders.RequiredFields.MiddleName = utils.StrToInt(pf_require_middle_name)
  70. (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone = utils.StrToInt(pf_require_mobile_phone)
  71. (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress = utils.StrToInt(pf_require_email_address)
  72. (*wrap.Config).Shop.Orders.RequiredFields.Delivery = utils.StrToInt(pf_require_delivery)
  73. (*wrap.Config).Shop.Orders.RequiredFields.Comment = utils.StrToInt(pf_require_comment)
  74. if err := wrap.ConfigSave(); err != nil {
  75. wrap.MsgError(err.Error())
  76. return
  77. }
  78. wrap.ResetCacheBlocks()
  79. // Reload current page
  80. wrap.Write(`window.location.reload(false);`)
  81. })
  82. }