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

Commit 083b4d8

Browse files
author
Barbara Palumbo
committed
feat(Order): add update actions to set the delivery in the custom fields for order and order edit
1 parent 4a29ace commit 083b4d8

10 files changed

+190
-2
lines changed

src/Core/Builder/Update/OrdersActionBuilder.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressAction;
3232
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressCustomFieldAction;
3333
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressCustomTypeAction;
34+
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryCustomFieldAction;
35+
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryCustomTypeAction;
3436
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryItemsAction;
3537
use Commercetools\Core\Request\Orders\Command\OrderSetItemShippingAddressCustomFieldAction;
3638
use Commercetools\Core\Request\Orders\Command\OrderSetItemShippingAddressCustomTypeAction;
@@ -360,6 +362,28 @@ public function setDeliveryAddressCustomType($action = null)
360362
return $this;
361363
}
362364

365+
/**
366+
*
367+
* @param OrderSetDeliveryCustomFieldAction|callable $action
368+
* @return $this
369+
*/
370+
public function setDeliveryCustomField($action = null)
371+
{
372+
$this->addAction($this->resolveAction(OrderSetDeliveryCustomFieldAction::class, $action));
373+
return $this;
374+
}
375+
376+
/**
377+
*
378+
* @param OrderSetDeliveryCustomTypeAction|callable $action
379+
* @return $this
380+
*/
381+
public function setDeliveryCustomType($action = null)
382+
{
383+
$this->addAction($this->resolveAction(OrderSetDeliveryCustomTypeAction::class, $action));
384+
return $this;
385+
}
386+
363387
/**
364388
* @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-items
365389
* @param OrderSetDeliveryItemsAction|callable $action

src/Core/Builder/Update/StagedOrderActionBuilder.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryAddressAction;
5050
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryAddressCustomFieldAction;
5151
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryAddressCustomTypeAction;
52+
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryCustomFieldAction;
53+
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryCustomTypeAction;
5254
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryItemsAction;
5355
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetItemShippingAddressCustomFieldAction;
5456
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetItemShippingAddressCustomTypeAction;
@@ -589,6 +591,28 @@ public function setDeliveryAddressCustomType($action = null)
589591
return $this;
590592
}
591593

594+
/**
595+
*
596+
* @param StagedOrderSetDeliveryCustomFieldAction|callable $action
597+
* @return $this
598+
*/
599+
public function setDeliveryCustomField($action = null)
600+
{
601+
$this->addAction($this->resolveAction(StagedOrderSetDeliveryCustomFieldAction::class, $action));
602+
return $this;
603+
}
604+
605+
/**
606+
*
607+
* @param StagedOrderSetDeliveryCustomTypeAction|callable $action
608+
* @return $this
609+
*/
610+
public function setDeliveryCustomType($action = null)
611+
{
612+
$this->addAction($this->resolveAction(StagedOrderSetDeliveryCustomTypeAction::class, $action));
613+
return $this;
614+
}
615+
592616
/**
593617
*
594618
* @param StagedOrderSetDeliveryItemsAction|callable $action

src/Core/Model/Order/Delivery.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Commercetools\Core\Model\Common\Address;
99
use Commercetools\Core\Model\Common\JsonObject;
1010
use Commercetools\Core\Model\Common\DateTimeDecorator;
11+
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1112
use DateTime;
1213

1314
/**
@@ -23,6 +24,8 @@
2324
* @method Delivery setParcels(ParcelCollection $parcels = null)
2425
* @method Address getAddress()
2526
* @method Delivery setAddress(Address $address = null)
27+
* @method CustomFieldObject getCustom()
28+
* @method Delivery setCustom(CustomFieldObject $custom = null)
2629
*/
2730
class Delivery extends JsonObject
2831
{
@@ -36,7 +39,8 @@ public function fieldDefinitions()
3639
],
3740
'items' => [static::TYPE => DeliveryItemCollection::class],
3841
'parcels' => [static::TYPE => ParcelCollection::class],
39-
'address' => [static::TYPE => Address::class]
42+
'address' => [static::TYPE => Address::class],
43+
'custom' => [static::TYPE => CustomFieldObject::class],
4044
];
4145
}
4246
}

src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderAddDeliveryAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Commercetools\Core\Model\Order\DeliveryItemCollection;
1010
use Commercetools\Core\Model\Order\ParcelCollection;
1111
use Commercetools\Core\Model\Common\Address;
12+
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1213

