Passed
Push — develop ( 1795ba...79eaf3 )
by Jens
25:35 queued 03:06
created

CartsActionBuilder::setLineItemCustomField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\Carts\Command\CartAddCustomLineItemAction;
8
use Commercetools\Core\Request\Carts\Command\CartAddDiscountCodeAction;
9
use Commercetools\Core\Request\Carts\Command\CartAddItemShippingAddressAction;
10
use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction;
11
use Commercetools\Core\Request\Carts\Command\CartAddPaymentAction;
12
use Commercetools\Core\Request\Carts\Command\CartAddShoppingListAction;
13
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction;
14
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToLineItemShippingDetailsTargetsAction;
15
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemMoneyAction;
16
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemQuantityAction;
17
use Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction;
18
use Commercetools\Core\Request\Carts\Command\CartChangeTaxCalculationModeAction;
19
use Commercetools\Core\Request\Carts\Command\CartChangeTaxModeAction;
20
use Commercetools\Core\Request\Carts\Command\CartChangeTaxRoundingModeAction;
21
use Commercetools\Core\Request\Carts\Command\CartRecalculateAction;
22
use Commercetools\Core\Request\Carts\Command\CartRemoveCustomLineItemAction;
23
use Commercetools\Core\Request\Carts\Command\CartRemoveDiscountCodeAction;
24
use Commercetools\Core\Request\Carts\Command\CartRemoveItemShippingAddressAction;
25
use Commercetools\Core\Request\Carts\Command\CartRemoveLineItemAction;
26
use Commercetools\Core\Request\Carts\Command\CartRemovePaymentAction;
27
use Commercetools\Core\Request\Carts\Command\CartSetAnonymousIdAction;
28
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressAction;
29
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressCustomFieldAction;
30
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressCustomTypeAction;
31
use Commercetools\Core\Request\Carts\Command\CartSetCartTotalTaxAction;
32
use Commercetools\Core\Request\Carts\Command\CartSetCountryAction;
33
use Commercetools\Core\Request\Carts\Command\CartSetCustomFieldAction;
34
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomFieldAction;
35
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomTypeAction;
36
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemShippingDetailsAction;
37
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxAmountAction;
38
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxRateAction;
39
use Commercetools\Core\Request\Carts\Command\CartSetCustomShippingMethodAction;
40
use Commercetools\Core\Request\Carts\Command\CartSetCustomTypeAction;
41
use Commercetools\Core\Request\Carts\Command\CartSetCustomerEmailAction;
42
use Commercetools\Core\Request\Carts\Command\CartSetCustomerGroupAction;
43
use Commercetools\Core\Request\Carts\Command\CartSetCustomerIdAction;
44
use Commercetools\Core\Request\Carts\Command\CartSetDeleteDaysAfterLastModificationAction;
45
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomFieldAction;
46
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomTypeAction;
47
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction;
48
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction;
49
use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction;
50
use Commercetools\Core\Request\Carts\Command\CartSetLineItemShippingDetailsAction;
51
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction;
52
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxRateAction;
53
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction;
54
use Commercetools\Core\Request\Carts\Command\CartSetLocaleAction;
55
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressAction;
56
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressCustomFieldAction;
57
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressCustomTypeAction;
58
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodAction;
59
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxAmountAction;
60
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxRateAction;
61
use Commercetools\Core\Request\Carts\Command\CartSetShippingRateInputAction;
62
use Commercetools\Core\Request\Carts\Command\CartUpdateItemShippingAddressAction;
63
64
class CartsActionBuilder
65
{
66
    private $actions = [];
67
68
    /**
69
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-customlineitem
70
     * @param CartAddCustomLineItemAction|callable $action
71
     * @return $this
72
     */
73 1
    public function addCustomLineItem($action = null)
74
    {
75 1
        $this->addAction($this->resolveAction(CartAddCustomLineItemAction::class, $action));
76 1
        return $this;
77
    }
78
79
    /**
80
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-discountcode
81
     * @param CartAddDiscountCodeAction|callable $action
82
     * @return $this
83
     */
84 1
    public function addDiscountCode($action = null)
85
    {
86 1
        $this->addAction($this->resolveAction(CartAddDiscountCodeAction::class, $action));
87 1
        return $this;
88
    }
89
90
    /**
91
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-itemshippingaddress
92
     * @param CartAddItemShippingAddressAction|callable $action
93
     * @return $this
94
     */
95 1
    public function addItemShippingAddress($action = null)
96
    {
97 1
        $this->addAction($this->resolveAction(CartAddItemShippingAddressAction::class, $action));
98 1
        return $this;
99
    }
100
101
    /**
102
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-lineitem
103
     * @param CartAddLineItemAction|callable $action
104
     * @return $this
105
     */
106 1
    public function addLineItem($action = null)
107
    {
108 1
        $this->addAction($this->resolveAction(CartAddLineItemAction::class, $action));
109 1
        return $this;
110
    }
111
112
    /**
113
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-payment
114
     * @param CartAddPaymentAction|callable $action
115
     * @return $this
116
     */
117 1
    public function addPayment($action = null)
118
    {
119 1
        $this->addAction($this->resolveAction(CartAddPaymentAction::class, $action));
120 1
        return $this;
121
    }
122
123
    /**
124
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-shoppinglist
125
     * @param CartAddShoppingListAction|callable $action
126
     * @return $this
127
     */
128 1
    public function addShoppingList($action = null)
129
    {
130 1
        $this->addAction($this->resolveAction(CartAddShoppingListAction::class, $action));
131 1
        return $this;
132
    }
133
134
    /**
135
     * @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatocustomlineitemshippingdetailstargets
136
     * @param CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction|callable $action
137
     * @return $this
138
     */
139 1
    public function applyDeltaToCustomLineItemShippingDetailsTargets($action = null)
140
    {
141
        // phpcs:ignore
142 1
        $this->addAction($this->resolveAction(CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction::class, $action));
143 1
        return $this;
144
    }
145
146
    /**
147
     * @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatolineitemshippingdetailstargets
148
     * @param CartApplyDeltaToLineItemShippingDetailsTargetsAction|callable $action
149
     * @return $this
150
     */
151 1
    public function applyDeltaToLineItemShippingDetailsTargets($action = null)
152
    {
153 1
        $this->addAction($this->resolveAction(CartApplyDeltaToLineItemShippingDetailsTargetsAction::class, $action));
154 1
        return $this;
155
    }
156
157
    /**
158
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-money
159
     * @param CartChangeCustomLineItemMoneyAction|callable $action
160
     * @return $this
161
     */
162 1
    public function changeCustomLineItemMoney($action = null)
163
    {
164 1
        $this->addAction($this->resolveAction(CartChangeCustomLineItemMoneyAction::class, $action));
165 1
        return $this;
166
    }
167
168
    /**
169
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-quantity
170
     * @param CartChangeCustomLineItemQuantityAction|callable $action
171
     * @return $this
172
     */
173 1
    public function changeCustomLineItemQuantity($action = null)
174
    {
175 1
        $this->addAction($this->resolveAction(CartChangeCustomLineItemQuantityAction::class, $action));
176 1
        return $this;
177
    }
178
179
    /**
180
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-lineitem-quantity
181
     * @param CartChangeLineItemQuantityAction|callable $action
182
     * @return $this
183
     */
184 1
    public function changeLineItemQuantity($action = null)
185
    {
186 1
        $this->addAction($this->resolveAction(CartChangeLineItemQuantityAction::class, $action));
187 1
        return $this;
188
    }
189
190
    /**
191
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-tax-calculationmode
192
     * @param CartChangeTaxCalculationModeAction|callable $action
193
     * @return $this
194
     */
195 1
    public function changeTaxCalculationMode($action = null)
196
    {
197 1
        $this->addAction($this->resolveAction(CartChangeTaxCalculationModeAction::class, $action));
198 1
        return $this;
199
    }
200
201
    /**
202
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-taxmode
203
     * @param CartChangeTaxModeAction|callable $action
204
     * @return $this
205
     */
206 1
    public function changeTaxMode($action = null)
207
    {
208 1
        $this->addAction($this->resolveAction(CartChangeTaxModeAction::class, $action));
209 1
        return $this;
210
    }
211
212
    /**
213
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-tax-roundingmode
214
     * @param CartChangeTaxRoundingModeAction|callable $action
215
     * @return $this
216
     */
217 1
    public function changeTaxRoundingMode($action = null)
218
    {
219 1
        $this->addAction($this->resolveAction(CartChangeTaxRoundingModeAction::class, $action));
220 1
        return $this;
221
    }
222
223
    /**
224
     * @link https://docs.commercetools.com/http-api-projects-carts.html#recalculate
225
     * @param CartRecalculateAction|callable $action
226
     * @return $this
227
     */
228 1
    public function recalculate($action = null)
229
    {
230 1
        $this->addAction($this->resolveAction(CartRecalculateAction::class, $action));
231 1
        return $this;
232
    }
233
234
    /**
235
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-customlineitem
236
     * @param CartRemoveCustomLineItemAction|callable $action
237
     * @return $this
238
     */
239 1
    public function removeCustomLineItem($action = null)
240
    {
241 1
        $this->addAction($this->resolveAction(CartRemoveCustomLineItemAction::class, $action));
242 1
        return $this;
243
    }
244
245
    /**
246
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-discountcode
247
     * @param CartRemoveDiscountCodeAction|callable $action
248
     * @return $this
249
     */
250 1
    public function removeDiscountCode($action = null)
251
    {
252 1
        $this->addAction($this->resolveAction(CartRemoveDiscountCodeAction::class, $action));
253 1
        return $this;
254
    }
255
256
    /**
257
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-itemshippingaddress
258
     * @param CartRemoveItemShippingAddressAction|callable $action
259
     * @return $this
260
     */
261 1
    public function removeItemShippingAddress($action = null)
262
    {
263 1
        $this->addAction($this->resolveAction(CartRemoveItemShippingAddressAction::class, $action));
264 1
        return $this;
265
    }
266
267
    /**
268
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-lineitem
269
     * @param CartRemoveLineItemAction|callable $action
270
     * @return $this
271
     */
272 1
    public function removeLineItem($action = null)
273
    {
274 1
        $this->addAction($this->resolveAction(CartRemoveLineItemAction::class, $action));
275 1
        return $this;
276
    }
277
278
    /**
279
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-payment
280
     * @param CartRemovePaymentAction|callable $action
281
     * @return $this
282
     */
283 1
    public function removePayment($action = null)
284
    {
285 1
        $this->addAction($this->resolveAction(CartRemovePaymentAction::class, $action));
286 1
        return $this;
287
    }
288
289
    /**
290
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-anonymous-id
291
     * @param CartSetAnonymousIdAction|callable $action
292
     * @return $this
293
     */
294 1
    public function setAnonymousId($action = null)
295
    {
296 1
        $this->addAction($this->resolveAction(CartSetAnonymousIdAction::class, $action));
297 1
        return $this;
298
    }
299
300
    /**
301
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-billing-address
302
     * @param CartSetBillingAddressAction|callable $action
303
     * @return $this
304
     */
305 1
    public function setBillingAddress($action = null)
306
    {
307 1
        $this->addAction($this->resolveAction(CartSetBillingAddressAction::class, $action));
308 1
        return $this;
309
    }
310
311
    /**
312
     *
313
     * @param CartSetBillingAddressCustomFieldAction|callable $action
314
     * @return $this
315
     */
316 1
    public function setBillingAddressCustomField($action = null)
317
    {
318 1
        $this->addAction($this->resolveAction(CartSetBillingAddressCustomFieldAction::class, $action));
319 1
        return $this;
320
    }
321
322
    /**
323
     *
324
     * @param CartSetBillingAddressCustomTypeAction|callable $action
325
     * @return $this
326
     */
327 1
    public function setBillingAddressCustomType($action = null)
328
    {
329 1
        $this->addAction($this->resolveAction(CartSetBillingAddressCustomTypeAction::class, $action));
330 1
        return $this;
331
    }
332
333
    /**
334
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-cart-total-tax
335
     * @param CartSetCartTotalTaxAction|callable $action
336
     * @return $this
337
     */
338 1
    public function setCartTotalTax($action = null)
339
    {
340 1
        $this->addAction($this->resolveAction(CartSetCartTotalTaxAction::class, $action));
341 1
        return $this;
342
    }
343
344
    /**
345
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-country
346
     * @param CartSetCountryAction|callable $action
347
     * @return $this
348
     */
349 1
    public function setCountry($action = null)
350
    {
351 1
        $this->addAction($this->resolveAction(CartSetCountryAction::class, $action));
352 1
        return $this;
353
    }
354
355
    /**
356
     *
357
     * @param CartSetCustomFieldAction|callable $action
358
     * @return $this
359
     */
360 1
    public function setCustomField($action = null)
361
    {
362 1
        $this->addAction($this->resolveAction(CartSetCustomFieldAction::class, $action));
363 1
        return $this;
364
    }
365
366
    /**
367
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-customfield
368
     * @param CartSetCustomLineItemCustomFieldAction|callable $action
369
     * @return $this
370
     */
371 1
    public function setCustomLineItemCustomField($action = null)
372
    {
373 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemCustomFieldAction::class, $action));
374 1
        return $this;
375
    }
376
377
    /**
378
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-custom-type
379
     * @param CartSetCustomLineItemCustomTypeAction|callable $action
380
     * @return $this
381
     */
382 1
    public function setCustomLineItemCustomType($action = null)
383
    {
384 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemCustomTypeAction::class, $action));
385 1
        return $this;
386
    }
387
388
    /**
389
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitemshippingdetails
390
     * @param CartSetCustomLineItemShippingDetailsAction|callable $action
391
     * @return $this
392
     */
393 1
    public function setCustomLineItemShippingDetails($action = null)
394
    {
395 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemShippingDetailsAction::class, $action));
396 1
        return $this;
397
    }
398
399
    /**
400
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxamount
401
     * @param CartSetCustomLineItemTaxAmountAction|callable $action
402
     * @return $this
403
     */
404 1
    public function setCustomLineItemTaxAmount($action = null)
405
    {
406 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemTaxAmountAction::class, $action));
407 1
        return $this;
408
    }
409
410
    /**
411
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxrate
412
     * @param CartSetCustomLineItemTaxRateAction|callable $action
413
     * @return $this
414
     */
415 1
    public function setCustomLineItemTaxRate($action = null)
416
    {
417 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemTaxRateAction::class, $action));
418 1
        return $this;
419
    }
