diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 7ebc30b70..821c5e208 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2023,12 +2023,13 @@ class AdminProductsControllerCore extends AdminController if (($error = $this->object->validateFieldsLang(false, true)) !== true) { $this->errors[] = $error; } - if(!count($this->errors)){ + + if (!count($this->errors)) { $objHotelRoomType = new HotelRoomType(); - if($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->object->id)){ + if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->object->id)) { $objHotelBranchInformation = new HotelBranchInformation((int)$roomTypeInfo['id_hotel']); - if(!$objHotelBranchInformation->active){ - $this->errors[] = $this->l('Please enable the hotel "'.$roomTypeInfo['hotel_name'].'" first in order to update the status.'); + if (!$objHotelBranchInformation->active) { + $this->errors[] = $this->l('Room type can not be active as long as hotel is disabled.'); } } } @@ -2055,14 +2056,15 @@ class AdminProductsControllerCore extends AdminController if (is_array($this->boxes) && !empty($this->boxes)) { foreach ($this->boxes as $id) { $objHotelRoomType = new HotelRoomType(); - if($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($id)){ + if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($id)) { $objHotelBranchInformation = new HotelBranchInformation((int)$roomTypeInfo['id_hotel']); - if(!$objHotelBranchInformation->active){ - $this->errors[] = $this->l('Please enable the hotel "'.$roomTypeInfo['hotel_name'].'" first in order to update the status.'); + if (!$objHotelBranchInformation->active) { + $this->errors[] = $this->l('Room type can not be active as long as hotel is disabled.'); } } } } + if (!count($this->errors)) { parent::processBulkStatusSelection($status); } @@ -2393,6 +2395,10 @@ class AdminProductsControllerCore extends AdminController } else if (!Validate::isLoadedObject($objHotel = new HotelBranchInformation($id_hotel))) { $this->errors[] = Tools::displayError('Selected Hotel not found'); } else { + // Prevent enabling a room type when its hotel is disabled + if ((int)Tools::getValue('active') === 1 && isset($objHotel) && !$objHotel->active) { + $this->errors[] = Tools::displayError('Room type can not be active as long as hotel is disabled.'); + } $hotelIdCategory = $objHotel->id_category; if (Validate::isLoadedObject($objCategory = new Category($hotelIdCategory))) { foreach($objCategory->getParentsCategories() as $category) { diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index baa85790c..5246337d7 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -441,40 +441,6 @@ class HotelReservationSystem extends Module } } - public function hookActionProductSave($params) - { - $obj_htl_rm_info = new HotelRoomType(); - if ($htl_rm_info = $obj_htl_rm_info->getRoomTypeInfoByIdProduct($params['id_product'])) { - $isToggling = Tools::getValue('statusproduct'); - if (isset($isToggling) && $isToggling) { - $prod_htl_id = $htl_rm_info['id_hotel']; - if (isset($prod_htl_id) && $prod_htl_id) { - $obj_hotel = new HotelBranchInformation($prod_htl_id); - if (!$obj_hotel->active) { - $obj_hotel->toggleStatus(); - } - } - } else { - if (!$params['product']->quantity) { - StockAvailable::setQuantity($params['id_product'], 0, 999999999); - } - if ($params['id_product']) { - $prod_htl_id = $htl_rm_info['id_hotel']; - if (isset($prod_htl_id) && $prod_htl_id) { - $obj_hotel = new HotelBranchInformation($prod_htl_id); - if (!$obj_hotel->active) { - $obj_product = new Product($params['id_product']); - if ($obj_product->active == 1) { - $this->context->controller->errors[] = $this->l('Room type can not be active as long as hotel is disabled.'); - $obj_product->toggleStatus(); - } - } - } - } - } - } - } - public function hookActionOrderStatusPostUpdate($params) { $objHtlBkDtl = new HotelBookingDetail(); @@ -637,7 +603,6 @@ class HotelReservationSystem extends Module 'actionObjectProductDeleteBefore', 'displayFooter', 'displayAfterDefautlFooterHook', - 'actionProductSave', 'addWebserviceResources', 'actionObjectLanguageAddAfter', 'actionObjectProfileAddAfter',