Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit b6cb2c6

Browse files
author
Jens Schulze
authored
Merge pull request #423 from commercetools/feature-ns/multiple-shipping-addresses-#390
support multiple shipping addresses #390
2 parents c6b2712 + 0d6fc54 commit b6cb2c6

38 files changed

+1188
-20
lines changed

src/Core/Builder/Update/CartsActionBuilder.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
use Commercetools\Core\Request\AbstractAction;
77
use Commercetools\Core\Request\Carts\Command\CartAddCustomLineItemAction;
88
use Commercetools\Core\Request\Carts\Command\CartAddDiscountCodeAction;
9+
use Commercetools\Core\Request\Carts\Command\CartAddItemShippingAddressAction;
910
use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction;
1011
use Commercetools\Core\Request\Carts\Command\CartAddPaymentAction;
1112
use Commercetools\Core\Request\Carts\Command\CartAddShoppingListAction;
13+
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction;
14+
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToLineItemShippingDetailsTargetsAction;
1215
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemMoneyAction;
1316
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemQuantityAction;
1417
use Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction;
@@ -18,6 +21,7 @@
1821
use Commercetools\Core\Request\Carts\Command\CartRecalculateAction;
1922
use Commercetools\Core\Request\Carts\Command\CartRemoveCustomLineItemAction;
2023
use Commercetools\Core\Request\Carts\Command\CartRemoveDiscountCodeAction;
24+
use Commercetools\Core\Request\Carts\Command\CartRemoveItemShippingAddressAction;
2125
use Commercetools\Core\Request\Carts\Command\CartRemoveLineItemAction;
2226
use Commercetools\Core\Request\Carts\Command\CartRemovePaymentAction;
2327
use Commercetools\Core\Request\Carts\Command\CartSetAnonymousIdAction;
@@ -27,6 +31,7 @@
2731
use Commercetools\Core\Request\Carts\Command\CartSetCustomFieldAction;
2832
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomFieldAction;
2933
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomTypeAction;
34+
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemShippingDetailsAction;
3035
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxAmountAction;
3136
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxRateAction;
3237
use Commercetools\Core\Request\Carts\Command\CartSetCustomShippingMethodAction;
@@ -38,6 +43,7 @@
3843
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction;
3944
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction;
4045
use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction;
46+
use Commercetools\Core\Request\Carts\Command\CartSetLineItemShippingDetailsAction;
4147
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction;
4248
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxRateAction;
4349
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction;
@@ -47,6 +53,7 @@
4753
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxAmountAction;
4854
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxRateAction;
4955
use Commercetools\Core\Request\Carts\Command\CartSetShippingRateInputAction;
56+
use Commercetools\Core\Request\Carts\Command\CartUpdateItemShippingAddressAction;
5057

5158
class CartsActionBuilder
5259
{
@@ -74,6 +81,17 @@ public function addDiscountCode($action = null)
7481
return $this;
7582
}
7683