420
421
    /**
422
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-custom-shippingmethod
423
     * @param CartSetCustomShippingMethodAction|callable $action
424
     * @return $this
425
     */
426 1
    public function setCustomShippingMethod($action = null)
427
    {
428 1
        $this->addAction($this->resolveAction(CartSetCustomShippingMethodAction::class, $action));
429 1
        return $this;
430
    }
431
432
    /**
433
     *
434
     * @param CartSetCustomTypeAction|callable $action
435
     * @return $this
436
     */
437 1
    public function setCustomType($action = null)
438
    {
439 1
        $this->addAction($this->resolveAction(CartSetCustomTypeAction::class, $action));
440 1
        return $this;
441
    }
442
443
    /**
444
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-email
445
     * @param CartSetCustomerEmailAction|callable $action
446
     * @return $this
447
     */
448 1
    public function setCustomerEmail($action = null)
449
    {
450 1
        $this->addAction($this->resolveAction(CartSetCustomerEmailAction::class, $action));
451 1
        return $this;
452
    }
453
454
    /**
455
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-group
456
     * @param CartSetCustomerGroupAction|callable $action
457
     * @return $this
458
     */
459 1
    public function setCustomerGroup($action = null)
460
    {
461 1
        $this->addAction($this->resolveAction(CartSetCustomerGroupAction::class, $action));
462 1
        return $this;
463
    }
