-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing InventoryLevel service (#16)
- Loading branch information
1 parent
edb201f
commit 1d0bb73
Showing
6 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |