1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helix\Shopify; |
4
|
|
|
|
5
|
|
|
use Helix\Shopify\Base\Data; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* An inventory level, which acts as a join between a location and an inventory item. |
9
|
|
|
* |
10
|
|
|
* @see https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel |
11
|
|
|
* |
12
|
|
|
* @see Location::newInventoryLevel() |
13
|
|
|
* |
14
|
|
|
* @method null|int getAvailable () |
15
|
|
|
* @method string getInventoryItemId () injected |
16
|
|
|
* @method string getLocationId () injected |
17
|
|
|
* @method string getUpdatedAt () |
18
|
|
|
*/ |
19
|
|
|
class InventoryLevel extends Data { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param int $qty +/- |
23
|
|
|
* @return $this |
24
|
|
|
*/ |
25
|
|
|
public function adjustAvailable (int $qty) { |
26
|
|
|
$remote = $this->api->post('inventory_levels', [ |
27
|
|
|
'inventory_item_id' => $this->getInventoryItemId(), |
28
|
|
|
'location_id' => $this->getLocationId(), |
29
|
|
|
'available_adjustment' => $qty |
30
|
|
|
]); |
31
|
|
|
return $this->_setData($remote['inventory_level']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param bool $relocate |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
|
|
public function connect (bool $relocate = false) { |
39
|
|
|
$remote = $this->api->post('inventory_levels/connect', [ |
40
|
|
|
'inventory_item_id' => $this->getInventoryItemId(), |
41
|
|
|
'location_id' => $this->getLocationId(), |
42
|
|
|
'relocate_if_necessary' => $relocate |
43
|
|
|
]); |
44
|
|
|
return $this->_setData($remote['inventory_level']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function disconnect (): void { |
48
|
|
|
$this->api->delete('inventory_levels', [ |
49
|
|
|
'inventory_item_id' => $this->getInventoryItemId(), |
50
|
|
|
'location_id' => $this->getLocationId() |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return InventoryItem |
56
|
|
|
*/ |
57
|
|
|
public function getInventoryItem () { |
58
|
|
|
return InventoryItem::load($this, $this->getInventoryItemId()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return Location |
63
|
|
|
*/ |
64
|
|
|
public function getLocation () { |
65
|
|
|
return Location::load($this, $this->getLocationId()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int $qty |
70
|
|
|
* @return InventoryLevel |
71
|
|
|
*/ |
72
|
|
|
public function setAvailable (int $qty) { |
73
|
|
|
$remote = $this->api->post('inventory_levels', [ |
74
|
|
|
'inventory_item_id' => $this->getInventoryItemId(), |
75
|
|
|
'location_id' => $this->getLocationId(), |
76
|
|
|
'available' => $qty |
77
|
|
|
]); |
78
|
|
|
return $this->_setData($remote['inventory_level']); |
79
|
|
|
} |
80
|
|
|
} |