module_shop_order.go 3.1 KB

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