Skip to content

Commit 1d0bb73

Browse files
rkazaniszynrobwittman
authored andcommitted
Add missing InventoryLevel service (#16)
1 parent edb201f commit 1d0bb73

File tree

6 files changed

+98
-1
lines changed

6 files changed

+98
-1
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"inventory_levels": [
3+
{
4+
"inventory_item_id": 2084329160713,
5+
"location_id": 106790921,
6+
"available": 1,
7+
"updated_at": "2018-02-20T03:37:40-05:00"
8+
},
9+
{
10+
"inventory_item_id": 2197022867465,
11+
"location_id": 106790921,
12+
"available": 0,
13+
"updated_at": "2018-03-29T05:08:20-04:00"
14+
}
15+
]
16+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Shopify\Enum\Fields;
4+
5+
class InventoryLevelFields extends AbstractObjectEnum
6+
{
7+
const INVENTORY_ITEM_ID = 'inventory_item_id';
8+
const LOCATION_ID = 'location_id';
9+
const AVAILABLE = 'available';
10+
const UPDATED_AT = 'updated_at';
11+
12+
public function getFieldTypes()
13+
{
14+
return array(
15+
'inventory_item_id' => 'integer',
16+
'location_id' => 'integer',
17+
'available' => 'integer',
18+
'updated_at' => 'DateTime',
19+
);
20+
}
21+
}

lib/Enum/Fields/ProductVariantFields.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ProductVariantFields extends AbstractObjectEnum
3030
const UPDATED_AT = 'updated_at';
3131
const WEIGHT = 'weight';
3232
const WEIGHT_UNIT = 'weight_unit';
33+
const INVENTORY_ITEM_ID = 'inventory_item_id';
3334

3435
public function getFieldTypes()
3536
{
@@ -59,7 +60,8 @@ public function getFieldTypes()
5960
'title' => 'string',
6061
'updated_at' => 'DateTime',
6162
'weight' => 'string',
62-
'weight_unit' => 'string'
63+
'weight_unit' => 'string',
64+
'inventory_item_id' => 'integer',
6365
);
6466
}
6567
}

lib/Object/InventoryLevel.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Shopify\Object;
4+
5+
use Shopify\Enum\Fields\InventoryLevelFields;
6+
7+
class InventoryLevel extends AbstractObject
8+
{
9+
public static function getFieldsEnum()
10+
{
11+
return InventoryLevelFields::getInstance();
12+
}
13+
}

lib/Service/InventoryLevelService.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Shopify\Service;
4+
5+
use Shopify\Object\InventoryLevel;
6+
7+
class InventoryLevelService extends AbstractService
8+
{
9+
/**
10+
* Retrieves a list of inventory levels.
11+
* You must include inventory_item_ids and/or location_ids as filter params.
12+
*
13+
* @link https://help.shopify.com/api/reference/inventorylevel#index
14+
* @param array $params
15+
* @return InventoryLevel[]
16+
*/
17+
public function all(array $params)
18+
{
19+
$endpoint = '/admin/inventory_levels.json';
20+
$response = $this->request($endpoint, 'GET', $params);
21+
22+
return $this->createCollection(InventoryLevel::class, $response['inventory_levels']);
23+
}
24+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Shopify\Test\Service;
4+
5+
use Shopify\Object\InventoryLevel;
6+
use Shopify\Service\InventoryLevelService;
7+
use Shopify\Test\TestCase;
8+
9+
class InventoryLevelServiceTest extends TestCase
10+
{
11+
public function testList()
12+
{
13+
$api = $this->getApiMock('lists/InventoryLevelsList.json');
14+
$service = new InventoryLevelService($api);
15+
$inventoryLevels = $service->all(array('inventory_item_ids' => '2084329160713,2197022867465'));
16+
$this->assertContainsOnlyInstancesOf(
17+
InventoryLevel::class,
18+
$inventoryLevels
19+
);
20+
}
21+
}

0 commit comments

Comments
 (0)