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