Fix incorrect message shown on room type status change when its hotel is disabled
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user