module_settings_act_shop.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package modules
  2. import (
  3. "strings"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  6. )
  7. func (this *Modules) RegisterAction_SettingsShop() *Action {
  8. return this.newAction(AInfo{
  9. WantDB: true,
  10. Mount: "settings-shop",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_price_fomat := wrap.R.FormValue("price-fomat")
  14. pf_price_round := wrap.R.FormValue("price-round")
  15. pf_require_last_name := wrap.R.FormValue("require-last-name")
  16. pf_require_first_name := wrap.R.FormValue("require-first-name")
  17. pf_require_middle_name := wrap.R.FormValue("require-middle-name")
  18. pf_require_mobile_phone := wrap.R.FormValue("require-mobile-phone")
  19. pf_require_email_address := wrap.R.FormValue("require-email-address")
  20. pf_require_delivery := wrap.R.FormValue("require-delivery")
  21. pf_require_comment := wrap.R.FormValue("require-comment")
  22. pf_new_order_notify_email := strings.TrimSpace(wrap.R.FormValue("new-order-notify-email"))
  23. if !utils.IsNumeric(pf_price_fomat) {
  24. wrap.MsgError(`Must be integer number`)
  25. return
  26. }
  27. if !utils.IsNumeric(pf_price_round) {
  28. wrap.MsgError(`Must be integer number`)
  29. return
  30. }
  31. pfi_price_fomat := utils.StrToInt(pf_price_fomat)
  32. pfi_price_round := utils.StrToInt(pf_price_round)
  33. // Correct values
  34. if pfi_price_fomat < 0 {
  35. pfi_price_fomat = 0
  36. }
  37. if pfi_price_fomat > 4 {
  38. pfi_price_fomat = 4
  39. }
  40. if pfi_price_round < 0 {
  41. pfi_price_round = 0
  42. }
  43. if pfi_price_round > 2 {
  44. pfi_price_round = 2
  45. }
  46. if pf_require_last_name == "" {
  47. pf_require_last_name = "0"
  48. }
  49. if pf_require_first_name == "" {
  50. pf_require_first_name = "0"
  51. }
  52. if pf_require_middle_name == "" {
  53. pf_require_middle_name = "0"
  54. }
  55. if pf_require_mobile_phone == "" {
  56. pf_require_mobile_phone = "0"
  57. }
  58. if pf_require_email_address == "" {
  59. pf_require_email_address = "0"
  60. }
  61. if pf_require_delivery == "" {
  62. pf_require_delivery = "0"
  63. }
  64. if pf_require_comment == "" {
  65. pf_require_comment = "0"
  66. }
  67. (*wrap.Config).Shop.Price.Format = pfi_price_fomat
  68. (*wrap.Config).Shop.Price.Round = pfi_price_round
  69. (*wrap.Config).Shop.Orders.RequiredFields.LastName = utils.StrToInt(pf_require_last_name)
  70. (*wrap.Config).Shop.Orders.RequiredFields.FirstName = utils.StrToInt(pf_require_first_name)
  71. (*wrap.Config).Shop.Orders.RequiredFields.MiddleName = utils.StrToInt(pf_require_middle_name)
  72. (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone = utils.StrToInt(pf_require_mobile_phone)
  73. (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress = utils.StrToInt(pf_require_email_address)
  74. (*wrap.Config).Shop.Orders.RequiredFields.Delivery = utils.StrToInt(pf_require_delivery)
  75. (*wrap.Config).Shop.Orders.RequiredFields.Comment = utils.StrToInt(pf_require_comment)
  76. if pf_new_order_notify_email != "" {
  77. if utils.IsValidEmail(pf_new_order_notify_email) {
  78. (*wrap.Config).Shop.Orders.NotifyEmail = pf_new_order_notify_email
  79. }
  80. }
  81. if err := wrap.ConfigSave(); err != nil {
  82. wrap.MsgError(err.Error())
  83. return
  84. }
  85. wrap.ResetCacheBlocks()
  86. // Reload current page
  87. wrap.Write(`window.location.reload(false);`)
  88. })
  89. }