From 1d0bb7326c6e0bced5adbc440c41c7a14f315a2c Mon Sep 17 00:00:00 2001 From: Radoslaw Date: Sun, 24 Mar 2019 00:36:19 +0100 Subject: [PATCH] Add missing InventoryLevel service (#16) --- data/mocks/lists/InventoryLevelsList.json | 16 +++++++++++++++ lib/Enum/Fields/InventoryLevelFields.php | 21 +++++++++++++++++++ lib/Enum/Fields/ProductVariantFields.php | 4 +++- lib/Object/InventoryLevel.php | 13 ++++++++++++ lib/Service/InventoryLevelService.php | 24 ++++++++++++++++++++++ test/Service/InventoryLevelServiceTest.php | 21 +++++++++++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 data/mocks/lists/InventoryLevelsList.json create mode 100644 lib/Enum/Fields/InventoryLevelFields.php create mode 100644 lib/Object/InventoryLevel.php create mode 100644 lib/Service/InventoryLevelService.php create mode 100644 test/Service/InventoryLevelServiceTest.php diff --git a/data/mocks/lists/InventoryLevelsList.json b/data/mocks/lists/InventoryLevelsList.json new file mode 100644 index 0000000..f6d39eb --- /dev/null +++ b/data/mocks/lists/InventoryLevelsList.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/lib/Enum/Fields/InventoryLevelFields.php b/lib/Enum/Fields/InventoryLevelFields.php new file mode 100644 index 0000000..cb7fbd8 --- /dev/null +++ b/lib/Enum/Fields/InventoryLevelFields.php @@ -0,0 +1,21 @@ + 'integer', + 'location_id' => 'integer', + 'available' => 'integer', + 'updated_at' => 'DateTime', + ); + } +} diff --git a/lib/Enum/Fields/ProductVariantFields.php b/lib/Enum/Fields/ProductVariantFields.php index 693c28b..b6770b8 100644 --- a/lib/Enum/Fields/ProductVariantFields.php +++ b/lib/Enum/Fields/ProductVariantFields.php @@ -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() { @@ -59,7 +60,8 @@ public function getFieldTypes() 'title' => 'string', 'updated_at' => 'DateTime', 'weight' => 'string', - 'weight_unit' => 'string' + 'weight_unit' => 'string', + 'inventory_item_id' => 'integer', ); } } diff --git a/lib/Object/InventoryLevel.php b/lib/Object/InventoryLevel.php new file mode 100644 index 0000000..01e6b5b --- /dev/null +++ b/lib/Object/InventoryLevel.php @@ -0,0 +1,13 @@ +request($endpoint, 'GET', $params); + + return $this->createCollection(InventoryLevel::class, $response['inventory_levels']); + } +} diff --git a/test/Service/InventoryLevelServiceTest.php b/test/Service/InventoryLevelServiceTest.php new file mode 100644 index 0000000..336a74e --- /dev/null +++ b/test/Service/InventoryLevelServiceTest.php @@ -0,0 +1,21 @@ +getApiMock('lists/InventoryLevelsList.json'); + $service = new InventoryLevelService($api); + $inventoryLevels = $service->all(array('inventory_item_ids' => '2084329160713,2197022867465')); + $this->assertContainsOnlyInstancesOf( + InventoryLevel::class, + $inventoryLevels + ); + } +}