/
views_shipping.go
62 lines (50 loc) · 1.21 KB
/
views_shipping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package marketplace
import (
"github.com/gocraft/web"
"net/http"
"strconv"
)
func (c *Context) SaveShippingOption(w web.ResponseWriter, r *web.Request) {
var (
name = r.FormValue("name")
priceUsdStr = r.FormValue("price")
)
priceFloat, err := strconv.ParseFloat(priceUsdStr, 64)
if err != nil {
http.NotFound(w, r.Request)
return
}
shippingOption := ShippingOption{
Name: name,
PriceUSD: priceFloat,
StoreUuid: c.ViewUserStore.Uuid,
}
err = shippingOption.Save()
if err != nil {
http.NotFound(w, r.Request)
return
}
http.Redirect(w, r.Request, "/settings/store?section=vendor", 302)
}
func (c *Context) DeleteShippingOption(w web.ResponseWriter, r *web.Request) {
idint, err := strconv.ParseInt(r.FormValue("id"), 10, 64)
if err != nil {
http.NotFound(w, r.Request)
return
}
option, err := FindShippingOptionById(uint(idint))
if err != nil {
http.NotFound(w, r.Request)
return
}
if option.StoreUuid != c.ViewUserStore.Uuid && !c.ViewUser.IsAdmin && !c.ViewUser.IsStaff {
http.NotFound(w, r.Request)
return
}
err = option.Remove()
if err != nil {
http.NotFound(w, r.Request)
return
}
http.Redirect(w, r.Request, "/settings/store?section=vendor", 302)
}