Update function name. Add checking for empty response in getBranchesInventory. #374

This commit is contained in:
Korina Cordero 2020-04-08 02:32:16 +00:00
parent eb5710b846
commit 6c02c30370
2 changed files with 14 additions and 9 deletions

View file

@ -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)

View file

@ -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;
}