From 6c02c303706049480119d5110d774c420be4e71e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 8 Apr 2020 02:32:16 +0000 Subject: [PATCH] Update function name. Add checking for empty response in getBranchesInventory. #374 --- src/Controller/JobOrderController.php | 4 +--- src/Service/InventoryManager.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 26c9cb88..bee059bc 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -1150,15 +1150,13 @@ class JobOrderController extends Controller // api call to check inventory // pass the list of branch codes of nearest hubs and the skus // go through returned list of branch codes - $hubs_with_inventory = $im->getBranchInventory($nearest_branch_codes, $skus); - // TODO: check for empty result for now. + $hubs_with_inventory = $im->getBranchesInventory($nearest_branch_codes, $skus); if (!empty($hubs_with_inventory)) { $nearest = []; $flag_hub_found = false; foreach ($hubs_with_inventory as $hub_with_inventory) { - error_log($hub_with_inventory['BranchCode']); // find hub according to branch code $found_hub = $em->getRepository(Hub::class)->findOneBy(['branch_code' => $hub_with_inventory['BranchCode']]); if ($found_hub != null) diff --git a/src/Service/InventoryManager.php b/src/Service/InventoryManager.php index 7a3250c5..4dc5a8b1 100644 --- a/src/Service/InventoryManager.php +++ b/src/Service/InventoryManager.php @@ -17,7 +17,7 @@ class InventoryManager $this->api_auth_token = $api_auth_token; } - public function getBranchInventory($nearest_branch_codes, $skus) + public function getBranchesInventory($nearest_branch_codes, $skus) { // api call to check inventory // pass the list of branch codes and the skus @@ -60,12 +60,19 @@ class InventoryManager // response is array of these // { - // "BranchCode": "TestBranch1", - // "BranchName": "Test Branch", + // "Id": 37, + // "BranchCode": "WestAve", + // "BranchName": "West ave. Branch", + // "BranchRole": 0, + // "Name": "3SMF / GOLD ", // "SapCode": "WMGD31EL-CPNM0-L", - // "Quantity": 4 - // }, - $results = json_decode($response, true); + // "Quantity": 38 + // } + + // check if the response is empty + $results = []; + if (!empty($response)) + $results = json_decode($response, true); return $results; }