464
465
    /**
466
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-id
467
     * @param CartSetCustomerIdAction|callable $action
468
     * @return $this
469
     */
470 1
    public function setCustomerId($action = null)
471
    {
472 1
        $this->addAction($this->resolveAction(CartSetCustomerIdAction::class, $action));
473 1
        return $this;
474
    }
475
476
    /**
477
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-deletedaysafterlastmodification-beta
478
     * @param CartSetDeleteDaysAfterLastModificationAction|callable $action
479
     * @return $this
480
     */
481 1
    public function setDeleteDaysAfterLastModification($action = null)
482
    {
483 1
        $this->addAction($this->resolveAction(CartSetDeleteDaysAfterLastModificationAction::class, $action));
484 1
        return $this;
485
    }
486
487
    /**
488
     *
489
     * @param CartSetItemShippingAddressCustomFieldAction|callable $action
490
     * @return $this
491
     */
492 1
    public function setItemShippingAddressCustomField($action = null)
493
    {
494 1
        $this->addAction($this->resolveAction(CartSetItemShippingAddressCustomFieldAction::class, $action));
495 1
        return $this;
496
    }
497
498
    /**
499
     *
500
     * @param CartSetItemShippingAddressCustomTypeAction|callable $action
501
     * @return $this
502
     */
