1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Commercetools\Core\Builder\Update; |
4
|
|
|
|
5
|
|
|
use Commercetools\Core\Error\InvalidArgumentException; |
6
|
|
|
use Commercetools\Core\Request\AbstractAction; |
7
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerAddAddressAction; |
8
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerAddBillingAddressAction; |
9
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerAddShippingAddressAction; |
10
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerChangeAddressAction; |
11
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerChangeEmailAction; |
12
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerRemoveAddressAction; |
13
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerRemoveBillingAddressAction; |
14
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerRemoveShippingAddressAction; |
15
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetCompanyNameAction; |
16
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetCustomFieldAction; |
17
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetCustomTypeAction; |
18
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetCustomerGroupAction; |
19
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetCustomerNumberAction; |
20
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetDateOfBirthAction; |
21
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetDefaultBillingAddressAction; |
22
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetDefaultShippingAddressAction; |
23
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetExternalIdAction; |
24
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetFirstNameAction; |
25
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetKeyAction; |
26
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetLastNameAction; |
27
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetLocaleAction; |
28
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetMiddleNameAction; |
29
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetSalutationAction; |
30
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetTitleAction; |
31
|
|
|
use Commercetools\Core\Request\Customers\Command\CustomerSetVatIdAction; |
32
|
|
|
|
33
|
|
|
class CustomersActionBuilder |
34
|
|
|
{ |
35
|
|
|
private $actions = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#add-address |
39
|
|
|
* @param CustomerAddAddressAction|callable $action |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
1 |
|
public function addAddress($action = null) |
43
|
|
|
{ |
44
|
1 |
|
$this->addAction($this->resolveAction(CustomerAddAddressAction::class, $action)); |
45
|
1 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#add-billing-address-id |
50
|
|
|
* @param CustomerAddBillingAddressAction|callable $action |
51
|
|
|
* @return $this |
52
|
|
|
*/ |
53
|
1 |
|
public function addBillingAddressId($action = null) |
54
|
|
|
{ |
55
|
1 |
|
$this->addAction($this->resolveAction(CustomerAddBillingAddressAction::class, $action)); |
56
|
1 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#add-billing-address-id |
61
|
|
|
* @param CustomerAddShippingAddressAction|callable $action |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
1 |
|
public function addShippingAddressId($action = null) |
65
|
|
|
{ |
66
|
1 |
|
$this->addAction($this->resolveAction(CustomerAddShippingAddressAction::class, $action)); |
67
|
1 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#change-address |
72
|
|
|
* @param CustomerChangeAddressAction|callable $action |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
1 |
|
public function changeAddress($action = null) |
76
|
|
|
{ |
77
|
1 |
|
$this->addAction($this->resolveAction(CustomerChangeAddressAction::class, $action)); |
78
|
1 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#change-email |
83
|
|
|
* @param CustomerChangeEmailAction|callable $action |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
1 |
|
public function changeEmail($action = null) |
87
|
|
|
{ |
88
|
1 |
|
$this->addAction($this->resolveAction(CustomerChangeEmailAction::class, $action)); |
89
|
1 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#remove-address |
94
|
|
|
* @param CustomerRemoveAddressAction|callable $action |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
1 |
|
public function removeAddress($action = null) |
98
|
|
|
{ |
99
|
1 |
|
$this->addAction($this->resolveAction(CustomerRemoveAddressAction::class, $action)); |
100
|
1 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#add-billing-address-id |
105
|
|
|
* @param CustomerRemoveBillingAddressAction|callable $action |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
1 |
|
public function removeBillingAddressId($action = null) |
109
|
|
|
{ |
110
|
1 |
|
$this->addAction($this->resolveAction(CustomerRemoveBillingAddressAction::class, $action)); |
111
|
1 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#add-billing-address-id |
116
|
|
|
* @param CustomerRemoveShippingAddressAction|callable $action |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
1 |
|
public function removeShippingAddressId($action = null) |
120
|
|
|
{ |
121
|
1 |
|
$this->addAction($this->resolveAction(CustomerRemoveShippingAddressAction::class, $action)); |
122
|
1 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-company-name |
127
|
|
|
* @param CustomerSetCompanyNameAction|callable $action |
128
|
|
|
* @return $this |
129
|
|
|
*/ |
130
|
1 |
|
public function setCompanyName($action = null) |
131
|
|
|
{ |
132
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetCompanyNameAction::class, $action)); |
133
|
1 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* |
138
|
|
|
* @param CustomerSetCustomFieldAction|callable $action |
139
|
|
|
* @return $this |
140
|
|
|
*/ |
141
|
1 |
|
public function setCustomField($action = null) |
142
|
|
|
{ |
143
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetCustomFieldAction::class, $action)); |
144
|
1 |
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* |
149
|
|
|
* @param CustomerSetCustomTypeAction|callable $action |
150
|
|
|
* @return $this |
151
|
|
|
*/ |
152
|
1 |
|
public function setCustomType($action = null) |
153
|
|
|
{ |
154
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetCustomTypeAction::class, $action)); |
155
|
1 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-customergroup |
160
|
|
|
* @param CustomerSetCustomerGroupAction|callable $action |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
1 |
|
public function setCustomerGroup($action = null) |
164
|
|
|
{ |
165
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetCustomerGroupAction::class, $action)); |
166
|
1 |
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-customer-number |
171
|
|
|
* @param CustomerSetCustomerNumberAction|callable $action |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
1 |
|
public function setCustomerNumber($action = null) |
175
|
|
|
{ |
176
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetCustomerNumberAction::class, $action)); |
177
|
1 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-date-of-birth |
182
|
|
|
* @param CustomerSetDateOfBirthAction|callable $action |
183
|
|
|
* @return $this |
184
|
|
|
*/ |
185
|
1 |
|
public function setDateOfBirth($action = null) |
186
|
|
|
{ |
187
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetDateOfBirthAction::class, $action)); |
188
|
1 |
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-default-billing-address |
193
|
|
|
* @param CustomerSetDefaultBillingAddressAction|callable $action |
194
|
|
|
* @return $this |
195
|
|
|
*/ |
196
|
1 |
|
public function setDefaultBillingAddress($action = null) |
197
|
|
|
{ |
198
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetDefaultBillingAddressAction::class, $action)); |
199
|
1 |
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-default-shipping-address |
204
|
|
|
* @param CustomerSetDefaultShippingAddressAction|callable $action |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
1 |
|
public function setDefaultShippingAddress($action = null) |
208
|
|
|
{ |
209
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetDefaultShippingAddressAction::class, $action)); |
210
|
1 |
|
return $this; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-external-id |
215
|
|
|
* @param CustomerSetExternalIdAction|callable $action |
216
|
|
|
* @return $this |
217
|
|
|
*/ |
218
|
1 |
|
public function setExternalId($action = null) |
219
|
|
|
{ |
220
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetExternalIdAction::class, $action)); |
221
|
1 |
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-first-name |
226
|
|
|
* @param CustomerSetFirstNameAction|callable $action |
227
|
|
|
* @return $this |
228
|
|
|
*/ |
229
|
1 |
|
public function setFirstName($action = null) |
230
|
|
|
{ |
231
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetFirstNameAction::class, $action)); |
232
|
1 |
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-key |
237
|
|
|
* @param CustomerSetKeyAction|callable $action |
238
|
|
|
* @return $this |
239
|
|
|
*/ |
240
|
1 |
|
public function setKey($action = null) |
241
|
|
|
{ |
242
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetKeyAction::class, $action)); |
243
|
1 |
|
return $this; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-last-name |
248
|
|
|
* @param CustomerSetLastNameAction|callable $action |
249
|
|
|
* @return $this |
250
|
|
|
*/ |
251
|
1 |
|
public function setLastName($action = null) |
252
|
|
|
{ |
253
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetLastNameAction::class, $action)); |
254
|
1 |
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-locale |
259
|
|
|
* @param CustomerSetLocaleAction|callable $action |
260
|
|
|
* @return $this |
261
|
|
|
*/ |
262
|
1 |
|
public function setLocale($action = null) |
263
|
|
|
{ |
264
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetLocaleAction::class, $action)); |
265
|
1 |
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-middle-name |
270
|
|
|
* @param CustomerSetMiddleNameAction|callable $action |
271
|
|
|
* @return $this |
272
|
|
|
*/ |
273
|
1 |
|
public function setMiddleName($action = null) |
274
|
|
|
{ |
275
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetMiddleNameAction::class, $action)); |
276
|
1 |
|
return $this; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-salutation |
281
|
|
|
* @param CustomerSetSalutationAction|callable $action |
282
|
|
|
* @return $this |
283
|
|
|
*/ |
284
|
1 |
|
public function setSalutation($action = null) |
285
|
|
|
{ |
286
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetSalutationAction::class, $action)); |
287
|
1 |
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-title |
292
|
|
|
* @param CustomerSetTitleAction|callable $action |
293
|
|
|
* @return $this |
294
|
|
|
*/ |
295
|
1 |
|
public function setTitle($action = null) |
296
|
|
|
{ |
297
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetTitleAction::class, $action)); |
298
|
1 |
|
return $this; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#set-vat-id |
303
|
|
|
* @param CustomerSetVatIdAction|callable $action |
304
|
|
|
* @return $this |
305
|
|
|
*/ |
306
|
1 |
|
public function setVatId($action = null) |
307
|
|
|
{ |
308
|
1 |
|
$this->addAction($this->resolveAction(CustomerSetVatIdAction::class, $action)); |
309
|
1 |
|
return $this; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @return CustomersActionBuilder |
314
|
|
|
*/ |
315
|
|
|
public function of() |
316
|
|
|
{ |
317
|
|
|
return new self(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @param $class |
322
|
|
|
* @param $action |
323
|
|
|
* @return AbstractAction |
324
|
|
|
* @throws InvalidArgumentException |
325
|
|
|
*/ |
326
|
25 |
|
private function resolveAction($class, $action = null) |
327
|
|
|
{ |
328
|
25 |
|
if (is_null($action) || is_callable($action)) { |
329
|
25 |
|
$callback = $action; |
330
|
25 |
|
$emptyAction = $class::of(); |
331
|
25 |
|
$action = $this->callback($emptyAction, $callback); |
332
|
|
|
} |
333
|
25 |
|
if ($action instanceof $class) { |
334
|
25 |
|
return $action; |
335
|
|
|
} |
336
|
|
|
throw new InvalidArgumentException( |
337
|
|
|
sprintf('Expected method to be called with or callable to return %s', $class) |
338
|
|
|
); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @param $action |
343
|
|
|
* @param callable $callback |
344
|
|
|
* @return AbstractAction |
345
|
|
|
*/ |
346
|
25 |
|
private function callback($action, callable $callback = null) |
347
|
|
|
{ |
348
|
25 |
|
if (!is_null($callback)) { |
349
|
|
|
$action = $callback($action); |
350
|
|
|
} |
351
|
25 |
|
return $action; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @param AbstractAction $action |
356
|
|
|
* @return $this; |
357
|
|
|
*/ |
358
|
25 |
|
public function addAction(AbstractAction $action) |
359
|
|
|
{ |
360
|
25 |
|
$this->actions[] = $action; |
361
|
25 |
|
return $this; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @return array |
366
|
|
|
*/ |
367
|
25 |
|
public function getActions() |
368
|
|
|
{ |
369
|
25 |
|
return $this->actions; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @param array $actions |
374
|
|
|
* @return $this |
375
|
|
|
*/ |
376
|
|
|
public function setActions(array $actions) |
377
|
|
|
{ |
378
|
|
|
$this->actions = $actions; |
379
|
|
|
return $this; |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|