Add all other batteries to compatible battery dropdown #67
This commit is contained in:
parent
190ab8ceaf
commit
b009199df3
1 changed files with 26 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Controller;
|
|||
use App\Ramcar\BaseController;
|
||||
use App\Entity\BatteryManufacturer;
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\Battery;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
@ -278,12 +279,14 @@ class BatteryManufacturerController extends BaseController
|
|||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = $em->getRepository(BatteryManufacturer::class)->find($req->request->get('id'));
|
||||
$vobj = $em->getRepository(Vehicle::class)->find($req->request->get('vehicle_id'));
|
||||
$all_batts = $em->getRepository(Battery::class)->findAll();
|
||||
|
||||
if (empty($obj) || empty($vobj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// build batteries array
|
||||
$batteries = [];
|
||||
$battery_index = [];
|
||||
|
||||
// get compatible batteries from selected manufacturer
|
||||
foreach ($vobj->getBatteries() as $battery)
|
||||
|
|
@ -300,13 +303,36 @@ class BatteryManufacturerController extends BaseController
|
|||
'warr_private' => $battery->getWarrantyPrivate(),
|
||||
'warr_commercial' => $battery->getWarrantyCommercial(),
|
||||
];
|
||||
$battery_index[$battery->getID()] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// add all other batteries, because they want options
|
||||
foreach ($all_batts as $battery)
|
||||
{
|
||||
// if we already listed it
|
||||
if (isset($battery_index[$battery->getID()]))
|
||||
continue;
|
||||
|
||||
$batteries[] = [
|
||||
'id' => $battery->getID(),
|
||||
'mfg_name' => $battery->getManufacturer()->getName(),
|
||||
'model_name' => $battery->getModel()->getName(),
|
||||
'size_name' => $battery->getSize()->getName(),
|
||||
'prod_code' => $battery->getProductCode(),
|
||||
'sell_price' => $battery->getSellingPrice(),
|
||||
'warr_private' => $battery->getWarrantyPrivate(),
|
||||
'warr_commercial' => $battery->getWarrantyCommercial(),
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
// NOTE: no need to order by price for control center / only for app
|
||||
// order by price
|
||||
usort($batteries, function ($a, $b) {
|
||||
return -($a['sell_price'] <=> $b['sell_price']);
|
||||
});
|
||||
*/
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
|
|
|
|||
Loading…
Reference in a new issue