module_settings_act_shop.go 4.4 KB

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