Add image_url to get estimate api call #107

This commit is contained in:
Kendrick Chan 2018-05-01 21:01:38 +08:00
parent 2f68a184e7
commit ae153c60b0

View file

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