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\Exception\InvalidRequestException; |
10
|
|
|
|
11
|
|
|
class SearchOrdersRequest extends AbstractRequest |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
private $params = []; |
14
|
|
|
|
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
$this->params['Search']['Field'] = implode(',', [ |
18
|
|
|
'OrderId', 'Version', 'OriginalOrderId', 'ParentOrderId', 'DeviceType', 'IsSeen', 'IsSplit', 'IsRoyalty', |
19
|
|
|
'IsSeller', 'IsAffiliate', 'IsRatingB2s', 'OrderTime', 'ExistMultiReleaseDate', 'ReleaseDate', |
20
|
|
|
'LastUpdateTime', 'Suspect', 'OrderStatus', 'StoreStatus', 'RoyaltyFixTime', 'PrintSlipFlag', |
21
|
|
|
'PrintDeliveryFlag', 'PrintBillFlag', 'BuyerCommentsFlag', 'PayStatus', 'SettleStatus', 'PayType', |
22
|
|
|
'PayMethod', 'PayMethodName', 'PayDate', 'SettleId', 'UseWallet', 'NeedBillSlip', 'NeedDetailedSlip', |
23
|
|
|
'NeedReceipt', 'BillFirstName', 'BillFirstNameKana', 'BillLastName', 'BillLastNameKana', 'BillPrefecture', |
24
|
|
|
'ShipStatus', 'ShipMethod', 'ShipRequestDate', 'ShipRequestTime', 'ShipNotes', 'ShipInvoiceNumber1', |
25
|
|
|
'ShipInvoiceNumber2', 'ArriveType', 'ShipDate', 'NeedGiftWrap', 'NeedGiftWrapMessage', 'NeedGiftWrapPaper', |
26
|
|
|
'ShipFirstName', 'ShipFirstNameKana', 'ShipLastName', 'ShipLastNameKana', 'ShipPrefecture', 'PayCharge', |
27
|
|
|
'ShipCharge', 'GiftWrapCharge', 'Discount', 'UsePoint', 'TotalPrice', 'RefundTotalPrice', 'UsePointType', |
28
|
|
|
'IsGetPointFixAll', 'SellerId', 'IsLogin', 'PayNo', 'PayNoIssueDate', 'SellerType', 'IsPayManagement', |
29
|
|
|
'ShipUrl', 'ShipMethodName', 'ArrivalDate', 'TotalMallCouponDiscount', |
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $sellerId |
35
|
|
|
* @return self |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function setSellerId(string $sellerId): self |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
if (isset($this->params['SellerId'])) { |
40
|
|
|
throw new LogicException('SellerId is already set.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->params['SellerId'] = $sellerId; |
44
|
|
|
|
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param null|DateTimeImmutable $from |
50
|
|
|
* @param null|DateTimeImmutable $to |
51
|
|
|
* @return self |
52
|
|
|
*/ |
53
|
|
|
public function setOrderedDateTimeRange(DateTimeImmutable $from = null, DateTimeImmutable $to = null): self |
54
|
|
|
{ |
55
|
|
|
if (null === $from && null === $to) { |
56
|
|
|
throw new InvalidArgumentException('Either OrderTimeFrom or OrderTimeTo has to be set.'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (null !== $from && |
60
|
|
|
null !== $to && |
61
|
|
|
$from > $to) { |
62
|
|
|
throw new LogicException('OrderTimeFrom has to be earlier than OrderTimeTo.'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (isset($this->params['Search']['Condition']['OrderTimeFrom'])) { |
66
|
|
|
throw new LogicException('OrderTimeFrom is already set.'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (isset($this->params['Search']['Condition']['OrderTimeTo'])) { |
70
|
|
|
throw new LogicException('OrderTimeTo is already set.'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
if (null !== $from) { |
|
|
|
|
74
|
|
|
$this->params['Search']['Condition']['OrderTimeFrom'] = $from->format('YmdHis'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
if (null !== $to) { |
|
|
|
|
78
|
|
|
$this->params['Search']['Condition']['OrderTimeTo'] = $to->format('YmdHis'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param int $offset |
86
|
|
|
* @return self |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function setOffset(int $offset): self |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
if ($offset < 0) { |
91
|
|
|
throw new InvalidArgumentException; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (isset($this->params['Search']['Start'])) { |
95
|
|
|
throw new LogicException('Start is already set.'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->params['Search']['Start'] = $offset + 1; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param int $limit |
105
|
|
|
* @return self |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function setLimit(int $limit): self |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
if ($limit < 0) { |
110
|
|
|
throw new InvalidArgumentException; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if (isset($this->params['Search']['Result'])) { |
114
|
|
|
throw new LogicException('Result is already set.'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$this->params['Search']['Result'] = $limit; |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getParams() |
126
|
|
|
{ |
127
|
|
|
$this->validateRequest(); |
128
|
|
|
|
129
|
|
|
$fluidXml = new FluidXml('Req'); |
130
|
|
|
$fluidXml->add($this->params); |
131
|
|
|
|
132
|
|
|
return $fluidXml->xml(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @throws InvalidRequestException |
137
|
|
|
*/ |
138
|
|
|
private function validateRequest(): void |
139
|
|
|
{ |
140
|
|
|
if (! isset($this->params['SellerId'])) { |
141
|
|
|
throw new InvalidRequestException; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|