Skip to content

Commit

Permalink
Merge pull request #777 from abhishek-webkul/gli-1362
Browse files Browse the repository at this point in the history
Fixed: Employee can search for inaccessible Service Products using search box at back office
  • Loading branch information
rohit053 authored Jan 8, 2024
2 parents 06942dd + 6052d4c commit 2f66994
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions controllers/admin/AdminSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,36 @@ public function searchCatalog()
$this->context = Context::getContext();
if ($this->_list['products'] = Product::searchByName($this->context->language->id, $this->query)) {
$objRoomType = new HotelRoomType();
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$accessibleHotels = HotelBranchInformation::getProfileAccessedHotels(
$this->context->employee->id_profile,
1,
1
);

foreach ($this->_list['products'] as $key => $product) {
$roomInfo = $objRoomType->getRoomTypeInfoByIdProduct($product['id_product']);
if (!in_array($roomInfo['id_hotel'], HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1))) {
$toUnset = false;
if ($product['booking_product']) {
$roomInfo = $objRoomType->getRoomTypeInfoByIdProduct($product['id_product']);
if (!in_array($roomInfo['id_hotel'], $accessibleHotels)) {
$toUnset = true;
}
} else {
$associations = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product['id_product']);
// proceed only if access can not be determined from hotels
if (!count(array_intersect($associations['hotels'], $accessibleHotels))) {
$toUnset = true;
foreach ($associations['room_types'] as $idProduct) {
$roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct);
if (in_array($roomTypeInfo['id_hotel'], $accessibleHotels)) {
$toUnset = false;
break;
}
}
}
}

if ($toUnset) {
unset($this->_list['products'][$key]);
}
}
Expand Down

0 comments on commit 2f66994

Please sign in to comment.