503 1
    public function setItemShippingAddressCustomType($action = null)
504
    {
505 1
        $this->addAction($this->resolveAction(CartSetItemShippingAddressCustomTypeAction::class, $action));
506 1
        return $this;
507
    }
508
509
    /**
510
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-customfield
511
     * @param CartSetLineItemCustomFieldAction|callable $action
512
     * @return $this
513
     */
514 1
    public function setLineItemCustomField($action = null)
515
    {
516 1
        $this->addAction($this->resolveAction(CartSetLineItemCustomFieldAction::class, $action));
517 1
        return $this;
518
    }
519
520
    /**
521
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-custom-type
522
     * @param CartSetLineItemCustomTypeAction|callable $action
523
     * @return $this
524
     */
525 1
    public function setLineItemCustomType($action = null)
526
    {
527 1
        $this->addAction($this->resolveAction(CartSetLineItemCustomTypeAction::class, $action));
528 1
        return $this;
529
    }
530
531
    /**
532
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
533
     * @param CartSetLineItemPriceAction|callable $action
534
     * @return $this
535
     */
536 1
    public function setLineItemPrice($action = null)
537
    {
538 1
        $this->addAction($this->resolveAction(CartSetLineItemPriceAction::class, $action));
539 1
        return $this;
540
    }
541
542
    /**
543
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
544
     * @param CartSetLineItemShippingDetailsAction|callable $action
545
     * @return $this
546
     */
547 1
    public function setLineItemShippingDetails($action = null)
548
    {
549 1
        $this->addAction($this->resolveAction(CartSetLineItemShippingDetailsAction::class, $action));
550 1
        return $this;
551
    }
552
553
    /**
554
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxamount
555
     * @param CartSetLineItemTaxAmountAction|callable $action
556
     * @return $this
557
     */
558 1
    public function setLineItemTaxAmount($action = null)
559
    {
560 1
        $this->addAction($this->resolveAction(CartSetLineItemTaxAmountAction::class, $action));
561 1
        return $this;
562
    }
563
564
    /**
565
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxrate
566
     * @param CartSetLineItemTaxRateAction|callable $action
567
     * @return $this
568
     */
569 1
    public function setLineItemTaxRate($action = null)
570
    {
571 1
        $this->addAction($this->resolveAction(CartSetLineItemTaxRateAction::class, $action));
572 1
        return $this;
573
    }
574
575
    /**
576
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
577
     * @param CartSetLineItemTotalPriceAction|callable $action
578
     * @return $this
579
     */
580 1
    public function setLineItemTotalPrice($action = null)
581
    {
582 1
        $this->addAction($this->resolveAction(CartSetLineItemTotalPriceAction::class, $action));
583 1
        return $this;
584
    }
585
586
    /**
587
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-locale
588
     * @param CartSetLocaleAction|callable $action
589
     * @return $this
590
     */
591 1
    public function setLocale($action = null)
592
    {
593 1
        $this->addAction($this->resolveAction(CartSetLocaleAction::class, $action));
594 1
        return $this;
595
    }
596
597
    /**
598
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shipping-address
599
     * @param CartSetShippingAddressAction|callable $action
600
     * @return $this
601
     */
602 1
    public function setShippingAddress($action = null)
603
    {
604 1
        $this->addAction($this->resolveAction(CartSetShippingAddressAction::class, $action));
605 1
        return $this;
606
    }
607
608
    /**
609
     *
610
     * @param CartSetShippingAddressCustomFieldAction|callable $action
611
     * @return $this
612
     */
613 1
    public function setShippingAddressCustomField($action = null)
