module_settings_act_shop.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package modules
  2. import (
  3. "golang-fave/engine/utils"
  4. "golang-fave/engine/wrapper"
  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 := utils.Trim(wrap.R.FormValue("price-fomat"))
  13. pf_price_round := utils.Trim(wrap.R.FormValue("price-round"))
  14. pf_require_last_name := utils.Trim(wrap.R.FormValue("require-last-name"))
  15. pf_require_first_name := utils.Trim(wrap.R.FormValue("require-first-name"))
  16. pf_require_middle_name := utils.Trim(wrap.R.FormValue("require-middle-name"))
  17. pf_require_mobile_phone := utils.Trim(wrap.R.FormValue("require-mobile-phone"))
  18. pf_require_email_address := utils.Trim(wrap.R.FormValue("require-email-address"))
  19. pf_require_delivery := utils.Trim(wrap.R.FormValue("require-delivery"))
  20. pf_require_comment := utils.Trim(wrap.R.FormValue("require-comment"))
  21. pf_new_order_notify_email := utils.Trim(wrap.R.FormValue("new-order-notify-email"))
  22. pf_new_order_email_theme_cp := utils.Trim(wrap.R.FormValue("new-order-email-theme-cp"))
  23. pf_new_order_email_theme_user := utils.Trim(wrap.R.FormValue("new-order-email-theme-user"))
  24. pf_accept_orders := utils.Trim(wrap.R.FormValue("accept-orders"))
  25. pf_custom_field_1_enabled := utils.Trim(wrap.R.FormValue("custom-field-1-enabled"))
  26. pf_custom_field_1_caption := utils.Trim(wrap.R.FormValue("custom-field-1-caption"))
  27. pf_custom_field_2_enabled := utils.Trim(wrap.R.FormValue("custom-field-2-enabled"))
  28. pf_custom_field_2_caption := utils.Trim(wrap.R.FormValue("custom-field-2-caption"))
  29. if !utils.IsNumeric(pf_price_fomat) {
  30. wrap.MsgError(`Must be integer number`)
  31. return
  32. }
  33. if !utils.IsNumeric(pf_price_round) {
  34. wrap.MsgError(`Must be integer number`)
  35. return
  36. }
  37. pfi_price_fomat := utils.StrToInt(pf_price_fomat)
  38. pfi_price_round := utils.StrToInt(pf_price_round)
  39. // Correct values
  40. if pfi_price_fomat < 0 {
  41. pfi_price_fomat = 0
  42. }
  43. if pfi_price_fomat > 4 {
  44. pfi_price_fomat = 4
  45. }
  46. if pfi_price_round < 0 {
  47. pfi_price_round = 0
  48. }
  49. if pfi_price_round > 2 {
  50. pfi_price_round = 2
  51. }
  52. if pf_require_last_name == "" {
  53. pf_require_last_name = "0"
  54. }
  55. if pf_require_first_name == "" {
  56. pf_require_first_name = "0"
  57. }
  58. if pf_require_middle_name == "" {
  59. pf_require_middle_name = "0"
  60. }
  61. if pf_require_mobile_phone == "" {
  62. pf_require_mobile_phone = "0"
  63. }
  64. if pf_require_email_address == "" {
  65. pf_require_email_address = "0"
  66. }
  67. if pf_require_delivery == "" {
  68. pf_require_delivery = "0"
  69. }
  70. if pf_require_comment == "" {
  71. pf_require_comment = "0"
  72. }
  73. if pf_accept_orders == "" {
  74. pf_accept_orders = "0"
  75. }
  76. (*wrap.Config).Shop.Price.Format = pfi_price_fomat
  77. (*wrap.Config).Shop.Price.Round = pfi_price_round
  78. (*wrap.Config).Shop.Orders.RequiredFields.LastName = utils.StrToInt(pf_require_last_name)
  79. (*wrap.Config).Shop.Orders.RequiredFields.FirstName = utils.StrToInt(pf_require_first_name)
  80. (*wrap.Config).Shop.Orders.RequiredFields.MiddleName = utils.StrToInt(pf_require_middle_name)
  81. (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone = utils.StrToInt(pf_require_mobile_phone)
  82. (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress = utils.StrToInt(pf_require_email_address)
  83. (*wrap.Config).Shop.Orders.RequiredFields.Delivery = utils.StrToInt(pf_require_delivery)
  84. (*wrap.Config).Shop.Orders.RequiredFields.Comment = utils.StrToInt(pf_require_comment)
  85. if pf_new_order_notify_email != "" {
  86. if utils.IsValidEmail(pf_new_order_notify_email) {
  87. (*wrap.Config).Shop.Orders.NotifyEmail = pf_new_order_notify_email
  88. }
  89. } else {
  90. (*wrap.Config).Shop.Orders.NotifyEmail = ""
  91. }
  92. (*wrap.Config).Shop.Orders.NewOrderEmailThemeCp = pf_new_order_email_theme_cp
  93. (*wrap.Config).Shop.Orders.NewOrderEmailThemeUser = pf_new_order_email_theme_user
  94. (*wrap.Config).Shop.Orders.Enabled = utils.StrToInt(pf_accept_orders)
  95. (*wrap.Config).Shop.CustomFields.Field1.Enabled = utils.StrToInt(pf_custom_field_1_enabled)
  96. (*wrap.Config).Shop.CustomFields.Field1.Caption = pf_custom_field_1_caption
  97. (*wrap.Config).Shop.CustomFields.Field2.Enabled = utils.StrToInt(pf_custom_field_2_enabled)
  98. (*wrap.Config).Shop.CustomFields.Field2.Caption = pf_custom_field_2_caption
  99. if err := wrap.ConfigSave(); err != nil {
  100. wrap.MsgError(err.Error())
  101. return
  102. }
  103. wrap.ResetCacheBlocks()
  104. // Reload current page
  105. wrap.Write(`window.location.reload(false);`)
  106. })
  107. }