|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Commercetools\Core\Request\Me\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Commercetools\Core\Model\Cart\ExternalLineItemTotalPrice; |
|
6
|
|
|
use Commercetools\Core\Model\Cart\ItemShippingDetailsDraft; |
|
7
|
|
|
use Commercetools\Core\Model\Channel\ChannelReference; |
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
|
9
|
|
|
use Commercetools\Core\Model\Common\Money; |
|
10
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
|
11
|
|
|
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft; |
|
12
|
|
|
use Commercetools\Core\Request\AbstractAction; |
|
13
|
|
|
use DateTime; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @package Commercetools\Core\Request\Me\Command |
|
17
|
|
|
* @link https://docs.commercetools.com/api/projects/me-carts#add-lineitem |
|
18
|
|
|
* @method string getAction() |
|
19
|
|
|
* @method MyCartAddLineItemAction setAction(string $action = null) |
|
20
|
|
|
* @method string getProductId() |
|
21
|
|
|
* @method MyCartAddLineItemAction setProductId(string $productId = null) |
|
22
|
|
|
* @method int getVariantId() |
|
23
|
|
|
* @method MyCartAddLineItemAction setVariantId(int $variantId = null) |
|
24
|
|
|
* @method int getQuantity() |
|
25
|
|
|
* @method MyCartAddLineItemAction setQuantity(int $quantity = null) |
|
26
|
|
|
* @method ChannelReference getSupplyChannel() |
|
27
|
|
|
* @method MyCartAddLineItemAction setSupplyChannel(ChannelReference $supplyChannel = null) |
|
28
|
|
|
* @method ChannelReference getDistributionChannel() |
|
29
|
|
|
* @method MyCartAddLineItemAction setDistributionChannel(ChannelReference $distributionChannel = null) |
|
30
|
|
|
* @method CustomFieldObjectDraft getCustom() |
|
31
|
|
|
* @method MyCartAddLineItemAction setCustom(CustomFieldObjectDraft $custom = null) |
|
32
|
|
|
* @method ItemShippingDetailsDraft getShippingDetails() |
|
33
|
|
|
* @method MyCartAddLineItemAction setShippingDetails(ItemShippingDetailsDraft $shippingDetails = null) |
|
34
|
|
|
* @method DateTime getAddedAt() |
|
35
|
|
|
* @method MyCartAddLineItemAction setAddedAt(DateTime $addedAt = null) |
|
36
|
|
|
* @method string getSku() |
|
37
|
|
|
* @method MyCartAddLineItemAction setSku(string $sku = null) |
|
38
|
|
|
* @method ExternalTaxRateDraft getExternalTaxRate() |
|
39
|
|
|
* @method MyCartAddLineItemAction setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null) |
|
40
|
|
|
* @method Money getExternalPrice() |
|
41
|
|
|
* @method MyCartAddLineItemAction setExternalPrice(Money $externalPrice = null) |
|
42
|
|
|
* @method ExternalLineItemTotalPrice getExternalTotalPrice() |
|
43
|
|
|
* @method MyCartAddLineItemAction setExternalTotalPrice(ExternalLineItemTotalPrice $externalTotalPrice = null) |
|
44
|
|
|
*/ |
|
45
|
|
|
class MyCartAddLineItemAction extends AbstractAction |
|
46
|
|
|
{ |
|
47
|
|
|
public function fieldDefinitions() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
'action' => [static::TYPE => 'string'], |
|
51
|
|
|
'productId' => [static::TYPE => 'string'], |
|
52
|
|
|
'variantId' => [static::TYPE => 'int'], |
|
53
|
|
|
'sku' => [static::TYPE => 'string'], |
|
54
|
|
|
'quantity' => [static::TYPE => 'int'], |
|
55
|
|
|
'supplyChannel' => [static::TYPE => ChannelReference::class], |
|
56
|
|
|
'distributionChannel' => [static::TYPE => ChannelReference::class], |
|
57
|
|
|
'custom' => [static::TYPE => CustomFieldObjectDraft::class], |
|
58
|
|
|
'externalTaxRate' => [static::TYPE => ExternalTaxRateDraft::class], |
|
59
|
|
|
'externalPrice' => [static::TYPE => Money::class], |
|
60
|
|
|
'externalTotalPrice' => [static::TYPE => ExternalLineItemTotalPrice::class], |
|
61
|
|
|
'shippingDetails' => [static::TYPE => ItemShippingDetailsDraft::class], |
|
62
|
|
|
'addedAt' => [static::TYPE => DateTime::class], |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param array $data |
|
68
|
|
|
* @param Context|callable $context |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct(array $data = [], $context = null) |
|
71
|
|
|
{ |
|
72
|
|
|
parent::__construct($data, $context); |
|
73
|
|
|
$this->setAction('addLineItem'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $productId |
|
78
|
|
|
* @param int $variantId |
|
79
|
|
|
* @param Context|callable $context |
|
80
|
|
|
* @param int $quantity |
|
81
|
|
|
* @return MyCartAddLineItemAction |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function ofProductIdVariantIdAndQuantity($productId, $variantId, $quantity, $context = null) |
|
84
|
|
|
{ |
|
85
|
|
|
return static::of($context)->setProductId($productId)->setVariantId($variantId)->setQuantity($quantity); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|