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