1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shippinno\YahooShoppingJp\Request; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use FluidXml\FluidXml; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use LogicException; |
9
|
|
|
use Shippinno\YahooShoppingJp\Api\AbstractApi; |
10
|
|
|
use Shippinno\YahooShoppingJp\Api\SearchOrdersApi; |
11
|
|
|
use Shippinno\YahooShoppingJp\Enum\OrderStatus; |
12
|
|
|
use Shippinno\YahooShoppingJp\Enum\ShipStatus; |
13
|
|
|
use Shippinno\YahooShoppingJp\Enum\StoreStatus; |
14
|
|
|
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException; |
15
|
|
|
use Shippinno\YahooShoppingJp\Response\AbstractResponse; |
16
|
|
|
use Shippinno\YahooShoppingJp\Response\SearchOrdersResponse; |
17
|
|
|
|
18
|
|
|
class SearchOrdersRequest extends AbstractRequest |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->params['Search']['Field'] = implode(',', [ |
24
|
|
|
'OrderId', |
25
|
|
|
'Version', |
26
|
|
|
'OriginalOrderId', |
27
|
|
|
'ParentOrderId', |
28
|
|
|
'DeviceType', |
29
|
|
|
'IsSeen', |
30
|
|
|
'IsSplit', |
31
|
|
|
'IsRoyalty', |
32
|
|
|
'IsSeller', |
33
|
|
|
'IsAffiliate', |
34
|
|
|
'IsRatingB2s', |
35
|
|
|
'OrderTime', |
36
|
|
|
'ExistMultiReleaseDate', |
37
|
|
|
'ReleaseDate', |
38
|
|
|
'LastUpdateTime', |
39
|
|
|
'Suspect', |
40
|
|
|
'OrderStatus', |
41
|
|
|
'StoreStatus', |
42
|
|
|
'RoyaltyFixTime', |
43
|
|
|
'PrintSlipFlag', |
44
|
|
|
'PrintDeliveryFlag', |
45
|
|
|
'PrintBillFlag', |
46
|
|
|
'BuyerCommentsFlag', |
47
|
|
|
'PayStatus', |
48
|
|
|
'SettleStatus', |
49
|
|
|
'PayType', |
50
|
|
|
'PayMethod', |
51
|
|
|
'PayMethodName', |
52
|
|
|
'PayDate', |
53
|
|
|
'SettleId', |
54
|
|
|
'UseWallet', |
55
|
|
|
'NeedBillSlip', |
56
|
|
|
'NeedDetailedSlip', |
57
|
|
|
'NeedReceipt', |
58
|
|
|
'BillFirstName', |
59
|
|
|
'BillFirstNameKana', |
60
|
|
|
'BillLastName', |
61
|
|
|
'BillLastNameKana', |
62
|
|
|
'BillPrefecture', |
63
|
|
|
'ShipStatus', |
64
|
|
|
'ShipMethod', |
65
|
|
|
'ShipRequestDate', |
66
|
|
|
'ShipRequestTime', |
67
|
|
|
'ShipNotes', |
68
|
|
|
'ShipInvoiceNumber1', |
69
|
|
|
'ShipInvoiceNumber2', |
70
|
|
|
'ArriveType', |
71
|
|
|
'ShipDate', |
72
|
|
|
'NeedGiftWrap', |
73
|
|
|
'NeedGiftWrapMessage', |
74
|
|
|
'NeedGiftWrapPaper', |
75
|
|
|
'ShipFirstName', |
76
|
|
|
'ShipFirstNameKana', |
77
|
|
|
'ShipLastName', |
78
|
|
|
'ShipLastNameKana', |
79
|
|
|
'ShipPrefecture', |
80
|
|
|
'PayCharge', |
81
|
|
|
'ShipCharge', |
82
|
|
|
'GiftWrapCharge', |
83
|
|
|
'Discount', |
84
|
|
|
'UsePoint', |
85
|
|
|
'TotalPrice', |
86
|
|
|
'RefundTotalPrice', |
87
|
|
|
'UsePointType', |
88
|
|
|
'IsGetPointFixAll', |
89
|
|
|
'SellerId', |
90
|
|
|
'IsLogin', |
91
|
|
|
'PayNo', |
92
|
|
|
'PayNoIssueDate', |
93
|
|
|
'SellerType', |
94
|
|
|
'IsPayManagement', |
95
|
|
|
'ShipUrl', |
96
|
|
|
'ShipMethodName', |
97
|
|
|
'ArrivalDate', |
98
|
|
|
'TotalMallCouponDiscount', |
99
|
|
|
]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return AbstractApi |
104
|
|
|
*/ |
105
|
|
|
public function api() |
106
|
|
|
{ |
107
|
|
|
return new SearchOrdersApi; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return AbstractResponse |
112
|
|
|
*/ |
113
|
|
|
public function response() |
114
|
|
|
{ |
115
|
|
|
return new SearchOrdersResponse; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
protected function validateParams() |
122
|
|
|
{ |
123
|
|
|
if (!isset($this->params['SellerId'])) { |
124
|
|
|
throw new InvalidRequestException; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if(!isset($this->params['Search']['Condition']['OrderId']) |
128
|
|
|
&& !isset($this->params['Search']['Condition']['OrderTime']) |
129
|
|
|
&& !isset($this->params['Search']['Condition']['OrderTimeFrom']) |
130
|
|
|
&& !isset($this->params['Search']['Condition']['OrderTimeTo'])) { |
131
|
|
|
|
132
|
|
|
throw new InvalidRequestException('OrderId,OrderTime or OrderTimeFrom&OrderTimeTo is necessary.'); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getParams() |
141
|
|
|
{ |
142
|
|
|
$this->validateParams(); |
143
|
|
|
|
144
|
|
|
$fluidXml = new FluidXml('Req'); |
145
|
|
|
$fluidXml->add($this->params); |
146
|
|
|
|
147
|
|
|
return $fluidXml->xml(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $orderId |
152
|
|
|
* @return self |
153
|
|
|
*/ |
154
|
|
|
public function setOrderId(string $orderId): self |
155
|
|
|
{ |
156
|
|
|
if (isset($this->params['Search']['Condition']['OrderId'])) { |
157
|
|
|
throw new LogicException('OrderId is already set.'); |
158
|
|
|
} |
159
|
|
|
$this->params['Search']['Condition']['OrderId'] = $orderId; |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param string $sellerId |
166
|
|
|
* @return self |
167
|
|
|
*/ |
168
|
|
View Code Duplication |
public function setSellerId(string $sellerId): self |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
if (isset($this->params['SellerId'])) { |
171
|
|
|
throw new LogicException('SellerId is already set.'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$this->params['SellerId'] = $sellerId; |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param bool $isSeen |
181
|
|
|
* @return self |
182
|
|
|
*/ |
183
|
|
|
public function setIsSeen(bool $isSeen): self |
184
|
|
|
{ |
185
|
|
|
if (isset($this->params['Search']['Condition']['IsSeen'])) { |
186
|
|
|
throw new LogicException('IsSeen is already set.'); |
187
|
|
|
} |
188
|
|
|
$this->params['Search']['Condition']['IsSeen'] = $isSeen ? 'true' : 'false'; |
189
|
|
|
|
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param null|DateTimeImmutable $from |
195
|
|
|
* @param null|DateTimeImmutable $to |
196
|
|
|
* @return self |
197
|
|
|
*/ |
198
|
|
|
public function setOrderedDateTimeRange(DateTimeImmutable $from = null, DateTimeImmutable $to = null): self |
199
|
|
|
{ |
200
|
|
|
if (null === $from && null === $to) { |
201
|
|
|
throw new InvalidArgumentException('Either OrderTimeFrom or OrderTimeTo has to be set.'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
if (null !== $from && |
205
|
|
|
null !== $to && |
206
|
|
|
$from > $to |
207
|
|
|
) { |
208
|
|
|
throw new LogicException('OrderTimeFrom has to be earlier than OrderTimeTo.'); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
if (isset($this->params['Search']['Condition']['OrderTimeFrom'])) { |
212
|
|
|
throw new LogicException('OrderTimeFrom is already set.'); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
if (isset($this->params['Search']['Condition']['OrderTimeTo'])) { |
216
|
|
|
throw new LogicException('OrderTimeTo is already set.'); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
View Code Duplication |
if (null !== $from) { |
|
|
|
|
220
|
|
|
$this->params['Search']['Condition']['OrderTimeFrom'] = $from->format('YmdHis'); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
View Code Duplication |
if (null !== $to) { |
|
|
|
|
224
|
|
|
$this->params['Search']['Condition']['OrderTimeTo'] = $to->format('YmdHis'); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param OrderStatus $orderStatus |
232
|
|
|
* @return self |
233
|
|
|
*/ |
234
|
|
|
public function setOrderStatus(OrderStatus $orderStatus): self |
235
|
|
|
{ |
236
|
|
|
if (isset($this->params['Search']['Condition']['OrderStatus'])) { |
237
|
|
|
throw new LogicException('OrderStatus is already set.'); |
238
|
|
|
} |
239
|
|
|
$this->params['Search']['Condition']['OrderStatus'] = $orderStatus->getValue(); |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param ShipStatus $shipStatus |
246
|
|
|
* @return self |
247
|
|
|
*/ |
248
|
|
|
public function setShipStatus(ShipStatus $shipStatus): self |
249
|
|
|
{ |
250
|
|
|
if (isset($this->params['Search']['Condition']['ShipStatus'])) { |
251
|
|
|
throw new LogicException('ShipStatus is already set.'); |
252
|
|
|
} |
253
|
|
|
$this->params['Search']['Condition']['ShipStatus'] = $shipStatus->getValue(); |
254
|
|
|
|
255
|
|
|
return $this; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param StoreStatus $shipStatus |
260
|
|
|
* @return self |
261
|
|
|
*/ |
262
|
|
|
public function setStoreStatus(StoreStatus $shipStatus): self |
263
|
|
|
{ |
264
|
|
|
if (isset($this->params['Search']['Condition']['StoreStatus'])) { |
265
|
|
|
throw new LogicException('StoreStatus is already set.'); |
266
|
|
|
} |
267
|
|
|
$this->params['Search']['Condition']['StoreStatus'] = $shipStatus->getValue(); |
268
|
|
|
|
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param int $offset |
274
|
|
|
* @return self |
275
|
|
|
*/ |
276
|
|
View Code Duplication |
public function setOffset(int $offset): self |
|
|
|
|
277
|
|
|
{ |
278
|
|
|
if ($offset < 0) { |
279
|
|
|
throw new InvalidArgumentException; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
if (isset($this->params['Search']['Start'])) { |
283
|
|
|
throw new LogicException('Start is already set.'); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
$this->params['Search']['Start'] = $offset + 1; |
287
|
|
|
|
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param int $limit |
293
|
|
|
* @return self |
294
|
|
|
*/ |
295
|
|
View Code Duplication |
public function setLimit(int $limit): self |
|
|
|
|
296
|
|
|
{ |
297
|
|
|
if ($limit < 0) { |
298
|
|
|
throw new InvalidArgumentException; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
if (isset($this->params['Search']['Result'])) { |
302
|
|
|
throw new LogicException('Result is already set.'); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$this->params['Search']['Result'] = $limit; |
306
|
|
|
|
307
|
|
|
return $this; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
} |
311
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.