1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
namespace Commercetools\Core\Request\ProductDiscounts; |
6
|
|
|
|
7
|
|
|
use Commercetools\Core\Client\HttpMethod; |
8
|
|
|
use Commercetools\Core\Client\JsonRequest; |
9
|
|
|
use Commercetools\Core\Model\Common\Context; |
10
|
|
|
use Commercetools\Core\Model\Common\Price; |
11
|
|
|
use Commercetools\Core\Model\ProductDiscount\ProductDiscount; |
12
|
|
|
use Commercetools\Core\Request\AbstractApiRequest; |
13
|
|
|
use Commercetools\Core\Response\ApiResponseInterface; |
14
|
|
|
use Commercetools\Core\Response\ResourceResponse; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
use Commercetools\Core\Model\MapperInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @package Commercetools\Core\Request\ProductDiscounts |
20
|
|
|
* |
21
|
|
|
* @method ProductDiscount mapResponse(ApiResponseInterface $response) |
22
|
|
|
* @method ProductDiscount mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
23
|
|
|
*/ |
24
|
|
|
class ProductDiscountMatchingRequest extends AbstractApiRequest |
25
|
|
|
{ |
26
|
|
|
protected $resultClass = ProductDiscount::class; |
27
|
|
|
|
28
|
|
|
const PRODUCT_ID = 'productId'; |
29
|
|
|
const VARIANT_ID = 'variantId'; |
30
|
|
|
const STAGED = 'staged'; |
31
|
|
|
const PRICE = 'price'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $productId; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
protected $variantId; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var bool |
45
|
|
|
*/ |
46
|
|
|
protected $staged; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Price |
50
|
|
|
*/ |
51
|
|
|
protected $price; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Price $price |
55
|
|
|
* @param Context $context |
56
|
|
|
*/ |
57
|
5 |
|
public function __construct(Price $price, Context $context = null) |
58
|
|
|
{ |
59
|
5 |
|
parent::__construct(ProductDiscountsEndpoint::endpoint(), $context); |
60
|
5 |
|
$this->price = $price; |
61
|
5 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
5 |
|
public function getProductId() |
67
|
|
|
{ |
68
|
5 |
|
return $this->productId; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $productId |
73
|
|
|
* @return ProductDiscountMatchingRequest |
74
|
|
|
*/ |
75
|
5 |
|
public function setProductId($productId) |
76
|
|
|
{ |
77
|
5 |
|
$this->productId = $productId; |
78
|
5 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
5 |
|
public function getVariantId() |
85
|
|
|
{ |
86
|
5 |
|
return $this->variantId; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param int $variantId |
91
|
|
|
* @return ProductDiscountMatchingRequest |
92
|
|
|
*/ |
93
|
5 |
|
public function setVariantId($variantId) |
94
|
|
|
{ |
95
|
5 |
|
$this->variantId = $variantId; |
96
|
5 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
5 |
|
public function getStaged() |
103
|
|
|
{ |
104
|
5 |
|
return $this->staged; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param bool $staged |
109
|
|
|
* @return ProductDiscountMatchingRequest |
110
|
|
|
*/ |
111
|
1 |
|
public function setStaged($staged) |
112
|
|
|
{ |
113
|
1 |
|
$this->staged = $staged; |
114
|
1 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return Price |
119
|
|
|
*/ |
120
|
5 |
|
public function getPrice() |
121
|
|
|
{ |
122
|
5 |
|
return $this->price; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param Price $price |
127
|
|
|
* @return ProductDiscountMatchingRequest |
128
|
|
|
*/ |
129
|
|
|
public function setPrice(Price $price) |
130
|
|
|
{ |
131
|
|
|
$this->price = $price; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $productId |
137
|
|
|
* @param int $variantId |
138
|
|
|
* @param Price $price |
139
|
|
|
* @param Context $context |
140
|
|
|
* @return ProductDiscountMatchingRequest |
141
|
|
|
*/ |
142
|
5 |
|
public static function ofProductIdVariantIdAndPrice($productId, $variantId, Price $price, Context $context = null) |
143
|
|
|
{ |
144
|
5 |
|
$request = new static($price, $context); |
145
|
5 |
|
$request->setProductId($productId)->setVariantId($variantId); |
146
|
|
|
|
147
|
5 |
|
return $request; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
* @internal |
153
|
|
|
*/ |
154
|
5 |
|
protected function getPath() |
155
|
|
|
{ |
156
|
5 |
|
return (string)$this->getEndpoint() . '/matching' . $this->getParamString(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return JsonRequest |
161
|
|
|
* @internal |
162
|
|
|
*/ |
163
|
5 |
|
public function httpRequest() |
164
|
|
|
{ |
165
|
|
|
$payload = [ |
166
|
5 |
|
static::PRODUCT_ID => $this->getProductId(), |
167
|
5 |
|
static::VARIANT_ID => $this->getVariantId(), |
168
|
5 |
|
static::STAGED => ($this->getStaged() === true), |
169
|
5 |
|
static::PRICE => $this->getPrice() |
170
|
|
|
]; |
171
|
|
|
|
172
|
5 |
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param ResponseInterface $response |
177
|
|
|
* @return ApiResponseInterface |
178
|
|
|
* @internal |
179
|
|
|
*/ |
180
|
1 |
|
public function buildResponse(ResponseInterface $response) |
181
|
|
|
{ |
182
|
1 |
|
return new ResourceResponse($response, $this, $this->getContext()); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|