-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathInventoryItemService.php
60 lines (55 loc) · 2.08 KB
/
InventoryItemService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Shopify\Service;
use Shopify\Object\InventoryItem;
class InventoryItemService extends AbstractService
{
/**
* Retrieves a list of inventory items.
* Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header.
* Sending the page parameter will return an error.
* To learn more, see Making requests to paginated REST Admin API endpoints.
*
* @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventoryitem#index-2020-07
* @param array $params
* @return InventoryItem[]
*/
public function all(array $params = []){
$endpoint = 'inventory_items.json';
$response = $this->request($endpoint, 'GET', $params);
return $this->createCollection(InventoryItem::class, $response['inventory_item']);
}
/**
* Retrieves a single inventory item by ID
*
* @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventoryitem#show-2020-07
* @param int $inventroyItemId
* @param array $fields
* @return InventoryItem[]
*/
public function get(int $inventroyItemId, array $fields = []){
$params = [];
if (!empty($fields)) {
$params['fields'] = $fields;
}
$endpoint = 'inventory_items/'.$inventroyItemId.'.json';
$response = $this->request($endpoint, 'GET', $params);
return $this->createObject(InventoryItem::class, $response['inventory_item']);
}
/**
* Updates an existing inventory item
*
* @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventoryitem#update-2020-07
* @param InventoryItem $inventoryItem
* @return void
*/
public function update(InventoryItem &$inventoryItem){
$data = $inventoryItem->exportData();
$endpoint = 'inventory_items/'.$inventoryItem->id.'.json';
$response = $this->request(
$endpoint, 'PUT', array(
'inventory_item' => $data
)
);
$inventoryItem->setData($response['inventory_item']);
}
}