-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
183 lines (158 loc) · 5.12 KB
/
config.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package usps
import (
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/utils"
"github.com/ottemo/commerce/app/models"
)
// setupConfig setups package configuration values for a system
func setupConfig() error {
if config := env.GetConfig(); config != nil {
err := config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathGroup,
Value: nil,
Type: env.ConstConfigTypeGroup,
Editor: "",
Options: nil,
Label: "USPS",
Description: "USPS - The United States Postal Service",
Image: "https://www.usps.com/ContentTemplates/assets/images/global/usps_logo.gif",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathEnabled,
Value: false,
Type: env.ConstConfigTypeBoolean,
Editor: "boolean",
Options: nil,
Label: "Enabled",
Description: "enables/disables shipping method for storefront",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathUser,
Value: nil,
Type: env.ConstConfigTypeText,
Editor: "line_editor",
Options: nil,
Label: "USERID",
Description: "Account ID to use in USPS API",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathOriginZip,
Value: nil,
Type: env.ConstConfigTypeText,
Editor: "line_editor",
Options: nil,
Label: "Origin zip",
Description: "shipping origin zip code - needed for price calculation",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathContainer,
Value: "VARIABLE",
Type: env.ConstConfigTypeVarchar,
Editor: "select",
Options: "{'VARIABLE': 'Variable', 'RECTANGULAR': 'Rectangular', 'NONRECTANGULAR': 'Not rectangular'}",
Label: "Container",
Description: "Container type will be sent to USPS service",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathSize,
Value: "REGULAR",
Type: env.ConstConfigTypeVarchar,
Editor: "select",
Options: "{'REGULAR': 'Regular', 'LARGE': 'Large'}",
Label: "Size",
Description: "Package size will be sent to USPS service. Regular - dimensions are 12’’ or less; Large - dimensions must be specified in manually",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathDefaultDimensions,
Value: "1.0 x 1.0 x 1.0 x 1.0",
Type: env.ConstConfigTypeVarchar,
Editor: "dimensions",
Options: nil,
Label: "Default dimensions",
Description: "Will be used if product dimension are not specified (width x length x height x girth - in inches)",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathDefaultWeight,
Value: 0.1,
Type: env.ConstConfigTypeDecimal,
Editor: "decimal",
Options: nil,
Label: "Default weight",
Description: "Will be used if product do not have this value (in pounds)",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathAllowedMethods,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "multi_select",
Options: ConstShippingMethods,
Label: "Allowed methods",
Description: "To customer will be proposed only allowed methods",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathDebugLog,
Value: false,
Type: env.ConstConfigTypeBoolean,
Editor: "boolean",
Options: nil,
Label: "Debug log",
Description: "enables/disables shipping method debug log",
Image: "",
}, func(value interface{}) (interface{}, error) { return utils.InterfaceToBool(value), nil })
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathAllowCountries,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "multi_select",
Options: utils.EncodeToJSONString(models.ConstCountriesList),
Label: "Allow countries",
Description: "",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
} else {
err := env.ErrorNew(ConstErrorModule, env.ConstErrorLevelStartStop, "91775c4b-521a-49f3-90bf-c377f266b62e", "Unable to obtain configuration for USPS")
return env.ErrorDispatch(err)
}
return nil
}