From 8b749566a43c8b5982751ef703679dbcbbc4afdd Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 19 Apr 2024 15:15:12 +0530 Subject: [PATCH 1/2] Fixed: Service product associated room types are shown according to hotel permission --- .../admin/AdminNormalProductsController.php | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index 87a959951..b0c0715b8 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -186,19 +186,17 @@ class AdminNormalProductsControllerCore extends AdminController $id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP? (int)$this->context->shop->id : 'a.id_shop_default'; $this->_join .= ' JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = '.$id_shop.') - LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (a.`id_product` = hrt.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hb ON (hrt.`id_hotel` = hb.`id`) - LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (hb.`id` = hbl.`id` AND b.`id_lang` = hbl.`id_lang`) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.$id_shop.') LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.$id_shop.') LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`) LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1) LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` rsp ON (rsp.`id_product` = a.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = hb.`id`)'; + LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (rsp.`id_element` = hrt.`id_product` AND rsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.') + '.HotelBranchInformation::addHotelRestriction(false, 'hrt'); $this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, IF(a.`price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_PER_DAY.', "'.$this->l('Per Day').'", "'.$this->l('Per Booking').'") as price_calculation_method_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; - $this->_select .= ' COUNT(rsp.`id_product`) as products_associated, hrt.`adults`, hrt.`children`, hb.`id` as id_hotel, aa.`city`, hbl.`hotel_name`, '; + $this->_select .= ' COUNT(hrt.`id_product`) as products_associated, '; $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`'; @@ -368,15 +366,6 @@ class AdminNormalProductsControllerCore extends AdminController return '--'; } - public function getHotelName($hotelName, $row) - { - if ($hotelName && isset($row['city'])) { - return $hotelName.' - '.$row['city']; - } - - return '--'; - } - public static function getQuantities($hotelName, $tr) { if ((int)$tr['is_virtual'] == 1 && $tr['nb_downloadable'] == 0) { @@ -3531,15 +3520,6 @@ class AdminNormalProductsControllerCore extends AdminController )); $data->assign($this->tpl_form_vars); - $objRoomType = new HotelRoomType(); - $objHotelInfo = new HotelBranchInformation(); - $data->assign('htl_info', $objHotelInfo->hotelsNameAndId()); - if ($hotelRoomType = $objRoomType->getRoomTypeInfoByIdProduct($product->id)) { - $data->assign('htl_room_type', $hotelRoomType); - $hotelFullInfo = $objHotelInfo->hotelBranchInfoById($hotelRoomType['id_hotel']); - $data->assign('htl_full_info', $hotelFullInfo); - } - $this->tpl_form_vars['product'] = $product; $this->tpl_form_vars['custom_form'] = $data->fetch(); } @@ -4113,19 +4093,6 @@ class AdminNormalProductsControllerCore extends AdminController } } - public function ajaxProcessGetIdHotelByIdProduct() - { - $response = array('status' => 'failed'); - $idProduct = Tools::getValue('id_product'); - $objHotelRoomType = new HotelRoomType(); - $roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($idProduct); - if ($roomTypeInfo) { - $response['status'] = 'success'; - $response['id_hotel'] = (int)$roomTypeInfo['id_hotel']; - } - die(json_encode($response)); - } - public function processImageLegends() { if (Tools::getValue('key_tab') == 'Images' && Tools::getValue('submitAddproductAndStay') == 'update_legends' && Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))) { From bd7bcfd5dc5d0569b35a0c9eb3e3d79faf43eb31 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Tue, 21 May 2024 19:52:08 +0530 Subject: [PATCH 2/2] revert remove unused function --- .../admin/AdminNormalProductsController.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index b0c0715b8..f4d682e73 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -366,6 +366,15 @@ class AdminNormalProductsControllerCore extends AdminController return '--'; } + public function getHotelName($hotelName, $row) + { + if ($hotelName && isset($row['city'])) { + return $hotelName.' - '.$row['city']; + } + + return '--'; + } + public static function getQuantities($hotelName, $tr) { if ((int)$tr['is_virtual'] == 1 && $tr['nb_downloadable'] == 0) { @@ -3520,6 +3529,15 @@ class AdminNormalProductsControllerCore extends AdminController )); $data->assign($this->tpl_form_vars); + $objRoomType = new HotelRoomType(); + $objHotelInfo = new HotelBranchInformation(); + $data->assign('htl_info', $objHotelInfo->hotelsNameAndId()); + if ($hotelRoomType = $objRoomType->getRoomTypeInfoByIdProduct($product->id)) { + $data->assign('htl_room_type', $hotelRoomType); + $hotelFullInfo = $objHotelInfo->hotelBranchInfoById($hotelRoomType['id_hotel']); + $data->assign('htl_full_info', $hotelFullInfo); + } + $this->tpl_form_vars['product'] = $product; $this->tpl_form_vars['custom_form'] = $data->fetch(); } @@ -4093,6 +4111,19 @@ class AdminNormalProductsControllerCore extends AdminController } } + public function ajaxProcessGetIdHotelByIdProduct() + { + $response = array('status' => 'failed'); + $idProduct = Tools::getValue('id_product'); + $objHotelRoomType = new HotelRoomType(); + $roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($idProduct); + if ($roomTypeInfo) { + $response['status'] = 'success'; + $response['id_hotel'] = (int)$roomTypeInfo['id_hotel']; + } + die(json_encode($response)); + } + public function processImageLegends() { if (Tools::getValue('key_tab') == 'Images' && Tools::getValue('submitAddproductAndStay') == 'update_legends' && Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))) {