module_shop_act_detach.go 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package modules
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. func (this *Modules) RegisterAction_ShopDetach() *Action {
  7. return this.newAction(AInfo{
  8. WantDB: true,
  9. Mount: "shop-detach",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_id := wrap.R.FormValue("id")
  13. if !utils.IsNumeric(pf_id) {
  14. wrap.MsgError(`Inner system error`)
  15. return
  16. }
  17. if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
  18. if _, err := tx.Exec(`
  19. UPDATE shop_products SET
  20. parent_id = NULL
  21. WHERE
  22. id = ?;
  23. `,
  24. utils.StrToInt(pf_id),
  25. ); err != nil {
  26. return err
  27. }
  28. return nil
  29. }); err != nil {
  30. wrap.MsgError(err.Error())
  31. return
  32. }
  33. wrap.RecreateProductXmlFile()
  34. wrap.ResetCacheBlocks()
  35. // Reload current page
  36. wrap.Write(`window.location.reload(false);`)
  37. })
  38. }