forked from labd/commercetools-go-sdk
/
client_replicate_by_project_key_carts_replicate_post.go
83 lines (75 loc) · 2.29 KB
/
client_replicate_by_project_key_carts_replicate_post.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
package platform
// Generated file, please do not change!!!
import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type ByProjectKeyCartsReplicateRequestMethodPost struct {
body ReplicaCartDraft
url string
client *Client
headers http.Header
}
func (r *ByProjectKeyCartsReplicateRequestMethodPost) Dump() map[string]interface{} {
return map[string]interface{}{
"url": r.url,
}
}
func (rb *ByProjectKeyCartsReplicateRequestMethodPost) WithHeaders(headers http.Header) *ByProjectKeyCartsReplicateRequestMethodPost {
rb.headers = headers
return rb
}
/**
* Creates a new Cart by replicating an existing Cart or Order. Can be useful in cases where a customer wants to cancel a recent order to make some changes or reorder a previous order.
*
* The replicated Cart preserves Customer information, Line Items and Custom Line Items, Custom Fields, Discount Codes, and other settings of the Cart or Order. If the Line Items become invalid, for example, due to removed Products or Prices, they are removed from the new Cart. If the Customer switches to another Customer Group, the new Cart is updated with the new value. It has up-to-date Tax Rates, Prices, and Line Item product data and is in `Active` [CartState](ctp:api:type:CartState).
*
* The new Cart does not contain Payments or Deliveries. The [State](ctp:api:type:ItemState) of Line Items and Custom Line Items is reset to `initial`.
*
*/
func (rb *ByProjectKeyCartsReplicateRequestMethodPost) Execute(ctx context.Context) (result *Cart, err error) {
data, err := serializeInput(rb.body)
if err != nil {
return nil, err
}
queryParams := url.Values{}
resp, err := rb.client.post(
ctx,
rb.url,
queryParams,
rb.headers,
data,
)
if err != nil {
return nil, err
}
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
defer resp.Body.Close()
switch resp.StatusCode {
case 201:
err = json.Unmarshal(content, &result)
return result, nil
case 400, 401, 403, 500, 502, 503:
errorObj := ErrorResponse{}
err = json.Unmarshal(content, &errorObj)
if err != nil {
return nil, err
}
return nil, errorObj
case 404:
return nil, ErrNotFound
default:
result := GenericRequestError{
StatusCode: resp.StatusCode,
Content: content,
Response: resp,
}
return nil, result
}
}