1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Request\Me; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Request\InStores\InStoreRequestDecorator; |
9
|
|
|
use Commercetools\Core\Request\InStores\InStoreTrait; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
use Commercetools\Core\Client\HttpMethod; |
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\Me |
23
|
|
|
* @link https://docs.commercetools.com/http-api-projects-me-orders.html#create-order-from-a-cart |
24
|
|
|
* @method Order mapResponse(ApiResponseInterface $response) |
25
|
|
|
* @method Order mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
26
|
|
|
* @method MeOrderCreateFromCartRequest|InStoreRequestDecorator inStore($storeKey) |
27
|
|
|
*/ |
28
|
|
|
class MeOrderCreateFromCartRequest extends AbstractApiRequest |
29
|
|
|
{ |
30
|
|
|
use InStoreTrait; |
31
|
|
|
|
32
|
|
|
const ID = 'id'; |
33
|
|
|
const VERSION = 'version'; |
34
|
|
|
|
35
|
|
|
protected $cartId; |
36
|
|
|
protected $version; |
37
|
|
|
|
38
|
|
|
protected $resultClass = Order::class; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public function getCartId() |
44
|
|
|
{ |
45
|
|
|
return $this->cartId; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $cartId |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function setCartId($cartId) |
53
|
|
|
{ |
54
|
|
|
$this->cartId = $cartId; |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function getVersion() |
63
|
|
|
{ |
64
|
|
|
return $this->version; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $version |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
|
|
public function setVersion($version) |
72
|
|
|
{ |
73
|
|
|
$this->version = $version; |
74
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $cartId |
80
|
|
|
* @param int $version |
81
|
|
|
* @param Context $context |
82
|
|
|
*/ |
83
|
|
|
public function __construct($cartId, $version, Context $context = null) |
84
|
|
|
{ |
85
|
|
|
parent::__construct(MeOrdersEndpoint::endpoint(), $context); |
86
|
|
|
$this->setCartId($cartId)->setVersion($version); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $cartId |
91
|
|
|
* @param int $version |
92
|
|
|
* @param Context $context |
93
|
|
|
* @return static |
94
|
|
|
*/ |
95
|
|
|
public static function ofCartIdAndVersion($cartId, $version, Context $context = null) |
96
|
|
|
{ |
97
|
|
|
return new static($cartId, $version, $context); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param ResponseInterface $response |
102
|
|
|
* @return AbstractApiResponse |
103
|
|
|
* @internal |
104
|
|
|
*/ |
105
|
|
|
public function buildResponse(ResponseInterface $response) |
106
|
|
|
{ |
107
|
|
|
return new ResourceResponse($response, $this, $this->getContext()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return JsonRequest |
112
|
|
|
* @internal |
113
|
|
|
*/ |
114
|
|
|
public function httpRequest() |
115
|
|
|
{ |
116
|
|
|
$payload = [ |
117
|
|
|
static::ID => $this->getCartId(), |
118
|
|
|
static::VERSION => $this->getVersion(), |
119
|
|
|
]; |
120
|
|
|
|
121
|
|
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|