84+
/**
85+
* @link https://docs.commercetools.com/http-api-projects-carts.html#add-itemshippingaddress
86+
* @param CartAddItemShippingAddressAction|callable $action
87+
* @return $this
88+
*/
89+
public function addItemShippingAddress($action = null)
90+
{
91+
$this->addAction($this->resolveAction(CartAddItemShippingAddressAction::class, $action));
92+
return $this;
93+
}
94+
7795
/**
7896
* @link https://docs.commercetools.com/http-api-projects-carts.html#add-lineitem
7997
* @param CartAddLineItemAction|callable $action
@@ -107,6 +125,29 @@ public function addShoppingList($action = null)
107125
return $this;
108126
}
109127

128+
/**
129+
* @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatocustomlineitemshippingdetailstargets
130+
* @param CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction|callable $action
131+
* @return $this
132+
*/
133+
public function applyDeltaToCustomLineItemShippingDetailsTargets($action = null)
134+
{
135+
// @codingStandardsIgnoreLine
136+
$this->addAction($this->resolveAction(CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction::class, $action));
137+
return $this;
138+
}
139+
140+
/**
141+
* @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatolineitemshippingdetailstargets
142+
* @param CartApplyDeltaToLineItemShippingDetailsTargetsAction|callable $action
143+
* @return $this
144+
*/
145+
public function applyDeltaToLineItemShippingDetailsTargets($action = null)
146+
{
147+
$this->addAction($this->resolveAction(CartApplyDeltaToLineItemShippingDetailsTargetsAction::class, $action));
148+
return $this;
149+
}
150+
110151
/**
111152
* @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-money
112153
* @param CartChangeCustomLineItemMoneyAction|callable $action
@@ -206,6 +247,17 @@ public function removeDiscountCode($action = null)
206247
return $this;
207248
}
208249

250+
/**
251+
* @link https://docs.commercetools.com/http-api-projects-carts.html#remove-itemshippingaddress
252+
* @param CartRemoveItemShippingAddressAction|callable $action
253+
* @return $this
254+
*/
255+
public function removeItemShippingAddress($action = null)
256+
{
257+
$this->addAction($this->resolveAction(CartRemoveItemShippingAddressAction::class, $action));
258+
return $this;
259+
}
260+
209261
/**
210262
* @link https://docs.commercetools.com/http-api-projects-carts.html#remove-lineitem
211263
* @param CartRemoveLineItemAction|callable $action
@@ -305,6 +357,17 @@ public function setCustomLineItemCustomType($action = null)
305357
return $this;
306358
}
307359

360+
/**
361+
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitemshippingdetails
362+
* @param CartSetCustomLineItemShippingDetailsAction|callable $action
363+
* @return $this
364+
*/
365+
public function setCustomLineItemShippingDetails($action = null)
366+
{
367+
$this->addAction($this->resolveAction(CartSetCustomLineItemShippingDetailsAction::class, $action));
368+
return $this;
369+
}
370+
308371
/**
309372
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxamount
310373
* @param CartSetCustomLineItemTaxAmountAction|callable $action
@@ -426,6 +489,17 @@ public function setLineItemPrice($action = null)
426489
return $this;
427490
}
428491

492+
/**
493+
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
494+
* @param CartSetLineItemShippingDetailsAction|callable $action
495+
* @return $this
496+
*/
497+
public function setLineItemShippingDetails($action = null)
498+
{
499+
$this->addAction($this->resolveAction(CartSetLineItemShippingDetailsAction::class, $action));
500+
return $this;
501+
}
502+
429503
/**
430504
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxamount
431505
* @param CartSetLineItemTaxAmountAction|callable $action
@@ -526,6 +600,17 @@ public function setShippingRateInput($action = null)
526600
return $this;
527601
}
528602

603+
/**
604+
* @link https://docs.commercetools.com/http-api-projects-carts.html#update-itemshippingaddress
605+
* @param CartUpdateItemShippingAddressAction|callable $action
606+
* @return $this
607+
*/
608+
public function updateItemShippingAddress($action = null)
609+
{
610+
$this->addAction($this->resolveAction(CartUpdateItemShippingAddressAction::class, $action));
611+
return $this;
612+
}
613+
529614
/**
530615
* @return CartsActionBuilder
531616
*/

src/Core/Builder/Update/OrdersActionBuilder.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Commercetools\Core\Error\InvalidArgumentException;
66
use Commercetools\Core\Request\AbstractAction;
77
use Commercetools\Core\Request\Orders\Command\OrderAddDeliveryAction;
8+
use Commercetools\Core\Request\Orders\Command\OrderAddItemShippingAddressAction;
89
use Commercetools\Core\Request\Orders\Command\OrderAddParcelToDeliveryAction;
910
use Commercetools\Core\Request\Orders\Command\OrderAddPaymentAction;
1011
use Commercetools\Core\Request\Orders\Command\OrderAddReturnInfoAction;
@@ -14,18 +15,21 @@
1415
use Commercetools\Core\Request\Orders\Command\OrderImportCustomLineItemStateAction;
1516
use Commercetools\Core\Request\Orders\Command\OrderImportLineItemStateAction;
1617
use Commercetools\Core\Request\Orders\Command\OrderRemoveDeliveryAction;
18+
use Commercetools\Core\Request\Orders\Command\OrderRemoveItemShippingAddressAction;
1719
use Commercetools\Core\Request\Orders\Command\OrderRemoveParcelFromDeliveryAction;
1820
use Commercetools\Core\Request\Orders\Command\OrderRemovePaymentAction;
1921
use Commercetools\Core\Request\Orders\Command\OrderSetBillingAddress;
2022
use Commercetools\Core\Request\Orders\Command\OrderSetCustomFieldAction;
2123
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemCustomFieldAction;
2224
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemCustomTypeAction;
25+
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemShippingDetailsAction;
2326
use Commercetools\Core\Request\Orders\Command\OrderSetCustomTypeAction;
2427
use Commercetools\Core\Request\Orders\Command\OrderSetCustomerEmail;
2528
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressAction;
2629
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryItemsAction;
2730
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemCustomFieldAction;
2831
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemCustomTypeAction;
32+
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemShippingDetailsAction;
2933
use Commercetools\Core\Request\Orders\Command\OrderSetLocaleAction;
3034
use Commercetools\Core\Request\Orders\Command\OrderSetOrderNumberAction;
3135
use Commercetools\Core\Request\Orders\Command\OrderSetParcelItemsAction;
@@ -37,6 +41,7 @@
3741
use Commercetools\Core\Request\Orders\Command\OrderTransitionCustomLineItemStateAction;
3842
use Commercetools\Core\Request\Orders\Command\OrderTransitionLineItemStateAction;
3943
use Commercetools\Core\Request\Orders\Command\OrderTransitionStateAction;
44+
use Commercetools\Core\Request\Orders\Command\OrderUpdateItemShippingAddressAction;
4045
use Commercetools\Core\Request\Orders\Command\OrderUpdateSyncInfoAction;
4146

