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