-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsales_channel.go
193 lines (178 loc) · 8.28 KB
/
sales_channel.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
184
185
186
187
188
189
190
191
192
193
//********************************************************************************************************************//
//
// Copyright (C) 2018 - 2021 J&J Ideenschmiede GmbH <[email protected]>
//
// This file is part of gosw6.
// All code may be used. Feel free and maybe code something better.
//
// Author: Jonas Kwiedor (aka gowizzard)
//
//********************************************************************************************************************//
package gosw6
import (
"encoding/json"
"fmt"
"net/url"
"time"
)
// SalesChannelsReturn is to decode the json return
type SalesChannelsReturn struct {
Total int `json:"total"`
Data []struct {
TypeId string `json:"typeId"`
LanguageId string `json:"languageId"`
CurrencyId string `json:"currencyId"`
PaymentMethodId string `json:"paymentMethodId"`
ShippingMethodId string `json:"shippingMethodId"`
CountryId string `json:"countryId"`
NavigationCategoryId string `json:"navigationCategoryId"`
NavigationCategoryDepth int `json:"navigationCategoryDepth"`
HomeSlotConfig interface{} `json:"homeSlotConfig"`
HomeCmsPageId interface{} `json:"homeCmsPageId"`
HomeCmsPage interface{} `json:"homeCmsPage"`
HomeEnabled bool `json:"homeEnabled"`
HomeName interface{} `json:"homeName"`
HomeMetaTitle interface{} `json:"homeMetaTitle"`
HomeMetaDescription interface{} `json:"homeMetaDescription"`
HomeKeywords interface{} `json:"homeKeywords"`
FooterCategoryId interface{} `json:"footerCategoryId"`
ServiceCategoryId interface{} `json:"serviceCategoryId"`
Name string `json:"name"`
ShortName interface{} `json:"shortName"`
AccessKey string `json:"accessKey"`
Currencies interface{} `json:"currencies"`
Languages interface{} `json:"languages"`
Configuration interface{} `json:"configuration"`
Active bool `json:"active"`
Maintenance bool `json:"maintenance"`
MaintenanceIpWhitelist interface{} `json:"maintenanceIpWhitelist"`
TaxCalculationType string `json:"taxCalculationType"`
Type interface{} `json:"type"`
Currency interface{} `json:"currency"`
Language interface{} `json:"language"`
PaymentMethod interface{} `json:"paymentMethod"`
ShippingMethod interface{} `json:"shippingMethod"`
Country interface{} `json:"country"`
Orders interface{} `json:"orders"`
Customers interface{} `json:"customers"`
Countries interface{} `json:"countries"`
PaymentMethods interface{} `json:"paymentMethods"`
ShippingMethods interface{} `json:"shippingMethods"`
Translations interface{} `json:"translations"`
Domains interface{} `json:"domains"`
SystemConfigs interface{} `json:"systemConfigs"`
NavigationCategory interface{} `json:"navigationCategory"`
FooterCategory interface{} `json:"footerCategory"`
ServiceCategory interface{} `json:"serviceCategory"`
ProductVisibilities interface{} `json:"productVisibilities"`
MailHeaderFooterId interface{} `json:"mailHeaderFooterId"`
NumberRangeSalesChannels interface{} `json:"numberRangeSalesChannels"`
MailHeaderFooter interface{} `json:"mailHeaderFooter"`
CustomerGroupId string `json:"customerGroupId"`
CustomerGroup interface{} `json:"customerGroup"`
NewsletterRecipients interface{} `json:"newsletterRecipients"`
PromotionSalesChannels interface{} `json:"promotionSalesChannels"`
DocumentBaseConfigSalesChannels interface{} `json:"documentBaseConfigSalesChannels"`
ProductReviews interface{} `json:"productReviews"`
SeoUrls interface{} `json:"seoUrls"`
SeoUrlTemplates interface{} `json:"seoUrlTemplates"`
MainCategories interface{} `json:"mainCategories"`
PaymentMethodIds []string `json:"paymentMethodIds"`
ProductExports interface{} `json:"productExports"`
HreflangActive bool `json:"hreflangActive"`
HreflangDefaultDomainId interface{} `json:"hreflangDefaultDomainId"`
HreflangDefaultDomain interface{} `json:"hreflangDefaultDomain"`
AnalyticsId interface{} `json:"analyticsId"`
Analytics interface{} `json:"analytics"`
CustomerGroupsRegistrations interface{} `json:"customerGroupsRegistrations"`
EventActions interface{} `json:"eventActions"`
BoundCustomers interface{} `json:"boundCustomers"`
Wishlists interface{} `json:"wishlists"`
LandingPages interface{} `json:"landingPages"`
UniqueIdentifier string `json:"_uniqueIdentifier"`
VersionId interface{} `json:"versionId"`
Translated struct {
Name string `json:"name"`
CustomFields struct {
} `json:"customFields"`
HomeSlotConfig interface{} `json:"homeSlotConfig"`
HomeEnabled bool `json:"homeEnabled"`
HomeName interface{} `json:"homeName"`
HomeMetaTitle interface{} `json:"homeMetaTitle"`
HomeMetaDescription interface{} `json:"homeMetaDescription"`
HomeKeywords interface{} `json:"homeKeywords"`
} `json:"translated"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt interface{} `json:"updatedAt"`
Extensions struct {
ForeignKeys struct {
ApiAlias interface{} `json:"apiAlias"`
Extensions []interface{} `json:"extensions"`
} `json:"foreignKeys"`
} `json:"extensions"`
Id string `json:"id"`
CustomFields interface{} `json:"customFields"`
NavigationCategoryVersionId string `json:"navigationCategoryVersionId"`
FooterCategoryVersionId *string `json:"footerCategoryVersionId"`
ServiceCategoryVersionId *string `json:"serviceCategoryVersionId"`
HomeCmsPageVersionId *string `json:"homeCmsPageVersionId"`
ApiAlias string `json:"apiAlias"`
} `json:"data"`
Aggregations []interface{} `json:"aggregations"`
Errors []struct {
Code string `json:"code"`
Status string `json:"status"`
Title string `json:"title"`
Detail string `json:"detail"`
Meta struct {
Trace []struct {
File string `json:"file"`
Line int `json:"line"`
Function string `json:"function"`
Class string `json:"class"`
Type string `json:"type"`
} `json:"trace"`
File string `json:"file"`
Line int `json:"line"`
} `json:"meta"`
} `json:"errors"`
}
// SalesChannels is to get a list of all sales channels
func SalesChannels(parameter map[string]string, r Request) (SalesChannelsReturn, error) {
// Set config for request
c := Config{
Path: "/api/sales-channel",
Method: "GET",
Body: nil,
}
// Parse url & add attributes
parse, err := url.Parse(c.Path)
if err != nil {
return SalesChannelsReturn{}, err
}
newUrl, err := url.ParseQuery(parse.RawQuery)
if err != nil {
return SalesChannelsReturn{}, err
}
for index, value := range parameter {
newUrl.Add(index, value)
}
// Set new url
parse.RawQuery = newUrl.Encode()
c.Path = fmt.Sprintf("%s", parse)
// Send request
response, err := c.Send(r)
if err != nil {
return SalesChannelsReturn{}, err
}
// Close request
defer response.Body.Close()
// Decode data
var decode SalesChannelsReturn
err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return SalesChannelsReturn{}, err
}
// Return data
return decode, err
}