module_settings_act_shop.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. pf_accept_orders := wrap.R.FormValue("accept-orders")
  24. if !utils.IsNumeric(pf_price_fomat) {
  25. wrap.MsgError(`Must be integer number`)
  26. return
  27. }
  28. if !utils.IsNumeric(pf_price_round) {
  29. wrap.MsgError(`Must be integer number`)
  30. return
  31. }
  32. pfi_price_fomat := utils.StrToInt(pf_price_fomat)
  33. pfi_price_round := utils.StrToInt(pf_price_round)
  34. // Correct values
  35. if pfi_price_fomat < 0 {
  36. pfi_price_fomat = 0
  37. }
  38. if pfi_price_fomat > 4 {
  39. pfi_price_fomat = 4
  40. }
  41. if pfi_price_round < 0 {
  42. pfi_price_round = 0
  43. }
  44. if pfi_price_round > 2 {
  45. pfi_price_round = 2
  46. }
  47. if pf_require_last_name == "" {
  48. pf_require_last_name = "0"
  49. }
  50. if pf_require_first_name == "" {
  51. pf_require_first_name = "0"
  52. }
  53. if pf_require_middle_name == "" {
  54. pf_require_middle_name = "0"
  55. }
  56. if pf_require_mobile_phone == "" {
  57. pf_require_mobile_phone = "0"
  58. }
  59. if pf_require_email_address == "" {
  60. pf_require_email_address = "0"
  61. }
  62. if pf_require_delivery == "" {
  63. pf_require_delivery = "0"
  64. }
  65. if pf_require_comment == "" {
  66. pf_require_comment = "0"
  67. }
  68. if pf_accept_orders == "" {
  69. pf_accept_orders = "0"
  70. }
  71. (*wrap.Config).Shop.Price.Format = pfi_price_fomat
  72. (*wrap.Config).Shop.Price.Round = pfi_price_round
  73. (*wrap.Config).Shop.Orders.RequiredFields.LastName = utils.StrToInt(pf_require_last_name)
  74. (*wrap.Config).Shop.Orders.RequiredFields.FirstName = utils.StrToInt(pf_require_first_name)
  75. (*wrap.Config).Shop.Orders.RequiredFields.MiddleName = utils.StrToInt(pf_require_middle_name)
  76. (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone = utils.StrToInt(pf_require_mobile_phone)
  77. (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress = utils.StrToInt(pf_require_email_address)
  78. (*wrap.Config).Shop.Orders.RequiredFields.Delivery = utils.StrToInt(pf_require_delivery)
  79. (*wrap.Config).Shop.Orders.RequiredFields.Comment = utils.StrToInt(pf_require_comment)
  80. if pf_new_order_notify_email != "" {
  81. if utils.IsValidEmail(pf_new_order_notify_email) {
  82. (*wrap.Config).Shop.Orders.NotifyEmail = pf_new_order_notify_email
  83. }
  84. }
  85. (*wrap.Config).Shop.Orders.Enabled = utils.StrToInt(pf_accept_orders)
  86. if err := wrap.ConfigSave(); err != nil {
  87. wrap.MsgError(err.Error())
  88. return
  89. }
  90. wrap.ResetCacheBlocks()
  91. // Reload current page
  92. wrap.Write(`window.location.reload(false);`)
  93. })
  94. }