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 ManagesInventory |
11
|
|
|
{ |
12
|
|
|
public function getInventoryItems(array $params = []): Collection |
13
|
|
|
{ |
14
|
|
|
$response = $this->get('inventory_items.json', $params); |
|
|
|
|
15
|
|
|
|
16
|
|
|
return $this->transformCollection($response['inventory_items'], ApiResource::class); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function getInventoryItem($inventoryItemId): ApiResource |
20
|
|
|
{ |
21
|
|
|
$response = $this->get("inventory_items/{$inventoryItemId}.json"); |
22
|
|
|
|
23
|
|
|
return new ApiResource($response['inventory_item'], $this); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function updateInventoryItem($inventoryItemId, array $data): ApiResource |
27
|
|
|
{ |
28
|
|
|
$response = $this->put("inventory_items/{$inventoryItemId}.json", ['inventory_item' => $data]); |
|
|
|
|
29
|
|
|
|
30
|
|
|
return new ApiResource($response['inventory_item'], $this); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getInventoryLevels(array $params = []): Collection |
34
|
|
|
{ |
35
|
|
|
$response = $this->get('inventory_levels.json', $params); |
36
|
|
|
|
37
|
|
|
return $this->transformCollection($response['inventory_levels'], ApiResource::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function deleteInventoryLevel($inventoryItemId, $locationId): void |
41
|
|
|
{ |
42
|
|
|
$this->delete('inventory_levels.json', [ |
|
|
|
|
43
|
|
|
'inventory_item_id' => $inventoryItemId, |
44
|
|
|
'location_id' => $locationId, |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function adjustInventoryLevel($inventoryItemId, $locationId, int $availableAdjustment): ApiResource |
49
|
|
|
{ |
50
|
|
|
$response = $this->post('inventory_levels/adjust.json', [ |
|
|
|
|
51
|
|
|
'inventory_item_id' => $inventoryItemId, |
52
|
|
|
'location_id' => $locationId, |
53
|
|
|
'available_adjustment' => $availableAdjustment, |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
return new ApiResource($response['inventory_level'], $this); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function connectInventoryLevel($inventoryItemId, $locationId, bool $relocate = false): ApiResource |
60
|
|
|
{ |
61
|
|
|
$response = $this->post('inventory_levels/connect.json', [ |
62
|
|
|
'inventory_item_id' => $inventoryItemId, |
63
|
|
|
'location_id' => $locationId, |
64
|
|
|
'relocate_if_necessary' => $relocate, |
65
|
|
|
]); |
66
|
|
|
|
67
|
|
|
return new ApiResource($response['inventory_level'], $this); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setInventoryLevel($inventoryItemId, $locationId, int $available, bool $disconnect = false): ApiResource |
71
|
|
|
{ |
72
|
|
|
$response = $this->post('inventory_levels/set.json', [ |
73
|
|
|
'inventory_item_id' => $inventoryItemId, |
74
|
|
|
'location_id' => $locationId, |
75
|
|
|
'available' => $available, |
76
|
|
|
'disconnect_if_necessary' => $disconnect, |
77
|
|
|
]); |
78
|
|
|
|
79
|
|
|
return new ApiResource($response['inventory_level'], $this); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getLocationsCount(array $params = []): int |
83
|
|
|
{ |
84
|
|
|
$response = $this->get('locations/count.json', $params); |
85
|
|
|
|
86
|
|
|
return $response['count'] ?? 0; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getLocations(array $params = []): Collection |
90
|
|
|
{ |
91
|
|
|
$response = $this->get('locations.json', $params); |
92
|
|
|
|
93
|
|
|
return $this->transformCollection($response['locations'], ApiResource::class); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getLocation($locationId): ApiResource |
97
|
|
|
{ |
98
|
|
|
$response = $this->get("locations/{$locationId}.json"); |
99
|
|
|
|
100
|
|
|
return $this->transformItem($response['location'], ApiResource::class); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getLocationInventoryLevels($locationId, array $params = []): Collection |
104
|
|
|
{ |
105
|
|
|
$response = $this->get("locations/{$locationId}/inventory_levels.json", $params); |
106
|
|
|
|
107
|
|
|
return $this->transformCollection($response['inventory_levels'], ApiResource::class); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|