Add checking for location and price tier when getting list of compatible batteries. #780
This commit is contained in:
parent
ba09e6ac7b
commit
4d89e7420f
3 changed files with 79 additions and 8 deletions
|
|
@ -51,7 +51,7 @@ tapi_vehicle_make_list:
|
|||
tapi_battery_list:
|
||||
path: /tapi/vehicles/{vid}/compatible_batteries
|
||||
controller: App\Controller\TAPI\BatteryController::getCompatibleBatteries
|
||||
methods: [GET]
|
||||
methods: [POST]
|
||||
|
||||
# promos
|
||||
tapi_promo_list:
|
||||
|
|
|
|||
|
|
@ -4,16 +4,19 @@ namespace App\Controller\CustomerAppAPI;
|
|||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\ItemType;
|
||||
use App\Ramcar\JOStatus;
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\TradeInType;
|
||||
use App\Ramcar\InsuranceApplicationStatus;
|
||||
use App\Service\PayMongoConnector;
|
||||
use App\Service\PriceTierManager;
|
||||
use DateTime;
|
||||
|
||||
class VehicleController extends ApiController
|
||||
|
|
@ -237,7 +240,7 @@ class VehicleController extends ApiController
|
|||
]);
|
||||
}
|
||||
|
||||
public function getCompatibleBatteries(Request $req, $vid)
|
||||
public function getCompatibleBatteries(Request $req, $vid, PriceTierManager $pt_manager)
|
||||
{
|
||||
// validate params
|
||||
$validity = $this->validateRequest($req);
|
||||
|
|
@ -252,11 +255,43 @@ class VehicleController extends ApiController
|
|||
return new ApiResponse(false, 'Invalid vehicle.');
|
||||
}
|
||||
|
||||
// get location from request
|
||||
$lng = $req->query->get('longitude', '');
|
||||
$lat = $req->query->get('latitude', '');
|
||||
|
||||
$batts = $vehicle->getActiveBatteries();
|
||||
$pt_id = 0;
|
||||
if ((!(empty($lng))) && (!(empty($lat))))
|
||||
{
|
||||
// get the price tier
|
||||
$coordinates = new Point($lng, $lat);
|
||||
|
||||
$pt_id = $pt_manager->getPriceTier($coordinates);
|
||||
}
|
||||
|
||||
// batteries
|
||||
$batt_list = [];
|
||||
$batts = $vehicle->getActiveBatteries();
|
||||
foreach ($batts as $batt) {
|
||||
// TODO: Add warranty_tnv to battery information
|
||||
// check if customer location is in a price tier location
|
||||
if ($pt_id == 0)
|
||||
$price = $batt->getSellingPrice();
|
||||
else
|
||||
{
|
||||
// get item type for battery
|
||||
$item_type = $this->em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
|
||||
if ($item_type == null)
|
||||
$price = $batt->getSellingPrice();
|
||||
else
|
||||
{
|
||||
$item_type_id = $item_type->getID();
|
||||
$batt_id = $batt->getID();
|
||||
|
||||
// find the item price given price tier id and battery id
|
||||
$price = $pt_manager->getItemPrice($pt_id, $item_type_id, $batt_id);
|
||||
}
|
||||
}
|
||||
|
||||
$batt_list[] = [
|
||||
'id' => $batt->getID(),
|
||||
'mfg_id' => $batt->getManufacturer()->getID(),
|
||||
|
|
@ -265,7 +300,7 @@ class VehicleController extends ApiController
|
|||
'model_name' => $batt->getModel()->getName(),
|
||||
'size_id' => $batt->getSize()->getID(),
|
||||
'size_name' => $batt->getSize()->getName(),
|
||||
'price' => $batt->getSellingPrice(),
|
||||
'price' => $price,
|
||||
'wty_private' => $batt->getWarrantyPrivate(),
|
||||
'wty_commercial' => $batt->getWarrantyCommercial(),
|
||||
'image_url' => $this->getBatteryImageURL($req, $batt),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ use Catalyst\ApiBundle\Component\Response as APIResponse;
|
|||
use App\Ramcar\APIResult;
|
||||
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
|
||||
use Catalyst\AuthBundle\Service\ACLGenerator as ACLGenerator;
|
||||
|
||||
|
|
@ -25,7 +30,7 @@ class BatteryController extends ApiController
|
|||
$this->acl_gen = $acl_gen;
|
||||
}
|
||||
|
||||
public function getCompatibleBatteries(Request $req, $vid, EntityManagerInterface $em)
|
||||
public function getCompatibleBatteries(Request $req, $vid, EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('tapi_battery_compatible.list', null, 'No access.');
|
||||
|
||||
|
|
@ -43,13 +48,44 @@ class BatteryController extends ApiController
|
|||
return new APIResponse(false, $message);
|
||||
}
|
||||
|
||||
// get location from request
|
||||
$lng = $req->request->get('longitude', '');
|
||||
$lat = $req->request->get('latitude', '');
|
||||
|
||||
$batts = $vehicle->getActiveBatteries();
|
||||
$pt_id = 0;
|
||||
if ((!(empty($lng))) && (!(empty($lat))))
|
||||
{
|
||||
// get the price tier
|
||||
$coordinates = new Point($lng, $lat);
|
||||
|
||||
$pt_id = $pt_manager->getPriceTier($coordinates);
|
||||
}
|
||||
|
||||
// batteries
|
||||
$batt_list = [];
|
||||
// $batts = $vehicle->getBatteries();
|
||||
$batts = $vehicle->getActiveBatteries();
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
// TODO: Add warranty_tnv to battery information
|
||||
// check if customer location is in a price tier location
|
||||
if ($pt_id == 0)
|
||||
$price = $batt->getSellingPrice();
|
||||
else
|
||||
{
|
||||
// get item type for battery
|
||||
$item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
|
||||
if ($item_type == null)
|
||||
$price = $batt->getSellingPrice();
|
||||
else
|
||||
{
|
||||
$item_type_id = $item_type->getID();
|
||||
$batt_id = $batt->getID();
|
||||
|
||||
// find the item price given price tier id and battery id
|
||||
$price = $pt_manager->getItemPrice($pt_id, $item_type_id, $batt_id);
|
||||
}
|
||||
}
|
||||
|
||||
$batt_list[] = [
|
||||
'id' => $batt->getID(),
|
||||
'mfg_id' => $batt->getManufacturer()->getID(),
|
||||
|
|
@ -58,7 +94,7 @@ class BatteryController extends ApiController
|
|||
'model_name' => $batt->getModel()->getName(),
|
||||
'size_id' => $batt->getSize()->getID(),
|
||||
'size_name' => $batt->getSize()->getName(),
|
||||
'price' => $batt->getSellingPrice(),
|
||||
'price' => $price,
|
||||
'wty_private' => $batt->getWarrantyPrivate(),
|
||||
'wty_commercial' => $batt->getWarrantyCommercial(),
|
||||
'image_url' => $this->getBatteryImageURL($req, $batt),
|
||||
|
|
|
|||
Loading…
Reference in a new issue