Skip to content

Commit

Permalink
Add missing InventoryLevel service (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkazaniszyn authored and robwittman committed Mar 23, 2019
1 parent edb201f commit 1d0bb73
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 1 deletion.
16 changes: 16 additions & 0 deletions data/mocks/lists/InventoryLevelsList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"inventory_levels": [
{
"inventory_item_id": 2084329160713,
"location_id": 106790921,
"available": 1,
"updated_at": "2018-02-20T03:37:40-05:00"
},
{
"inventory_item_id": 2197022867465,
"location_id": 106790921,
"available": 0,
"updated_at": "2018-03-29T05:08:20-04:00"
}
]
}
21 changes: 21 additions & 0 deletions lib/Enum/Fields/InventoryLevelFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Shopify\Enum\Fields;

class InventoryLevelFields extends AbstractObjectEnum
{
const INVENTORY_ITEM_ID = 'inventory_item_id';
const LOCATION_ID = 'location_id';
const AVAILABLE = 'available';
const UPDATED_AT = 'updated_at';

public function getFieldTypes()
{
return array(
'inventory_item_id' => 'integer',
'location_id' => 'integer',
'available' => 'integer',
'updated_at' => 'DateTime',
);
}
}
4 changes: 3 additions & 1 deletion lib/Enum/Fields/ProductVariantFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ProductVariantFields extends AbstractObjectEnum
const UPDATED_AT = 'updated_at';
const WEIGHT = 'weight';
const WEIGHT_UNIT = 'weight_unit';
const INVENTORY_ITEM_ID = 'inventory_item_id';

public function getFieldTypes()
{
Expand Down Expand Up @@ -59,7 +60,8 @@ public function getFieldTypes()
'title' => 'string',
'updated_at' => 'DateTime',
'weight' => 'string',
'weight_unit' => 'string'
'weight_unit' => 'string',
'inventory_item_id' => 'integer',
);
}
}
13 changes: 13 additions & 0 deletions lib/Object/InventoryLevel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Shopify\Object;

use Shopify\Enum\Fields\InventoryLevelFields;

class InventoryLevel extends AbstractObject
{
public static function getFieldsEnum()
{
return InventoryLevelFields::getInstance();
}
}
24 changes: 24 additions & 0 deletions lib/Service/InventoryLevelService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Shopify\Service;

use Shopify\Object\InventoryLevel;

class InventoryLevelService extends AbstractService
{
/**
* Retrieves a list of inventory levels.
* You must include inventory_item_ids and/or location_ids as filter params.
*
* @link https://help.shopify.com/api/reference/inventorylevel#index
* @param array $params
* @return InventoryLevel[]
*/
public function all(array $params)
{
$endpoint = '/admin/inventory_levels.json';
$response = $this->request($endpoint, 'GET', $params);

return $this->createCollection(InventoryLevel::class, $response['inventory_levels']);
}
}
21 changes: 21 additions & 0 deletions test/Service/InventoryLevelServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Shopify\Test\Service;

use Shopify\Object\InventoryLevel;
use Shopify\Service\InventoryLevelService;
use Shopify\Test\TestCase;

class InventoryLevelServiceTest extends TestCase
{
public function testList()
{
$api = $this->getApiMock('lists/InventoryLevelsList.json');
$service = new InventoryLevelService($api);
$inventoryLevels = $service->all(array('inventory_item_ids' => '2084329160713,2197022867465'));
$this->assertContainsOnlyInstancesOf(
InventoryLevel::class,
$inventoryLevels
);
}
}

0 comments on commit 1d0bb73

Please sign in to comment.