From 917459f228ce80ec8e49eb5bc90b357784751ddd Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 8 Apr 2020 09:31:28 +0000 Subject: [PATCH] Comment out call to inventory manager. #374 --- src/Controller/APIController.php | 36 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 194c14be..d0099e73 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2265,15 +2265,36 @@ class APIController extends Controller foreach ($hubs as $hub) { $nearest_hubs_with_distance[] = $hub; - if (!empty($hub['hub']->getBranchCode())) - $nearest_branch_codes[] = $hub['hub']->getBranchCode(); + //if (!empty($hub['hub']->getBranchCode())) + // $nearest_branch_codes[] = $hub['hub']->getBranchCode(); } // check if nearest hubs have branch codes - if (count($nearest_branch_codes) == 0) - return $selected_hub; + //if (count($nearest_branch_codes) == 0) + // return $selected_hub; + // assume all 10 have stock + // find the nearest hub with available riders + $nearest = null; + foreach ($nearest_hubs_with_distance as $nhd) + { + if (count($nhd['hub']->getAvailableRiders()) > 0) + { + if (empty($nearest)) + $nearest = $nhd; + else + { + if ($nhd['distance'] < $nearest['distance']) + $nearest = $nhd; + } + } + } + + $selected_hub = $nearest['hub']; + + // uncomment this snippet when inventory check becomes active // get battery sku + /* if ($batt != null) { $skus[] = $batt->getSAPCode(); @@ -2281,7 +2302,8 @@ class APIController 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->getBranchesInventory($nearest_branch_codes, $skus); + // bypass inventory check for now + // $hubs_with_inventory = $im->getBranchesInventory($nearest_branch_codes, $skus); if (!empty($hubs_with_inventory)) { $nearest = []; @@ -2320,8 +2342,8 @@ class APIController extends Controller } } $selected_hub = $nearest['hub']; - } - } + } + } */ return $selected_hub; }