4247
class OrdersActionBuilder
@@ -54,6 +59,17 @@ public function addDelivery($action = null)
5459
return $this;
5560
}
5661

62+
/**
63+
* @link https://docs.commercetools.com/http-api-projects-orders.html#add-itemshippingaddress
64+
* @param OrderAddItemShippingAddressAction|callable $action
65+
* @return $this
66+
*/
67+
public function addItemShippingAddress($action = null)
68+
{
69+
$this->addAction($this->resolveAction(OrderAddItemShippingAddressAction::class, $action));
70+
return $this;
71+
}
72+
5773
/**
5874
* @link https://docs.commercetools.com/http-api-projects-orders.html#add-parcel
5975
* @param OrderAddParcelToDeliveryAction|callable $action
@@ -153,6 +169,17 @@ public function removeDelivery($action = null)
153169
return $this;
154170
}
155171

172+
/**
173+
* @link https://docs.commercetools.com/http-api-projects-orders.html#remove-itemshippingaddress
174+
* @param OrderRemoveItemShippingAddressAction|callable $action
175+
* @return $this
176+
*/
177+
public function removeItemShippingAddress($action = null)
178+
{
179+
$this->addAction($this->resolveAction(OrderRemoveItemShippingAddressAction::class, $action));
180+
return $this;
181+
}
182+
156183
/**
157184
* @link https://docs.commercetools.com/http-api-projects-orders.html#remove-parcel-from-delivery
158185
* @param OrderRemoveParcelFromDeliveryAction|callable $action
@@ -219,6 +246,17 @@ public function setCustomLineItemCustomType($action = null)
219246
return $this;
220247
}
221248

249+
/**
250+
* @link https://docs.commercetools.com/http-api-projects-orders.html#set-customlineitemshippingdetails
251+
* @param OrderSetCustomLineItemShippingDetailsAction|callable $action
252+
* @return $this
253+
*/
254+
public function setCustomLineItemShippingDetails($action = null)
255+
{
256+
$this->addAction($this->resolveAction(OrderSetCustomLineItemShippingDetailsAction::class, $action));
257+
return $this;
258+
}
259+
222260
/**
223261
*
224262
* @param OrderSetCustomTypeAction|callable $action
@@ -285,6 +323,17 @@ public function setLineItemCustomType($action = null)
285323
return $this;
286324
}
287325

326+
/**
327+
* @link https://docs.commercetools.com/http-api-projects-orders.html#set-lineitemshippingdetails
328+
* @param OrderSetLineItemShippingDetailsAction|callable $action
329+
* @return $this
330+
*/
331+
public function setLineItemShippingDetails($action = null)
332+
{
333+
$this->addAction($this->resolveAction(OrderSetLineItemShippingDetailsAction::class, $action));
334+
return $this;
335+
}
336+
288337
/**
289338
* @link https://docs.commercetools.com/http-api-projects-orders.html#set-locale
290339
* @param OrderSetLocaleAction|callable $action
@@ -406,6 +455,17 @@ public function transitionState($action = null)
406455
return $this;
407456
}
408457

458+
/**
459+
* @link https://docs.commercetools.com/http-api-projects-orders.html#update-itemshippingaddress
460+
* @param OrderUpdateItemShippingAddressAction|callable $action
461+
* @return $this
462+
*/
463+
public function updateItemShippingAddress($action = null)
464+
{
465+
$this->addAction($this->resolveAction(OrderUpdateItemShippingAddressAction::class, $action));
466+
return $this;
467+
}
468+
409469
/**
410470
* @link https://docs.commercetools.com/http-api-projects-orders.html#update-syncinfo
411471
* @param OrderUpdateSyncInfoAction|callable $action
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Error;
6+
7+
/**
8+
* @package Commercetools\Core\Error
9+
*
10+
* @method string getCode()
11+
* @method InvalidItemShippingDetailsError setCode(string $code = null)
12+
* @method string getMessage()
13+
* @method InvalidItemShippingDetailsError setMessage(string $message = null)
14+
* @method string getSubject()
15+
* @method InvalidItemShippingDetailsError setSubject(string $subject = null)
16+
* @method string getItemId()
17+
* @method InvalidItemShippingDetailsError setItemId(string $itemId = null)
18+
*/
19+
class InvalidItemShippingDetailsError extends ApiError
20+
{
21+
const CODE = 'InvalidItemShippingDetails';
22+
23+
public function fieldDefinitions()
24+
{
25+
$definitions = parent::fieldDefinitions();
26+
$definitions['subject'] = [static::TYPE => 'string'];
27+
$definitions['itemId'] = [static::TYPE => 'string'];
28+
29+
return $definitions;
30+
}
31+
}

