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

Commit c64fad0

Browse files
author
Jens Schulze
committed
feat(LineItems): add update actions for custom types on line items
1 parent 28820e6 commit c64fad0

File tree

9 files changed

+205
-3
lines changed

9 files changed

+205
-3
lines changed

src/Model/CustomField/FieldContainer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public function fieldDefinition($field)
4646
return $fieldType->fieldTypeDefinition();
4747
}
4848

49+
/**
50+
* @param string $field
51+
* @param mixed $value
52+
* @return $this
53+
*/
54+
public function set($field, $value)
55+
{
56+
return parent::set($field, $value);
57+
}
58+
4959
public function hasField($field)
5060
{
5161
return true;

src/Model/Type/Type.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Commercetools\Core\Model\Common\JsonObject;
99
use Commercetools\Core\Model\Common\DateTimeDecorator;
1010
use Commercetools\Core\Model\Common\LocalizedString;
11+
use Commercetools\Core\Model\Common\Resource;
1112

1213
/**
1314
* @package Commercetools\Core\Model\Type
@@ -30,7 +31,7 @@
3031
* @method FieldDefinitionCollection getFieldDefinitions()
3132
* @method Type setFieldDefinitions(FieldDefinitionCollection $fieldDefinitions = null)
3233
*/
33-
class Type extends JsonObject
34+
class Type extends Resource
3435
{
3536
public function fieldDefinitions()
3637
{

src/Request/Carts/Command/CartAddCustomLineItemAction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Commercetools\Core\Model\TaxCategory\TaxCategory;
1212
use Commercetools\Core\Request\AbstractAction;
1313
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
14+
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
1415

1516
/**
1617
* @package Commercetools\Core\Request\Carts\Command
@@ -27,6 +28,8 @@
2728
* @method CartAddCustomLineItemAction setSlug(string $slug = null)
2829
* @method TaxCategoryReference getTaxCategory()
2930
* @method CartAddCustomLineItemAction setTaxCategory(TaxCategoryReference $taxCategory = null)
31+
* @method CustomFieldObjectDraft getCustom()
32+
* @method CartAddCustomLineItemAction setCustom(CustomFieldObjectDraft $custom = null)
3033
*/
3134
class CartAddCustomLineItemAction extends AbstractAction
3235
{
@@ -39,6 +42,7 @@ public function fieldDefinitions()
3942
'money' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
4043
'slug' => [static::TYPE => 'string'],
4144
'taxCategory' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference'],
45+
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
4246
];
4347
}
4448

src/Request/Carts/Command/CartAddLineItemAction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Commercetools\Core\Model\Common\Context;
99
use Commercetools\Core\Request\AbstractAction;
1010
use Commercetools\Core\Model\Channel\ChannelReference;
11+
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
1112

1213
/**
1314
* @package Commercetools\Core\Request\Carts\Command
@@ -24,6 +25,8 @@
2425
* @method CartAddLineItemAction setSupplyChannel(ChannelReference $supplyChannel = null)
2526
* @method ChannelReference getDistributionChannel()
2627
* @method CartAddLineItemAction setDistributionChannel(ChannelReference $distributionChannel = null)
28+
* @method CustomFieldObjectDraft getCustom()
29+
* @method CartAddLineItemAction setCustom(CustomFieldObjectDraft $custom = null)
2730
*/
2831
class CartAddLineItemAction extends AbstractAction
2932
{
@@ -36,6 +39,7 @@ public function fieldDefinitions()
3639
'quantity' => [static::TYPE => 'int'],
3740
'supplyChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
3841
'distributionChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
42+
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
3943
];
4044
}
4145

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Carts\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Carts\Command
13+
*
14+
* @method string getAction()
15+
* @method CartSetCustomLineItemCustomFieldAction setAction(string $action = null)
16+
* @method string getName()
17+
* @method CartSetCustomLineItemCustomFieldAction setName(string $name = null)
18+
* @method string getCustomLineItemId()
19+
* @method CartSetCustomLineItemCustomFieldAction setCustomLineItemId(string $customLineItemId = null)
20+
* @method getValue()
21+
* @method CartSetCustomLineItemCustomFieldAction setValue($value = null)
22+
*/
23+
class CartSetCustomLineItemCustomFieldAction extends SetCustomFieldAction
24+
{
25+
public function fieldDefinitions()
26+
{
27+
return [
28+
'action' => [static::TYPE => 'string'],
29+
'name' => [static::TYPE => 'string'],
30+
'customLineItemId' => [static::TYPE => 'string'],
31+
'value' => [static::TYPE => null],
32+
];
33+
}
34+
35+
/**
36+
* @param array $data
37+
* @param Context|callable $context
38+
*/
39+
public function __construct(array $data = [], $context = null)
40+
{
41+
parent::__construct($data, $context);
42+
$this->setAction('setCustomLineItemCustomField');
43+
}
44+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Carts\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction;
10+
use Commercetools\Core\Model\CustomField\FieldContainer;
11+
12+
/**
13+
* @package Commercetools\Core\Request\Carts\Command
14+
*
15+
* @method string getAction()
16+
* @method CartSetCustomLineItemCustomTypeAction setAction(string $action = null)
17+
* @method string getTypeId()
18+
* @method CartSetCustomLineItemCustomTypeAction setTypeId(string $typeId = null)
19+
* @method string getTypeKey()
20+
* @method CartSetCustomLineItemCustomTypeAction setTypeKey(string $typeKey = null)
21+
* @method string getCustomLineItemId()
22+
* @method CartSetCustomLineItemCustomTypeAction setCustomLineItemId(string $customLineItemId = null)
23+
* @method FieldContainer getFields()
24+
* @method CartSetCustomLineItemCustomTypeAction setFields(FieldContainer $fields = null)
25+
*/
26+
class CartSetCustomLineItemCustomTypeAction extends SetCustomTypeAction
27+
{
28+
public function fieldDefinitions()
29+
{
30+
return [
31+
'action' => [static::TYPE => 'string'],
32+
'typeId' => [static::TYPE => 'string'],
33+
'typeKey' => [static::TYPE => 'string'],
34+
'customLineItemId' => [static::TYPE => 'string'],
35+
'fields' => [static::TYPE => '\Commercetools\Core\Model\CustomField\FieldContainer'],
36+
];
37+
}
38+
39+
/**
40+
* @param array $data
41+
* @param Context|callable $context
42+
*/
43+
public function __construct(array $data = [], $context = null)
44+
{
45+
parent::__construct($data, $context);
46+
$this->setAction('setCustomLineItemCustomType');
47+
}
48+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Carts\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Carts\Command
13+
*
14+
* @method string getAction()
15+
* @method CartSetLineItemCustomFieldAction setAction(string $action = null)
16+
* @method string getName()
17+
* @method CartSetLineItemCustomFieldAction setName(string $name = null)
18+
* @method string getLineItemId()
19+
* @method CartSetLineItemCustomFieldAction setLineItemId(string $lineItemId = null)
20+
* @method getValue()
21+
* @method CartSetLineItemCustomFieldAction setValue($value = null)
22+
*/
23+
class CartSetLineItemCustomFieldAction extends SetCustomFieldAction
24+
{
25+
public function fieldDefinitions()
26+
{
27+
return [
28+
'action' => [static::TYPE => 'string'],
29+
'name' => [static::TYPE => 'string'],
30+
'lineItemId' => [static::TYPE => 'string'],
31+
'value' => [static::TYPE => null],
32+
];
33+
}
34+
35+
/**
36+
* @param array $data
37+
* @param Context|callable $context
38+
*/
39+
public function __construct(array $data = [], $context = null)
40+
{
41+
parent::__construct($data, $context);
42+
$this->setAction('setLineItemCustomField');
43+
}
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Carts\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction;
10+
use Commercetools\Core\Model\CustomField\FieldContainer;
11+
12+
/**
13+
* @package Commercetools\Core\Request\Carts\Command
14+
* @method string getAction()
15+
* @method CartSetLineItemCustomTypeAction setAction(string $action = null)
16+
* @method string getTypeId()
17+
* @method CartSetLineItemCustomTypeAction setTypeId(string $typeId = null)
18+
* @method string getTypeKey()
19+
* @method CartSetLineItemCustomTypeAction setTypeKey(string $typeKey = null)
20+
* @method string getLineItemId()
21+
* @method CartSetLineItemCustomTypeAction setLineItemId(string $lineItemId = null)
22+
* @method FieldContainer getFields()
23+
* @method CartSetLineItemCustomTypeAction setFields(FieldContainer $fields = null)
24+
*/
25+
class CartSetLineItemCustomTypeAction extends SetCustomTypeAction
26+
{
27+
public function fieldDefinitions()
28+
{
29+
return [
30+
'action' => [static::TYPE => 'string'],
31+
'typeId' => [static::TYPE => 'string'],
32+
'typeKey' => [static::TYPE => 'string'],
33+
'lineItemId' => [static::TYPE => 'string'],
34+
'fields' => [static::TYPE => '\Commercetools\Core\Model\CustomField\FieldContainer'],
35+
];
36+
}
37+
38+
/**
39+
* @param array $data
40+
* @param Context|callable $context
41+
*/
42+
public function __construct(array $data = [], $context = null)
43+
{
44+
parent::__construct($data, $context);
45+
$this->setAction('setLineItemCustomType');
46+
}
47+
}

tests/unit/Request/GenericActionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ public function actionFieldProvider()
259259
],
260260
[
261261
'\Commercetools\Core\Request\Carts\Command\CartAddCustomLineItemAction',
262-
['action', 'name', 'quantity', 'money', 'slug', 'taxCategory']
262+
['action', 'name', 'quantity', 'money', 'slug', 'taxCategory', 'custom']
263263
],
264264
[
265265
'\Commercetools\Core\Request\Carts\Command\CartAddDiscountCodeAction',
266266
['action', 'code']
267267
],
268268
[
269269
'\Commercetools\Core\Request\Carts\Command\CartAddLineItemAction',
270-
['action', 'productId', 'variantId', 'quantity', 'supplyChannel', 'distributionChannel']
270+
['action', 'productId', 'variantId', 'quantity', 'supplyChannel', 'distributionChannel', 'custom']
271271
],
272272
[
273273
'\Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction',

0 commit comments

Comments
 (0)