module_shop_order.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package modules
  2. import (
  3. "strings"
  4. "golang-fave/engine/basket"
  5. "golang-fave/engine/wrapper"
  6. )
  7. func (this *Modules) RegisterAction_ShopOrder() *Action {
  8. return this.newAction(AInfo{
  9. WantDB: true,
  10. Mount: "shop-order",
  11. WantAdmin: false,
  12. }, func(wrap *wrapper.Wrapper) {
  13. if wrap.ShopBasket.ProductsCount(&basket.SBParam{
  14. R: wrap.R,
  15. DB: wrap.DB,
  16. Host: wrap.CurrHost,
  17. Config: wrap.Config,
  18. SessionId: wrap.GetSessionId(),
  19. }) <= 0 {
  20. wrap.Write(`{"error": true, "variable": "ShopOrderErrorBasketEmpty"}`)
  21. return
  22. }
  23. pf_client_last_name := wrap.R.FormValue("client_last_name")
  24. pf_client_first_name := wrap.R.FormValue("client_first_name")
  25. pf_client_second_name := wrap.R.FormValue("client_second_name")
  26. pf_client_phone := wrap.R.FormValue("client_phone")
  27. pf_client_email := wrap.R.FormValue("client_email")
  28. pf_client_delivery_comment := wrap.R.FormValue("client_delivery_comment")
  29. pf_client_order_comment := wrap.R.FormValue("client_order_comment")
  30. if (*wrap.Config).Shop.Orders.RequiredFields.LastName != 0 {
  31. if strings.TrimSpace(pf_client_last_name) == "" {
  32. wrap.Write(`{"error": true, "field": "client_last_name", "variable": "ShopOrderEmptyLastName"}`)
  33. return
  34. }
  35. }
  36. if (*wrap.Config).Shop.Orders.RequiredFields.FirstName != 0 {
  37. if strings.TrimSpace(pf_client_first_name) == "" {
  38. wrap.Write(`{"error": true, "field": "client_first_name", "variable": "ShopOrderEmptyFirstName"}`)
  39. return
  40. }
  41. }
  42. if (*wrap.Config).Shop.Orders.RequiredFields.SecondName != 0 {
  43. if strings.TrimSpace(pf_client_second_name) == "" {
  44. wrap.Write(`{"error": true, "field": "client_second_name", "variable": "ShopOrderEmptySecondName"}`)
  45. return
  46. }
  47. }
  48. if (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone != 0 {
  49. if strings.TrimSpace(pf_client_phone) == "" {
  50. wrap.Write(`{"error": true, "field": "client_phone", "variable": "ShopOrderEmptyMobilePhone"}`)
  51. return
  52. }
  53. }
  54. if (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress != 0 {
  55. if strings.TrimSpace(pf_client_email) == "" {
  56. wrap.Write(`{"error": true, "field": "client_email", "variable": "ShopOrderEmptyEmailAddress"}`)
  57. return
  58. }
  59. }
  60. if (*wrap.Config).Shop.Orders.RequiredFields.Delivery != 0 {
  61. if strings.TrimSpace(pf_client_delivery_comment) == "" {
  62. wrap.Write(`{"error": true, "field": "client_delivery_comment", "variable": "ShopOrderEmptyDelivery"}`)
  63. return
  64. }
  65. }
  66. if (*wrap.Config).Shop.Orders.RequiredFields.Comment != 0 {
  67. if strings.TrimSpace(pf_client_order_comment) == "" {
  68. wrap.Write(`{"error": true, "field": "client_order_comment", "variable": "ShopOrderEmptyComment"}`)
  69. return
  70. }
  71. }
  72. // Clear user basket
  73. wrap.ShopBasket.ClearBasket(&basket.SBParam{
  74. R: wrap.R,
  75. DB: wrap.DB,
  76. Host: wrap.CurrHost,
  77. Config: wrap.Config,
  78. SessionId: wrap.GetSessionId(),
  79. })
  80. wrap.Write(`{"error": false, "field": "", "variable": "ShopOrderSuccess"}`)
  81. return
  82. // if !utils.IsNumeric(pf_id) {
  83. // wrap.MsgError(`Inner system error`)
  84. // return
  85. // }
  86. // if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
  87. // if _, err := tx.Exec(`
  88. // UPDATE shop_products SET
  89. // parent_id = NULL,
  90. // active = 0
  91. // WHERE
  92. // id = ?
  93. // ;`,
  94. // utils.StrToInt(pf_id),
  95. // ); err != nil {
  96. // return err
  97. // }
  98. // return nil
  99. // }); err != nil {
  100. // wrap.MsgError(err.Error())
  101. // return
  102. // }
  103. // wrap.RecreateProductXmlFile()
  104. // wrap.ResetCacheBlocks()
  105. // // Reload current page
  106. // wrap.Write(`window.location.reload(false);`)
  107. })
  108. }