diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 697e379c..b8736440 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -549,6 +549,15 @@ class APIController extends Controller return $res->getReturnResponse(); } + protected function getBatteryImageURL($req, $batt) + { + // TODO: workaround for now, we get static image of battery based on model name + $filename = trim(strtolower($batt->getModel()->getName())) . '_mobile.jpg'; + $file_path = $req->getSchemeAndHttpHost() . $this->generateUrl('static_battery_image') . '/' . $filename; + + return $file_path; + } + public function listVehicles(Request $req) { // check required parameters and api key @@ -642,9 +651,6 @@ class APIController extends Controller $batts = $vehicle->getBatteries(); foreach ($batts as $batt) { - // TODO: workaround for now, we get static image of battery based on model name - $filename = trim(strtolower($batt->getModel()->getName())) . '_mobile.jpg'; - $file_path = $req->getSchemeAndHttpHost() . $this->generateUrl('static_battery_image') . '/' . $filename; $batt_list[] = [ 'id' => $batt->getID(), 'mfg_id' => $batt->getManufacturer()->getID(), @@ -656,7 +662,7 @@ class APIController extends Controller 'price' => $batt->getSellingPrice(), 'wty_private' => $batt->getWarrantyPrivate(), 'wty_commercial' => $batt->getWarrantyCommercial(), - 'image_url' => $file_path, + 'image_url' => $this->getBatteryImageURL($req, $batt), ]; } @@ -953,11 +959,19 @@ class APIController extends Controller $items_data = []; foreach ($items as $item) { - $items_data[] = [ + $my_data = [ 'title' => $item->getTitle(), 'qty' => $item->getQuantity() + 0, 'price' => $item->getPrice() + 0.0, ]; + + $item_batt = $item->getBattery(); + if ($item_batt != null) + { + $my_data['image_url'] = $this->getBatteryImageURL($req, $batt); + } + + $items_data[] = $my_data; } $data['items'] = $items_data;