614
    {
615 1
        $this->addAction($this->resolveAction(CartSetShippingAddressCustomFieldAction::class, $action));
616 1
        return $this;
617
    }
618
619
    /**
620
     *
621
     * @param CartSetShippingAddressCustomTypeAction|callable $action
622
     * @return $this
623
     */
624 1
    public function setShippingAddressCustomType($action = null)
625
    {
626 1
        $this->addAction($this->resolveAction(CartSetShippingAddressCustomTypeAction::class, $action));
627 1
        return $this;
628
    }
629
630
    /**
631
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod
632
     * @param CartSetShippingMethodAction|callable $action
633
     * @return $this
634
     */
635 1
    public function setShippingMethod($action = null)
636
    {
637 1
        $this->addAction($this->resolveAction(CartSetShippingMethodAction::class, $action));
638 1
        return $this;
639
    }
640
641
    /**
642
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod-taxamount
643
     * @param CartSetShippingMethodTaxAmountAction|callable $action
644
     * @return $this
645
     */
646 1
    public function setShippingMethodTaxAmount($action = null)
647
    {
648 1
        $this->addAction($this->resolveAction(CartSetShippingMethodTaxAmountAction::class, $action));
649 1
        return $this;
650
    }
651
652
    /**
653
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod-taxrate
654
     * @param CartSetShippingMethodTaxRateAction|callable $action
655
     * @return $this
656
     */
657 1
    public function setShippingMethodTaxRate($action = null)
658
    {
659 1
        $this->addAction($this->resolveAction(CartSetShippingMethodTaxRateAction::class, $action));
660 1
        return $this;
661
    }
662
663
    /**
664
     * @link https://dev.commercetools.com/http-api-projects-carts.html#set-shippingrateinput
665
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingrateinput
666
     * @param CartSetShippingRateInputAction|callable $action
667
     * @return $this
668
     */
669 1
    public function setShippingRateInput($action = null)
670
    {
671 1
        $this->addAction($this->resolveAction(CartSetShippingRateInputAction::class, $action));
672 1
        return $this;
673
    }
674
675
    /**
676
     * @link https://docs.commercetools.com/http-api-projects-carts.html#update-itemshippingaddress
677
     * @param CartUpdateItemShippingAddressAction|callable $action
678
     * @return $this
679
     */
680 1
    public function updateItemShippingAddress($action = null)
681
    {
682 1
        $this->addAction($this->resolveAction(CartUpdateItemShippingAddressAction::class, $action));
683 1
        return $this;
684
    }
685
686
    /**
687
     * @return CartsActionBuilder
688
     */
689
    public static function of()
690
    {
691
        return new self();
692
    }
693
694
    /**
695
     * @param $class
696
     * @param $action
697
     * @return AbstractAction
698
     * @throws InvalidArgumentException
699
     */
700 56
    private function resolveAction($class, $action = null)
701
    {
702 56
        if (is_null($action) || is_callable($action)) {
703 56
            $callback = $action;
704 56
            $emptyAction = $class::of();
705 56
            $action = $this->callback($emptyAction, $callback);
706
        }
707 56
        if ($action instanceof $class) {
708 56
            return $action;
709
        }
710
        throw new InvalidArgumentException(
711
            sprintf('Expected method to be called with or callable to return %s', $class)
712
        );
713
    }
714
715
    /**
716
     * @param $action
717
     * @param callable $callback
718
     * @return AbstractAction
719
     */
720 56
    private function callback($action, callable $callback = null)
721
    {
722 56
        if (!is_null($callback)) {
723
            $action = $callback($action);
724
        }
725 56
        return $action;
726
    }
727
728
    /**
729
     * @param AbstractAction $action
730
     * @return $this;
731
     */
732 56
    public function addAction(AbstractAction $action)
733
    {
734 56
        $this->actions[] = $action;
735 56
        return $this;
736
    }
737
738
    /**
739
     * @return array
740
     */
741 56
    public function getActions()
742
    {
743 56
        return $this->actions;
744
    }
745
746
747
    /**
748
     * @param array $actions
749
     * @return $this
750
     */
751
    public function setActions(array $actions)
752
    {
753
        $this->actions = $actions;
754
        return $this;
755
    }
756
}
757