1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Request\Orders; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\State\StateReference; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
use Commercetools\Core\Client\HttpMethod; |
11
|
|
|
use Commercetools\Core\Client\HttpRequestInterface; |
12
|
|
|
use Commercetools\Core\Client\JsonRequest; |
13
|
|
|
use Commercetools\Core\Model\Common\Context; |
14
|
|
|
use Commercetools\Core\Request\AbstractApiRequest; |
15
|
|
|
use Commercetools\Core\Response\AbstractApiResponse; |
16
|
|
|
use Commercetools\Core\Response\ResourceResponse; |
17
|
|
|
use Commercetools\Core\Model\Order\Order; |
18
|
|
|
use Commercetools\Core\Response\ApiResponseInterface; |
19
|
|
|
use Commercetools\Core\Model\MapperInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @package Commercetools\Core\Request\Orders |
23
|
|
|
* @link https://docs.commercetools.com/http-api-projects-orders.html#create-order-from-cart |
24
|
|
|
* @method Order mapResponse(ApiResponseInterface $response) |
25
|
|
|
* @method Order mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
26
|
|
|
*/ |
27
|
|
|
class OrderCreateFromCartRequest extends AbstractApiRequest |
28
|
|
|
{ |
29
|
|
|
const ID = 'id'; |
30
|
|
|
const VERSION = 'version'; |
31
|
|
|
const ORDER_NUMBER = 'orderNumber'; |
32
|
|
|
const PAYMENT_STATE = 'paymentState'; |
33
|
|
|
const ORDER_STATE = 'orderState'; |
34
|
|
|
const STATE = 'state'; |
35
|
|
|
const SHIPMENT_STATE = 'shipmentState'; |
36
|
|
|
|
37
|
|
|
protected $cartId; |
38
|
|
|
protected $version; |
39
|
|
|
protected $orderNumber; |
40
|
|
|
protected $paymentState; |
41
|
|
|
protected $orderState; |
42
|
|
|
protected $state; |
43
|
|
|
protected $shipmentState; |
44
|
|
|
|
45
|
|
|
protected $resultClass = Order::class; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
43 |
|
public function getCartId() |
51
|
|
|
{ |
52
|
43 |
|
return $this->cartId; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $cartId |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
46 |
|
public function setCartId($cartId) |
60
|
|
|
{ |
61
|
46 |
|
$this->cartId = $cartId; |
62
|
|
|
|
63
|
46 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
43 |
|
public function getVersion() |
70
|
|
|
{ |
71
|
43 |
|
return $this->version; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param int $version |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
46 |
|
public function setVersion($version) |
79
|
|
|
{ |
80
|
46 |
|
$this->version = $version; |
81
|
|
|
|
82
|
46 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
5 |
|
public function getOrderNumber() |
89
|
|
|
{ |
90
|
5 |
|
return $this->orderNumber; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $orderNumber |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
5 |
|
public function setOrderNumber($orderNumber) |
98
|
|
|
{ |
99
|
5 |
|
$this->orderNumber = $orderNumber; |
100
|
|
|
|
101
|
5 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
2 |
|
public function getPaymentState() |
108
|
|
|
{ |
109
|
2 |
|
return $this->paymentState; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $paymentState |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
2 |
|
public function setPaymentState($paymentState) |
117
|
|
|
{ |
118
|
2 |
|
$this->paymentState = $paymentState; |
119
|
|
|
|
120
|
2 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
2 |
|
public function getOrderState() |
127
|
|
|
{ |
128
|
2 |
|
return $this->orderState; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $orderState |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
2 |
|
public function setOrderState($orderState) |
136
|
|
|
{ |
137
|
2 |
|
$this->orderState = $orderState; |
138
|
|
|
|
139
|
2 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return StateReference |
144
|
|
|
*/ |
145
|
2 |
|
public function getState() |
146
|
|
|
{ |
147
|
2 |
|
return $this->state; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param StateReference $state |
152
|
|
|
* @return $this |
153
|
|
|
*/ |
154
|
2 |
|
public function setState(StateReference $state) |
155
|
|
|
{ |
156
|
2 |
|
$this->state = $state; |
157
|
|
|
|
158
|
2 |
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
2 |
|
public function getShipmentState() |
165
|
|
|
{ |
166
|
2 |
|
return $this->shipmentState; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $shipmentState |
171
|
|
|
* @return $this |
172
|
|
|
*/ |
173
|
2 |
|
public function setShipmentState($shipmentState) |
174
|
|
|
{ |
175
|
2 |
|
$this->shipmentState = $shipmentState; |
176
|
|
|
|
177
|
2 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $cartId |
182
|
|
|
* @param int $version |
183
|
|
|
* @param Context $context |
184
|
|
|
*/ |
185
|
46 |
|
public function __construct($cartId, $version, Context $context = null) |
186
|
|
|
{ |
187
|
46 |
|
parent::__construct(OrdersEndpoint::endpoint(), $context); |
188
|
46 |
|
$this->setCartId($cartId)->setVersion($version); |
189
|
46 |
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param string $cartId |
193
|
|
|
* @param int $version |
194
|
|
|
* @param Context $context |
195
|
|
|
* @return static |
196
|
|
|
*/ |
197
|
46 |
|
public static function ofCartIdAndVersion($cartId, $version, Context $context = null) |
198
|
|
|
{ |
199
|
46 |
|
return new static($cartId, $version, $context); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param ResponseInterface $response |
204
|
|
|
* @return AbstractApiResponse |
205
|
|
|
* @internal |
206
|
|
|
*/ |
207
|
41 |
|
public function buildResponse(ResponseInterface $response) |
208
|
|
|
{ |
209
|
41 |
|
return new ResourceResponse($response, $this, $this->getContext()); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return JsonRequest |
214
|
|
|
* @internal |
215
|
|
|
*/ |
216
|
43 |
|
public function httpRequest() |
217
|
|
|
{ |
218
|
|
|
$payload = [ |
219
|
43 |
|
static::ID => $this->getCartId(), |
220
|
43 |
|
static::VERSION => $this->getVersion(), |
221
|
|
|
]; |
222
|
43 |
|
if (!is_null($this->paymentState)) { |
223
|
2 |
|
$payload[static::PAYMENT_STATE] = $this->getPaymentState(); |
224
|
|
|
} |
225
|
43 |
|
if (!is_null($this->orderNumber)) { |
226
|
5 |
|
$payload[static::ORDER_NUMBER] = $this->getOrderNumber(); |
227
|
|
|
} |
228
|
43 |
|
if (!is_null($this->orderState)) { |
229
|
2 |
|
$payload[static::ORDER_STATE] = $this->getOrderState(); |
230
|
|
|
} |
231
|
43 |
|
if (!is_null($this->state)) { |
232
|
2 |
|
$payload[static::STATE] = $this->getState(); |
233
|
|
|
} |
234
|
43 |
|
if (!is_null($this->shipmentState)) { |
235
|
2 |
|
$payload[static::SHIPMENT_STATE] = $this->getShipmentState(); |
236
|
|
|
} |
237
|
43 |
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|