Add checking for customer pre-registered hub. #609

This commit is contained in:
Korina Cordero 2021-08-02 09:03:46 +00:00
parent 6f5c88dbdb
commit b56754363e

View file

@ -2555,7 +2555,33 @@ class APIController extends Controller implements LoggedController
return $res->getReturnResponse();
$coordinates = new Point($req->query->get('longitude'), $req->query->get('latitude'));
$nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools);
// add checking if customer has a pre-registered hub
$cust = $this->session->getCustomer();
if ($cust == null)
{
$res->setError(true)
->setErrorMessage('No customer information found');
return $res->getReturnResponse();
}
// check if customer has customer tag promo
if (($cust->getCustomerTag('TAG_CAR_CLUB_OFFICER_PROMO')) ||
($cust->getCustomerTag('TAG_CAR_CLUB_MEMBER_PROMO')))
{
// if has customer tag, customer has not availed of promo, get the hub where customer is pre-registered
$car_club_cust_hub = $cust->getCarClubCustomerHub();
if ($car_club_cust_hub != null)
{
// need to get the rider slots for the pre-registered hub
$hub = $car_club_cust_hub->getHub();
$nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools, $hub);
}
}
else
{
$nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools);
}
if (empty($nearest_hub_slots['hub']))
{
@ -3111,6 +3137,26 @@ class APIController extends Controller implements LoggedController
if (($hour < 8) || ($hour > 16))
$schedule_choice = false;
// add checking if customer has a pre-registered hub
$cust = $this->session->getCustomer();
if ($cust == null)
{
$res->setError(true)
->setErrorMessage('No customer information found');
return $res->getReturnResponse();
}
// check if customer has customer tag promo
if (($cust->getCustomerTag('TAG_CAR_CLUB_OFFICER_PROMO')) ||
($cust->getCustomerTag('TAG_CAR_CLUB_MEMBER_PROMO')))
{
// if has customer tag, customer has not availed of promo, get the hub where customer is pre-registered
$car_club_hub = $cust->getCarClubCustomerHub();
if ($car_club_hub != null)
{
$schedule_choice = false;
}
}
$data = [
'display_schedule_choice' => $schedule_choice,
];
@ -3764,10 +3810,23 @@ class APIController extends Controller implements LoggedController
return $selected_rider;
}
protected function findAdvanceNearestHubAndSlots(Point $coordinates, EntityManagerInterface $em, MapTools $map_tools)
protected function findAdvanceNearestHubAndSlots(Point $coordinates, EntityManagerInterface $em, MapTools $map_tools, $hub=null)
{
// get the nearest 10 hubs
$hub_data = [];
if ($hub != null)
{
// get the slots of hub
$hub_slots = $this->getHubRiderSlots($hub, $em);
$hub_data = [
'hub' => $hub,
'slots' => $hub_slots,
];
return $hub_data;
}
// get the nearest 10 hubs
$nearest_hubs_with_distance = [];
$hubs = $map_tools->getClosestOpenHubs($coordinates, 10);