1314
/**
1415
* @package Commercetools\Core\Request\OrderEdits\StagedOrder\Command
@@ -21,6 +22,8 @@
2122
* @method StagedOrderAddDeliveryAction setParcels(ParcelCollection $parcels = null)
2223
* @method Address getAddress()
2324
* @method StagedOrderAddDeliveryAction setAddress(Address $address = null)
25+
* @method CustomFieldObject getCustom()
26+
* @method StagedOrderAddDeliveryAction setCustom(CustomFieldObject $custom = null)
2427
*/
2528
class StagedOrderAddDeliveryAction extends OrderAddDeliveryAction implements StagedOrderUpdateAction
2629
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Request\OrderEdits\StagedOrder\Command;
4+
5+
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryCustomFieldAction;
6+
7+
/**
8+
* @package Commercetools\Core\Request\OrderEdits\StagedOrder\Command
9+
*
10+
* @method string getAction()
11+
* @method StagedOrderSetDeliveryCustomFieldAction setAction(string $action = null)
12+
* @method string getName()
13+
* @method StagedOrderSetDeliveryCustomFieldAction setName(string $name = null)
14+
* @method mixed getValue()
15+
* @method StagedOrderSetDeliveryCustomFieldAction setValue($value = null)
16+
*/
17+
// phpcs:ignore
18+
class StagedOrderSetDeliveryCustomFieldAction extends OrderSetDeliveryCustomFieldAction implements StagedOrderUpdateAction
19+
{
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Request\OrderEdits\StagedOrder\Command;
4+
5+
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryCustomTypeAction;
6+
use Commercetools\Core\Model\Type\TypeReference;
7+
use Commercetools\Core\Model\CustomField\FieldContainer;
8+
9+
/**
10+
* @package Commercetools\Core\Request\OrderEdits\StagedOrder\Command
11+
*
12+
* @method string getAction()
13+
* @method StagedOrderSetDeliveryCustomTypeAction setAction(string $action = null)
14+
* @method TypeReference getType()
15+
* @method StagedOrderSetDeliveryCustomTypeAction setType(TypeReference $type = null)
16+
* @method FieldContainer getFields()
17+
* @method StagedOrderSetDeliveryCustomTypeAction setFields(FieldContainer $fields = null)
18+
*/
19+
class StagedOrderSetDeliveryCustomTypeAction extends OrderSetDeliveryCustomTypeAction implements StagedOrderUpdateAction
20+
{
21+
}

src/Core/Request/Orders/Command/OrderAddDeliveryAction.php

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

88
use Commercetools\Core\Model\Common\Address;
99
use Commercetools\Core\Model\Common\Context;
10+
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1011
use Commercetools\Core\Model\Order\DeliveryItemCollection;
1112
use Commercetools\Core\Model\Order\ParcelCollection;
1213
use Commercetools\Core\Model\Order\ParcelMeasurements;
@@ -24,6 +25,8 @@
2425
* @method OrderAddDeliveryAction setParcels(ParcelCollection $parcels = null)
2526
* @method Address getAddress()
2627
* @method OrderAddDeliveryAction setAddress(Address $address = null)
28+
* @method CustomFieldObject getCustom()
29+
* @method OrderAddDeliveryAction setCustom(CustomFieldObject $custom = null)
2730
*/
2831
class OrderAddDeliveryAction extends AbstractAction
2932
{
@@ -34,6 +37,7 @@ public function fieldDefinitions()
3437
'items' => [static::TYPE => DeliveryItemCollection::class],
3538
'parcels' => [static::TYPE => ParcelCollection::class],
3639
'address' => [static::TYPE => Address::class],
40+
'custom' => [static::TYPE =>CustomFieldObject::class],
3741
];
3842
}
3943

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Request\Orders\Command;
4+
5+
use Commercetools\Core\Model\Common\Context;
6+
use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction;
7+
8+
/**
9+
* @package Commercetools\Core\Request\Orders\Command
10+
*
11+
*
12+
* @method string getAction()
13+
* @method OrderSetDeliveryCustomFieldAction setAction(string $action = null)
14+
* @method string getName()
15+
* @method OrderSetDeliveryCustomFieldAction setName(string $name = null)
16+
* @method mixed getValue()
17+
* @method OrderSetDeliveryCustomFieldAction setValue($value = null)
18+
*/
19+
class OrderSetDeliveryCustomFieldAction extends SetCustomFieldAction
20+
{
21+
public function fieldDefinitions()
22+
{
23+
return [
24+
'action' => [static::TYPE => 'string'],
25+
'name' => [static::TYPE => 'string'],
26+
'value' => [static::TYPE => null],
27+
];
28+
}
29+
30+
/**
31+
* @param array $data
32+
* @param Context|callable $context
33+
*/
34+
public function __construct(array $data = [], $context = null)
35+
{
36+
parent::__construct($data, $context);
37+
$this->setAction('setDeliveryCustomField');
38+
}
39+
40+
public static function ofName($name, $context = null)
41+
{
42+
return static::of($context)->setName($name);
43+
}
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Request\Orders\Command;
4+
5+
use Commercetools\Core\Model\Common\Context;
6+
use Commercetools\Core\Model\CustomField\FieldContainer;
7+
use Commercetools\Core\Model\Type\TypeReference;
8+
use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction;
9+
10+
/**
11+
* @package Commercetools\Core\Request\Orders\Command
12+
*
13+
* @method string getAction()
14+
* @method OrderSetDeliveryCustomTypeAction setAction(string $action = null)
15+
* @method TypeReference getType()
16+
* @method OrderSetDeliveryCustomTypeAction setType(TypeReference $type = null)
17+
* @method FieldContainer getFields()
18+
* @method OrderSetDeliveryCustomTypeAction setFields(FieldContainer $fields = null)
19+
*/
20+
class OrderSetDeliveryCustomTypeAction extends SetCustomTypeAction
21+
{
22+
public function fieldDefinitions()
23+
{
24+
return [
25+
'action' => [static::TYPE => 'string'],
26+
'type' => [static::TYPE => TypeReference::class],
27+
'fields' => [static::TYPE => FieldContainer::class],
28+
];
29+
}
30+
31+
/**
32+
* @param array $data
33+
* @param Context|callable $context
34+
*/
35+
public function __construct(array $data = [], $context = null)
36+
{
37+
parent::__construct($data, $context);
38+
$this->setAction('setDeliveryCustomType');
39+
}
40+
41+
public static function ofTypeKey($typeKey, $context = null)
42+
{
43+
return static::of($context)->setType(TypeReference::ofKey($typeKey));
44+
}
45+
}

tests/integration/Order/OrderUpdateRequestTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,6 @@ function (Order $order) use ($client, $type) {
17991799
);
18001800
}
18011801

1802-
18031802
public function testSetParcelCustom()
18041803
{
18051804
$client = $this->getApiClient();

0 commit comments

Comments
 (0)