module_shop_order.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. // SBParam := basket.SBParam{
  14. // R: wrap.R,
  15. // DB: wrap.DB,
  16. // Host: wrap.CurrHost,
  17. // Config: wrap.Config,
  18. // SessionId: wrap.GetSessionId(),
  19. // }
  20. if wrap.ShopBasket.ProductsCount(&basket.SBParam{
  21. R: wrap.R,
  22. DB: wrap.DB,
  23. Host: wrap.CurrHost,
  24. Config: wrap.Config,
  25. SessionId: wrap.GetSessionId(),
  26. }) <= 0 {
  27. wrap.Write(`{"error": true, "variable": "ShopOrderErrorBasketEmpty"}`)
  28. return
  29. }
  30. pf_client_last_name := wrap.R.FormValue("client_last_name")
  31. pf_client_first_name := wrap.R.FormValue("client_first_name")
  32. pf_client_second_name := wrap.R.FormValue("client_second_name")
  33. pf_client_phone := wrap.R.FormValue("client_phone")
  34. pf_client_email := wrap.R.FormValue("client_email")
  35. pf_client_delivery_comment := wrap.R.FormValue("client_delivery_comment")
  36. pf_client_order_comment := wrap.R.FormValue("client_order_comment")
  37. if strings.TrimSpace(pf_client_last_name) == "" {
  38. wrap.Write(`{"error": true, "field": "client_last_name", "variable": "ShopOrderEmptyLastName"}`)
  39. return
  40. }
  41. if strings.TrimSpace(pf_client_first_name) == "" {
  42. wrap.Write(`{"error": true, "field": "client_first_name", "variable": "ShopOrderEmptyFirstName"}`)
  43. return
  44. }
  45. if strings.TrimSpace(pf_client_second_name) == "" {
  46. wrap.Write(`{"error": true, "field": "client_second_name", "variable": "ShopOrderEmptySecondName"}`)
  47. return
  48. }
  49. if strings.TrimSpace(pf_client_phone) == "" {
  50. wrap.Write(`{"error": true, "field": "client_phone", "variable": "ShopOrderEmptyMobilePhone"}`)
  51. return
  52. }
  53. if strings.TrimSpace(pf_client_email) == "" {
  54. wrap.Write(`{"error": true, "field": "client_email", "variable": "ShopOrderEmptyEmailAddress"}`)
  55. return
  56. }
  57. if strings.TrimSpace(pf_client_delivery_comment) == "" {
  58. wrap.Write(`{"error": true, "field": "client_delivery_comment", "variable": "ShopOrderEmptyDelivery"}`)
  59. return
  60. }
  61. if strings.TrimSpace(pf_client_order_comment) == "" {
  62. wrap.Write(`{"error": true, "field": "client_order_comment", "variable": "ShopOrderEmptyComment"}`)
  63. return
  64. }
  65. // Clear user basket
  66. wrap.ShopBasket.ClearBasket(&basket.SBParam{
  67. R: wrap.R,
  68. DB: wrap.DB,
  69. Host: wrap.CurrHost,
  70. Config: wrap.Config,
  71. SessionId: wrap.GetSessionId(),
  72. })
  73. wrap.Write(`{"error": false, "field": "", "variable": "ShopOrderSuccess"}`)
  74. return
  75. // if !utils.IsNumeric(pf_id) {
  76. // wrap.MsgError(`Inner system error`)
  77. // return
  78. // }
  79. // if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
  80. // if _, err := tx.Exec(`
  81. // UPDATE shop_products SET
  82. // parent_id = NULL,
  83. // active = 0
  84. // WHERE
  85. // id = ?
  86. // ;`,
  87. // utils.StrToInt(pf_id),
  88. // ); err != nil {
  89. // return err
  90. // }
  91. // return nil
  92. // }); err != nil {
  93. // wrap.MsgError(err.Error())
  94. // return
  95. // }
  96. // wrap.RecreateProductXmlFile()
  97. // wrap.ResetCacheBlocks()
  98. // // Reload current page
  99. // wrap.Write(`window.location.reload(false);`)
  100. })
  101. }