1
|
|
|
const ApiService = Shopware.Classes.ApiService; |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Gateway for the API endpoint "promotion codes" |
5
|
|
|
* @class |
6
|
|
|
* @extends ApiService |
7
|
|
|
*/ |
8
|
|
|
export default class PromotionCodeApiService extends ApiService { |
9
|
|
|
constructor(httpClient, loginService, apiEndpoint = 'promotion') { |
10
|
|
|
super(httpClient, loginService, apiEndpoint); |
11
|
|
|
this.name = 'promotionCodeApiService'; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @returns {Promise<T>} |
16
|
|
|
*/ |
17
|
|
|
generateCodeFixed() { |
18
|
|
|
const headers = this.getBasicHeaders(); |
19
|
|
|
|
20
|
|
|
return this.httpClient.get( |
21
|
|
|
`/_action/${this.getApiBasePath()}/codes/generate-fixed`, |
22
|
|
|
{ |
23
|
|
|
headers |
24
|
|
|
} |
25
|
|
|
).then((response) => { |
26
|
|
|
return ApiService.handleResponse(response); |
27
|
|
|
}); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param {String} codePattern |
32
|
|
|
* @param {Number} amount |
33
|
|
|
* |
34
|
|
|
* @returns {Promise<T>} |
35
|
|
|
*/ |
36
|
|
|
generateIndividualCodes(codePattern, amount = 1) { |
37
|
|
|
const headers = this.getBasicHeaders(); |
38
|
|
|
|
39
|
|
|
return this.httpClient.get( |
40
|
|
|
`/_action/${this.getApiBasePath()}/codes/generate-individual`, |
41
|
|
|
{ |
42
|
|
|
params: { codePattern, amount }, |
43
|
|
|
headers |
44
|
|
|
} |
45
|
|
|
).then((response) => { |
46
|
|
|
return ApiService.handleResponse(response); |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param {String} promotionId |
52
|
|
|
* @param {Number} amount |
53
|
|
|
* |
54
|
|
|
* @returns {Promise<T>} |
55
|
|
|
*/ |
56
|
|
|
addIndividualCodes(promotionId, amount) { |
57
|
|
|
const headers = this.getBasicHeaders(); |
58
|
|
|
|
59
|
|
|
return this.httpClient.post( |
60
|
|
|
`/_action/${this.getApiBasePath()}/codes/add-individual`, |
61
|
|
|
{ |
62
|
|
|
promotionId, |
63
|
|
|
amount |
64
|
|
|
}, |
65
|
|
|
{ |
66
|
|
|
headers |
67
|
|
|
} |
68
|
|
|
).then((response) => { |
69
|
|
|
return ApiService.handleResponse(response); |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param {String} promotionId |
75
|
|
|
* @param {String} codePattern |
76
|
|
|
* @param {Number} amount |
77
|
|
|
* |
78
|
|
|
* @returns {Promise<T>} |
79
|
|
|
*/ |
80
|
|
|
replaceIndividualCodes(promotionId, codePattern, amount = 1) { |
81
|
|
|
const headers = this.getBasicHeaders(); |
82
|
|
|
|
83
|
|
|
return this.httpClient.patch( |
84
|
|
|
`/_action/${this.getApiBasePath()}/codes/replace-individual`, |
85
|
|
|
{ |
86
|
|
|
promotionId, |
87
|
|
|
codePattern, |
88
|
|
|
amount |
89
|
|
|
}, |
90
|
|
|
{ |
91
|
|
|
headers |
92
|
|
|
} |
93
|
|
|
).then((response) => { |
94
|
|
|
return ApiService.handleResponse(response); |
95
|
|
|
}); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param {String} codePattern |
100
|
|
|
* |
101
|
|
|
* @returns {Promise<T>} |
102
|
|
|
*/ |
103
|
|
|
generatePreview(codePattern) { |
104
|
|
|
const headers = this.getBasicHeaders(); |
105
|
|
|
|
106
|
|
|
return this.httpClient.get( |
107
|
|
|
`/_action/${this.getApiBasePath()}/codes/preview`, |
108
|
|
|
{ |
109
|
|
|
params: { codePattern }, |
110
|
|
|
headers |
111
|
|
|
} |
112
|
|
|
).then((response) => { |
113
|
|
|
return ApiService.handleResponse(response); |
114
|
|
|
}); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.