1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Signifly\Shopify\REST\Actions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Signifly\Shopify\REST\Resources\ApiResource; |
7
|
|
|
use Signifly\Shopify\Shopify; |
8
|
|
|
|
9
|
|
|
/** @mixin Shopify */ |
10
|
|
|
trait ManagesFulfillments |
11
|
|
|
{ |
12
|
|
|
public function getOrderFulfillmentsCount($orderId, array $params = []): int |
13
|
|
|
{ |
14
|
|
|
return $this->getResourceCount('fulfillments', $params, ['orders', $orderId]); |
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function getOrderFulfillments($orderId, array $params = []): Collection |
18
|
|
|
{ |
19
|
|
|
return $this->getResources('fulfillments', $params, ['orders', $orderId]); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getOrderFulfillment($orderId, $fulfillmentId): ApiResource |
23
|
|
|
{ |
24
|
|
|
return $this->getResource('fulfillments', $fulfillmentId, ['orders', $orderId]); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function createOrderFulfillment($orderId, array $data): ApiResource |
28
|
|
|
{ |
29
|
|
|
return $this->createResource('fulfillments', $data, ['orders', $orderId]); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function createFulfillment(array $data): ApiResource |
33
|
|
|
{ |
34
|
|
|
return $this->createResource('fulfillments', $data); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function updateOrderFulfillment($orderId, $fulfillmentId, array $data): ApiResource |
38
|
|
|
{ |
39
|
|
|
return $this->updateResource('fulfillments', $fulfillmentId, $data, ['orders', $orderId]); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function updateTrackingForFulfillment($fulfillmentId, array $data): ApiResource |
43
|
|
|
{ |
44
|
|
|
$response = $this->post("fulfillments/{$fulfillmentId}/update_tracking.json", $data); |
|
|
|
|
45
|
|
|
|
46
|
|
|
return new ApiResource($response['fulfillment'], $this); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function completeOrderFulfillment($orderId, $fulfillmentId): ApiResource |
50
|
|
|
{ |
51
|
|
|
$response = $this->post("orders/{$orderId}/fulfillments/{$fulfillmentId}/complete.json"); |
52
|
|
|
|
53
|
|
|
return new ApiResource($response['fulfillment'], $this); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function openOrderFulfillment($orderId, $fulfillmentId): ApiResource |
57
|
|
|
{ |
58
|
|
|
$response = $this->post("orders/{$orderId}/fulfillments/{$fulfillmentId}/open.json"); |
59
|
|
|
|
60
|
|
|
return new ApiResource($response['fulfillment'], $this); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function cancelOrderFulfillment($orderId, $fulfillmentId): ApiResource |
64
|
|
|
{ |
65
|
|
|
$response = $this->post("orders/{$orderId}/fulfillments/{$fulfillmentId}/cancel.json"); |
66
|
|
|
|
67
|
|
|
return new ApiResource($response['fulfillment'], $this); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function cancelFulfillment($fulfillmentId): ApiResource |
71
|
|
|
{ |
72
|
|
|
$response = $this->post("fulfillments/{$fulfillmentId}/cancel.json"); |
73
|
|
|
|
74
|
|
|
return new ApiResource($response['fulfillment'], $this); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getFulfillmentOrderFulfillments($fulfillmentOrderId, array $params = []): Collection |
78
|
|
|
{ |
79
|
|
|
return $this->getResources('fulfillments', $params, ['fulfillment_orders', $fulfillmentOrderId]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getOrderFulfillmentEvents($orderId, $fulfillmentId, array $params = []): Collection |
83
|
|
|
{ |
84
|
|
|
return $this->getResources('events', $params, ['orders', $orderId, 'fulfillments', $fulfillmentId]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getOrderFulfillmentEvent($orderId, $fulfillmentId, $eventId): ApiResource |
88
|
|
|
{ |
89
|
|
|
return $this->getResource('events', $eventId, ['orders', $orderId, 'fulfillments', $fulfillmentId]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function createOrderFulfillmentEvent($orderId, $fulfillmentId, array $data): ApiResource |
93
|
|
|
{ |
94
|
|
|
return $this->createResource('events', $data, ['orders', $orderId, 'fulfillments', $fulfillmentId]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function deleteOrderFulfillmentEvent($orderId, $fulfillmentId, $eventId): void |
98
|
|
|
{ |
99
|
|
|
$this->deleteResource('events', $eventId, ['orders', $orderId, 'fulfillments', $fulfillmentId]); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getOrderFulfillmentOrders($orderId, array $params = []): Collection |
103
|
|
|
{ |
104
|
|
|
return $this->getResources('fulfillment_orders', $params, ['orders', $orderId]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getFulfillmentOrder($fulfillmentOrderId): ApiResource |
108
|
|
|
{ |
109
|
|
|
return $this->getResource('fulfillment_orders', $fulfillmentOrderId); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function cancelFulfillmentOrder($fulfillmentOrderId): ApiResource |
113
|
|
|
{ |
114
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/cancel.json"); |
115
|
|
|
|
116
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function closeFulfillmentOrder($fulfillmentOrderId, array $data): ApiResource |
120
|
|
|
{ |
121
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/close.json", [ |
122
|
|
|
'fulfillment_order' => $data, |
123
|
|
|
]); |
124
|
|
|
|
125
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function moveFulfillmentOrder($fulfillmentOrderId, array $data): ApiResource |
129
|
|
|
{ |
130
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/close.json", [ |
131
|
|
|
'fulfillment_order' => $data, |
132
|
|
|
]); |
133
|
|
|
|
134
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getFulfillmentOrderLocationsForMove($fulfillmentOrderId, array $params = []): Collection |
138
|
|
|
{ |
139
|
|
|
return $this->getResources('locations_for_move', $params, ['fulfillment_orders', $fulfillmentOrderId]); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function sendFulfillmentOrderFulfillmentRequest($fulfillmentOrderId, array $data = []): ApiResource |
143
|
|
|
{ |
144
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/fulfillment_request.json", [ |
145
|
|
|
'fulfillment_request' => $data, |
146
|
|
|
]); |
147
|
|
|
|
148
|
|
|
return new ApiResource($response['original_fulfillment_order'], $this); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function acceptFulfillmentOrderFulfillmentRequest($fulfillmentOrderId, array $data = []): ApiResource |
152
|
|
|
{ |
153
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/fulfillment_request/accept.json", [ |
154
|
|
|
'fulfillment_request' => $data, |
155
|
|
|
]); |
156
|
|
|
|
157
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function rejectFulfillmentOrderFulfillmentRequest($fulfillmentOrderId, array $data = []): ApiResource |
161
|
|
|
{ |
162
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/fulfillment_request/reject.json", [ |
163
|
|
|
'fulfillment_request' => $data, |
164
|
|
|
]); |
165
|
|
|
|
166
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function createFulfillmentService(array $data): ApiResource |
170
|
|
|
{ |
171
|
|
|
return $this->createResource('fulfillment_services', $data); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function getFulfillmentServices(array $params = []): Collection |
175
|
|
|
{ |
176
|
|
|
return $this->getResources('fulfillment_services', $params); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function getFulfillmentService($fulfillmentServiceId): ApiResource |
180
|
|
|
{ |
181
|
|
|
return $this->getResource('fulfillment_services', $fulfillmentServiceId); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function updateFulfillmentService($fulfillmentServiceId, array $data): ApiResource |
185
|
|
|
{ |
186
|
|
|
return $this->updateResource('fulfillment_services', $fulfillmentServiceId, $data); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function deleteFulfillmentService($fulfillmentServiceId): void |
190
|
|
|
{ |
191
|
|
|
$this->deleteResource('fulfillment_services', $fulfillmentServiceId); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function createCarrierService(array $data): ApiResource |
195
|
|
|
{ |
196
|
|
|
return $this->createResource('carrier_services', $data); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function getCarrierServices(array $params = []): Collection |
200
|
|
|
{ |
201
|
|
|
return $this->getResources('carrier_services', $params); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function getCarrierService($carrierServiceId): ApiResource |
205
|
|
|
{ |
206
|
|
|
return $this->getResource('carrier_services', $carrierServiceId); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function updateCarrierService($carrierServiceId, array $data): ApiResource |
210
|
|
|
{ |
211
|
|
|
return $this->updateResource('carrier_services', $carrierServiceId, $data); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function deleteCarrierService($carrierServiceId): void |
215
|
|
|
{ |
216
|
|
|
$this->deleteResource('carrier_services', $carrierServiceId); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function sendFulfillmentOrderCancellationRequest($fulfillmentOrderId, array $data = []): ApiResource |
220
|
|
|
{ |
221
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/cancellation_request.json", [ |
222
|
|
|
'cancellation_request' => $data, |
223
|
|
|
]); |
224
|
|
|
|
225
|
|
|
return new ApiResource($response['original_fulfillment_order'], $this); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function acceptFulfillmentOrderCancellationRequest($fulfillmentOrderId, array $data = []): ApiResource |
229
|
|
|
{ |
230
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/cancellation_request/accept.json", [ |
231
|
|
|
'cancellation_request' => $data, |
232
|
|
|
]); |
233
|
|
|
|
234
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function rejectFulfillmentOrderCancellationRequest($fulfillmentOrderId, array $data = []): ApiResource |
238
|
|
|
{ |
239
|
|
|
$response = $this->post("fulfillment_orders/{$fulfillmentOrderId}/cancellation_request/reject.json", [ |
240
|
|
|
'cancellation_request' => $data, |
241
|
|
|
]); |
242
|
|
|
|
243
|
|
|
return new ApiResource($response['fulfillment_order'], $this); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function getAssignedFulfillmentOrders(string $assignmentStatus, array $locationIds): Collection |
247
|
|
|
{ |
248
|
|
|
$response = $this->get('assigned_fulfillment_orders.json', [ |
|
|
|
|
249
|
|
|
'assignment_status' => $assignmentStatus, |
250
|
|
|
'location_ids' => $locationIds, |
251
|
|
|
]); |
252
|
|
|
|
253
|
|
|
return $this->transformCollection($response['fulfillment_orders'], ApiResource::class); |
|
|
|
|
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|