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

Commit 20014da

Browse files
committed
feat(Cart): support multiple shipping addresses
1 parent c4e85b3 commit 20014da

29 files changed

+594
-6
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+
*
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+
*
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+
*
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+
*
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
*/
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

src/Core/Model/Cart/CustomLineItem.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
4141
* @method TaxedItemPrice getTaxedPrice()
4242
* @method CustomLineItem setTaxedPrice(TaxedItemPrice $taxedPrice = null)
43+
* @method ItemShippingDetails getShippingDetails()
44+
* @method CustomLineItem setShippingDetails(ItemShippingDetails $shippingDetails = null)
4345
*/
4446
class CustomLineItem extends JsonObject
4547
{
@@ -60,6 +62,7 @@ public function fieldDefinitions()
6062
'discountedPricePerQuantity' => [
6163
static::TYPE => DiscountedPricePerQuantityCollection::class
6264
],
65+
'shippingDetails' => [static::TYPE => ItemShippingDetails::class],
6366
];
6467
}
6568

src/Core/Model/Cart/CustomLineItemDraft.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
namespace Commercetools\Core\Model\Cart;
77

8+
use Commercetools\Core\Model\Common\AddressCollection;
89
use Commercetools\Core\Model\Common\JsonObject;
910
use Commercetools\Core\Model\Common\LocalizedString;
1011
use Commercetools\Core\Model\Common\Money;
11-
use Commercetools\Core\Model\Order\ItemState;
1212
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
13-
use Commercetools\Core\Model\TaxCategory\TaxRate;
1413
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1514
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
1615

@@ -31,6 +30,10 @@
3130
* @method CustomLineItemDraft setCustom(CustomFieldObject $custom = null)
3231
* @method ExternalTaxRateDraft getExternalTaxRate()
3332
* @method CustomLineItemDraft setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
33+
* @method AddressCollection getItemShippingAddresses()
34+
* @method CustomLineItemDraft setItemShippingAddresses(AddressCollection $itemShippingAddresses = null)
35+
* @method ItemShippingDetailsDraft getShippingDetails()
36+
* @method CustomLineItemDraft setShippingDetails(ItemShippingDetailsDraft $shippingDetails = null)
3437
*/
3538
class CustomLineItemDraft extends JsonObject
3639
{
@@ -44,6 +47,7 @@ public function fieldDefinitions()
4447
'taxCategory' => [static::TYPE => TaxCategoryReference::class],
4548
'externalTaxRate' => [static::TYPE => ExternalTaxRateDraft::class],
4649
'custom' => [static::TYPE => CustomFieldObject::class],
50+
'shippingDetails' => [static::TYPE => ItemShippingDetailsDraft::class],
4751
];
4852
}
4953
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
*
13+
* @method ItemShippingTargetCollection getTargets()
14+
* @method ItemShippingDetails setTargets(ItemShippingTargetCollection $targets = null)
15+
* @method bool getValid()
16+
* @method ItemShippingDetails setValid(bool $valid = null)
17+
*/
18+
class ItemShippingDetails extends JsonObject
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'targets' => [static::TYPE => ItemShippingTargetCollection::class],
24+
'valid' => [static::TYPE => 'bool'],
25+
];
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
*
13+
* @method ItemShippingTargetCollection getTargets()
14+
* @method ItemShippingDetailsDraft setTargets(ItemShippingTargetCollection $targets = null)
15+
*/
16+
class ItemShippingDetailsDraft extends JsonObject
17+
{
18+
public function fieldDefinitions()
19+
{
20+
return [
21+
'targets' => [static::TYPE => ItemShippingTargetCollection::class],
22+
];
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
*
13+
* @method string getAddressKey()
14+
* @method ItemShippingTarget setAddressKey(string $addressKey = null)
15+
* @method int getQuantity()
16+
* @method ItemShippingTarget setQuantity(int $quantity = null)
17+
*/
18+
class ItemShippingTarget extends JsonObject
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'addressKey' => [static::TYPE => 'string'],
24+
'quantity' => [static::TYPE => 'int'],
25+
];
26+
}
27+
}

0 commit comments

Comments
 (0)