src/Core/Helper/Annotate/AnnotationGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function ($link) {
209209
$actionShortName = $updateClass->getShortName();
210210
$action = new $update();
211211
$actionName = $action->getAction();
212-
212+
$csIgnore = strlen($actionShortName) > 55 ? '// @codingStandardsIgnoreLine' . PHP_EOL . ' ' : '';
213213
$method = <<<METHOD
214214
/**
215215
*$docLinks
@@ -218,7 +218,7 @@ function ($link) {
218218
*/
219219
public function $actionName(\$action = null)
220220
{
221-
\$this->addAction(\$this->resolveAction($actionShortName::class, \$action));
221+
$csIgnore\$this->addAction(\$this->resolveAction($actionShortName::class, \$action));
222222
return \$this;
223223
}
224224
METHOD;

src/Core/Model/Cart/Cart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Commercetools\Core\Model\CartDiscount\CartDiscountReferenceCollection;
99
use Commercetools\Core\Model\Common\Address;
10+
use Commercetools\Core\Model\Common\AddressCollection;
1011
use Commercetools\Core\Model\Common\LocaleTrait;
1112
use Commercetools\Core\Model\Common\Resource;
1213
use Commercetools\Core\Model\Common\Money;
@@ -77,6 +78,8 @@
7778
* @method Cart setTaxCalculationMode(string $taxCalculationMode = null)
7879
* @method ShippingRateInput getShippingRateInput()
7980
* @method Cart setShippingRateInput(ShippingRateInput $shippingRateInput = null)
81+
* @method AddressCollection getItemShippingAddresses()
82+
* @method Cart setItemShippingAddresses(AddressCollection $itemShippingAddresses = null)
8083
* @method CartReference getReference()
8184
*/
8285
class Cart extends Resource
@@ -134,7 +137,8 @@ public function fieldDefinitions()
134137
'refusedGifts' => [static::TYPE => CartDiscountReferenceCollection::class],
135138
'origin' => [static::TYPE => 'string'],
136139
'taxCalculationMode' => [static::TYPE => 'string'],
137-
'shippingRateInput' => [static::TYPE => ShippingRateInput::class]
140+
'shippingRateInput' => [static::TYPE => ShippingRateInput::class],
141+
'itemShippingAddresses' => [static::TYPE => AddressCollection::class],
138142
];
139143
}
140144

src/Core/Model/Cart/CartDraft.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace Commercetools\Core\Model\Cart;
77

8+
use Commercetools\Core\Model\Common\AddressCollection;
89
use Commercetools\Core\Model\Common\Context;
910
use Commercetools\Core\Model\Common\JsonObject;
1011
use Commercetools\Core\Model\Common\LocaleTrait;
@@ -58,6 +59,8 @@
5859
* @method CartDraft setExternalTaxRateForShippingMethod(ExternalTaxRateDraft $externalTaxRateForShippingMethod = null)
5960
* @method ShippingRateInputDraft getShippingRateInput()
6061
* @method CartDraft setShippingRateInput(ShippingRateInputDraft $shippingRateInput = null)
62+
* @method AddressCollection getItemShippingAddresses()
63+
* @method CartDraft setItemShippingAddresses(AddressCollection $itemShippingAddresses = null)
6164
*/
6265
class CartDraft extends JsonObject
6366
{
@@ -87,6 +90,7 @@ public function fieldDefinitions()
8790
'taxCalculationMode' => [static::TYPE => 'string'],
8891
'externalTaxRateForShippingMethod' => [static::TYPE => ExternalTaxRateDraft::class],
8992
'shippingRateInput' => [static::TYPE => ShippingRateInputDraft::class],
93+
'itemShippingAddresses' => [static::TYPE => AddressCollection::class],
9094
];
9195
}
9296

0 commit comments

Comments
 (0)