diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index fe1ce4392..d4d1d111c 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -883,6 +883,12 @@ abstract class PaymentModuleCore extends Module } } + // Save room selling object and property type names as they are at the time of order creation + if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct, $idLang)) { + $objBookingDetail->room_type_selling_object_name = $roomTypeInfo['room_type_selling_object'].'|'.$roomTypeInfo['multiple_room_type_selling_object']; + } + $objBookingDetail->property_type_name = HotelPropertyType::getPropertyType($objCartBookingData->id_hotel, $idLang); + /*for saving details of the advance payment product wise*/ $objBookingDetail->total_paid_amount = $total_price['total_price_tax_incl']; if ($this->context->cart->is_advance_payment) { diff --git a/classes/RoomTypeSellingObject.php b/classes/RoomTypeSellingObject.php index 3d60c96ea..a072ba1cf 100644 --- a/classes/RoomTypeSellingObject.php +++ b/classes/RoomTypeSellingObject.php @@ -27,6 +27,7 @@ class RoomTypeSellingObjectCore extends ObjectModel public $date_add; public $date_upd; public $name; + public $name_plural; public static $definition = array( 'table' => 'room_type_selling_object', @@ -37,17 +38,15 @@ class RoomTypeSellingObjectCore extends ObjectModel 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), + 'name_plural' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), ), ); - public function delete() + public function isUsed() { - Db::getInstance()->execute( - 'UPDATE `'._DB_PREFIX_.'product` SET `id_room_type_selling_object` = NULL - WHERE `id_room_type_selling_object` = '.(int)$this->id + return (bool) Db::getInstance()->getValue( + 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'product` WHERE `id_room_type_selling_object` = '.(int) $this->id ); - - return parent::delete(); } public static function getRoomTypeSellingObject($idLang = null, $active = true) @@ -58,7 +57,7 @@ class RoomTypeSellingObjectCore extends ObjectModel $cache_key = 'RoomTypeSellingObject::getRoomTypeSellingObject'.(int)$idLang.'_'.(int)$active; if (!Cache::isStored($cache_key)) { - $sql = 'SELECT hrst.`id_room_type_selling_object` AS `id_room_type_selling_object`, hrstl.`name` + $sql = 'SELECT hrst.`id_room_type_selling_object` AS `id_room_type_selling_object`, hrstl.`name`, hrstl.`name_plural` FROM `'._DB_PREFIX_.'room_type_selling_object` hrst LEFT JOIN `'._DB_PREFIX_.'room_type_selling_object_lang` hrstl ON (hrst.`id_room_type_selling_object` = hrstl.`id_room_type_selling_object` diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index d4a02d904..4b42f25e3 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -322,7 +322,6 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $invoiceAddressPatternRules['avoid'][] = 'lastname'; if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($order_obj->id)) { $objHotelBranchInfo = new HotelBranchInformation((int) $idHotel, $context->language->id); - $propertyType = HotelPropertyType::getPropertyType($idHotel); $invoiceAddressPatternRules['avoid'][] = 'lastname'; if ($idHotelAddress = $objHotelBranchInfo->getHotelIdAddress()) { $objHotelAddress = new Address((int) $idHotelAddress); @@ -374,6 +373,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $unit_price_tax_incl = $order_details_obj->unit_price_tax_incl; $cart_htl_data[$type_key]['hotel_name'] = $data_v['hotel_name']; + $propertyType = $data_v['property_type_name']; + $cart_htl_data[$type_key]['name'] = $order_details_obj->product_name; $cart_htl_data[$type_key]['unit_price_tax_excl'] = $unit_price_tax_excl; $cart_htl_data[$type_key]['unit_price_tax_incl'] = $unit_price_tax_incl; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index aac780979..a21c1fd05 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5434,11 +5434,13 @@ class AdminOrdersControllerCore extends AdminController $objBookingDetail->check_in_time = $objHotelBranch->check_in; $objBookingDetail->check_out_time = $objHotelBranch->check_out; } - if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct)) { + if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct, $idLang)) { $objBookingDetail->adults = $objCartBookingData->adults; $objBookingDetail->children = $objCartBookingData->children; $objBookingDetail->child_ages = $objCartBookingData->child_ages; + $objBookingDetail->room_type_selling_object_name = $roomTypeInfo['room_type_selling_object'].'|'.$roomTypeInfo['multiple_room_type_selling_object']; } + $objBookingDetail->property_type_name = HotelPropertyType::getPropertyType($objCartBookingData->id_hotel, $idLang); if ($objBookingDetail->save()) { $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); diff --git a/controllers/admin/AdminRoomTypeSellingObjectsController.php b/controllers/admin/AdminRoomTypeSellingObjectsController.php index 724fdafb2..53aa3eaa5 100644 --- a/controllers/admin/AdminRoomTypeSellingObjectsController.php +++ b/controllers/admin/AdminRoomTypeSellingObjectsController.php @@ -45,6 +45,10 @@ class AdminRoomTypeSellingObjectsController extends AdminController 'title' => $this->l('Name'), 'align' => 'left', ), + 'name_plural' => array( + 'title' => $this->l('Plural Name'), + 'align' => 'left', + ), 'active' => array( 'title' => $this->l('Status'), 'align' => 'center', @@ -98,6 +102,14 @@ class AdminRoomTypeSellingObjectsController extends AdminController 'required' => true, 'hint' => $this->l('Displayed name for this room type selling object.'), ), + array( + 'type' => 'text', + 'label' => $this->l('Plural Name'), + 'name' => 'name_plural', + 'lang' => true, + 'required' => true, + 'hint' => $this->l('Displayed name when more than one is booked.'), + ), array( 'type' => 'switch', 'label' => $this->l('Enabled'), @@ -146,6 +158,18 @@ class AdminRoomTypeSellingObjectsController extends AdminController } } + if (!trim(Tools::getValue('name_plural_'.$defaultLangId))) { + $this->errors[] = $this->l('Plural Name is required at least in ').$objDefaultLanguage['name']; + } else { + foreach ($languages as $lang) { + if (trim(Tools::getValue('name_plural_'.$lang['id_lang']))) { + if (!Validate::isGenericName(Tools::getValue('name_plural_'.$lang['id_lang']))) { + $this->errors[] = $this->l('Invalid Plural Name in ').$lang['name']; + } + } + } + } + if ($idSellingObject) { $this->display = 'edit'; } else { @@ -159,4 +183,43 @@ class AdminRoomTypeSellingObjectsController extends AdminController parent::postProcess(); } } + + public function processDelete() + { + $object = $this->loadObject(); + if (!$this->checkDeletion($object)) { + return false; + } + return parent::processDelete(); + } + + protected function processBulkDelete() + { + if (is_array($this->boxes) && !empty($this->boxes)) { + foreach ($this->boxes as $idSellingObject) { + $object = new RoomTypeSellingObject((int) $idSellingObject); + if (!$this->checkDeletion($object)) { + return false; + } + } + } + + return parent::processBulkDelete(); + } + + protected function checkDeletion($object) + { + if (Validate::isLoadedObject($object)) { + if ($object->isUsed()) { + $this->errors[] = $this->l('You cannot delete this room type selling object because it is currently assigned to one or more room types.'); + } else { + return true; + } + } else { + $this->errors[] = Tools::displayError('An error occurred while deleting the object.').' + '.$this->table.' '.Tools::displayError('(cannot load object)'); + } + + return false; + } } diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index f25677620..1fdd09ef1 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -182,8 +182,13 @@ class OrderConfirmationControllerCore extends FrontController $cart_htl_data[$type_key]['cover_img'] = $cover_img; $cart_htl_data[$type_key]['adults'] = $rm_dtl['adults']; $cart_htl_data[$type_key]['children'] = $rm_dtl['children']; - $cart_htl_data[$type_key]['room_type_selling_object'] = $rm_dtl['room_type_selling_object']; - $cart_htl_data[$type_key]['multiple_room_type_selling_object'] = $rm_dtl['multiple_room_type_selling_object']; + + // Prefer the name stored at order-creation time so it stays historically accurate + if (!empty($order_bk_data[0]['room_type_selling_object_name'])) { + $sellingObjectNames = explode('|', $order_bk_data[0]['room_type_selling_object_name']); + $cart_htl_data[$type_key]['room_type_selling_object'] = $sellingObjectNames[0]; + $cart_htl_data[$type_key]['multiple_room_type_selling_object'] = $sellingObjectNames[1]; + } foreach ($order_bk_data as $data_k => $data_v) { $date_join = strtotime($data_v['date_from']).strtotime($data_v['date_to']); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 8c80d5633..8f50de38a 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -101,6 +101,7 @@ class OrderDetailControllerCore extends FrontController $total_convenience_fee_te = 0; $total_convenience_fee_ti = 0; $roomTypes = array(); + $propertyType = null; $objOrderReturn = new OrderReturn(); $refundedAmount = 0; $refundedAmount = $objOrderReturn->getRefundedAmount($order->id); @@ -131,9 +132,12 @@ class OrderDetailControllerCore extends FrontController } $cartHotelData[$type_key]['id_product'] = $type_value['product_id']; $cartHotelData[$type_key]['cover_img'] = $type_value['cover_img']; - if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($type_value['product_id'])) { - $cartHotelData[$type_key]['room_type_selling_object'] = $roomTypeInfo['room_type_selling_object']; - $cartHotelData[$type_key]['multiple_room_type_selling_object'] = $roomTypeInfo['multiple_room_type_selling_object']; + + // Prefer the name stored at order-creation time so it stays historically accurate + if (!empty($order_bk_data[0]['room_type_selling_object_name'])) { + $sellingObjectNames = explode('|', $order_bk_data[0]['room_type_selling_object_name']); + $cartHotelData[$type_key]['room_type_selling_object'] = $sellingObjectNames[0]; + $cartHotelData[$type_key]['multiple_room_type_selling_object'] = $sellingObjectNames[1]; } @@ -275,6 +279,7 @@ class OrderDetailControllerCore extends FrontController $cartHotelData[$type_key]['date_diff'][$date_join]['feature_price_diff'] = $feature_price_diff; $cartHotelData[$type_key]['hotel_name'] = $data_v['hotel_name']; + $propertyType = $data_v['property_type_name']; // add additional services products in hotel detail. $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services'] = $objServiceProductOrderDetail->getRoomTypeServiceProducts( $id_order, @@ -451,12 +456,12 @@ class OrderDetailControllerCore extends FrontController if ($idHotel = $addressTax->id_hotel) { $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); $hotelAddressInfo = HotelBranchInformation::getAddress($idHotel); - $propertyName = HotelPropertyType::getPropertyType($idHotel); + // Prefer the name stored at order-creation time so it stays historically accurate $objHotelBranchRefundRules = new HotelBranchRefundRules(); $hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1); $this->context->smarty->assign(array( 'obj_hotel_branch_information' => $objHotelBranchInformation, - 'property_name' => $propertyName, + 'property_type' => $propertyType, 'hotel_address_info' => $hotelAddressInfo, 'hotel_refund_rules' => $hotelRefundRules, )); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index ed26f73f5..2df7e90fb 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -2792,5 +2792,6 @@ CREATE TABLE IF NOT EXISTS `PREFIX_room_type_selling_object_lang` ( `id_room_type_selling_object` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(255) NOT NULL, + `name_plural` varchar(255) DEFAULT NULL, PRIMARY KEY (`id_room_type_selling_object`, `id_lang`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index ba1308020..dfc083828 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -53,6 +53,8 @@ class HotelBookingDetail extends ObjectModel // hotel information/location/contact public $hotel_name; public $room_type_name; + public $room_type_selling_object_name; + public $property_type_name; public $city; public $state; public $country; @@ -118,6 +120,8 @@ class HotelBookingDetail extends ObjectModel // hotel information/location/contact 'room_num' => array('type' => self::TYPE_STRING, 'required' => true), 'room_type_name' => array('type' => self::TYPE_STRING, 'required' => true), + 'room_type_selling_object_name' => array('type' => self::TYPE_STRING), + 'property_type_name' => array('type' => self::TYPE_STRING), 'hotel_name' => array('type' => self::TYPE_STRING, 'required' => true), 'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'size' => 64, 'required' => true), 'state' => array('type' => self::TYPE_STRING), diff --git a/modules/hotelreservationsystem/classes/HotelPropertyType.php b/modules/hotelreservationsystem/classes/HotelPropertyType.php index 9d75dc6d9..df7c64ce8 100644 --- a/modules/hotelreservationsystem/classes/HotelPropertyType.php +++ b/modules/hotelreservationsystem/classes/HotelPropertyType.php @@ -40,15 +40,16 @@ class HotelPropertyType extends ObjectModel ), ); - public function delete() + /** + * Check if this property type is currently assigned to any property. + * + * @return bool + */ + public function isUsed() { - Db::getInstance()->update( - 'htl_branch_info', - array('id_property_type' => 0), - '`id_property_type` = '.(int)$this->id + return (bool) Db::getInstance()->getValue( + 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'htl_branch_info` WHERE `id_property_type` = '.(int) $this->id ); - - return parent::delete(); } /** @@ -77,8 +78,8 @@ class HotelPropertyType extends ObjectModel } $propertyType = Cache::retrieve($cacheKey); - - return $propertyType ? $propertyType : Translate::getModuleTranslation('hotelreservationsystem', 'Hotel', 'HotelPropertyType'); + $module = Module::getInstanceByName('hotelreservationsystem'); + return $propertyType ? $propertyType : $module->l('Hotel', 'HotelPropertyType'); } /** diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index c6bcf2899..08b68ac75 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -182,6 +182,8 @@ class HotelReservationSystemDb `is_back_order` tinyint(4) NOT NULL, `hotel_name` varchar(255) DEFAULT NULL, `room_type_name` varchar(255) DEFAULT NULL, + `room_type_selling_object_name` varchar(255) DEFAULT NULL, + `property_type_name` varchar(255) DEFAULT NULL, `city` varchar(255) NOT NULL, `state` varchar(255) DEFAULT NULL, `country` varchar(255) DEFAULT NULL, diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index fb5cbaeea..35d2ceeed 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -237,7 +237,7 @@ class HotelRoomType extends ObjectModel $sql = 'SELECT hrt.*, hbl.`hotel_name`, hrtstl.`name` AS `room_type_selling_object`, - CONCAT(hrtstl.`name`, "s") AS `multiple_room_type_selling_object` + hrtstl.`name_plural` AS `multiple_room_type_selling_object` FROM `'._DB_PREFIX_.'htl_room_type` AS hrt INNER JOIN `'._DB_PREFIX_.'htl_branch_info_lang` AS hbl ON (hbl.`id` = hrt.`id_hotel` @@ -255,8 +255,9 @@ class HotelRoomType extends ObjectModel $result = Db::getInstance()->getRow($sql); if ($result && !$result['room_type_selling_object']) { - $result['room_type_selling_object'] = Translate::getModuleTranslation('hotelreservationsystem', 'Room', 'HotelRoomType'); - $result['multiple_room_type_selling_object'] = Translate::getModuleTranslation('hotelreservationsystem', 'Rooms', 'HotelRoomType'); + $module = Module::getInstanceByName('hotelreservationsystem'); + $result['room_type_selling_object'] = $module->l('Room', 'HotelRoomType'); + $result['multiple_room_type_selling_object'] = $module->l('Rooms', 'HotelRoomType'); } return $result; @@ -317,7 +318,7 @@ class HotelRoomType extends ObjectModel $idLang = Context::getContext()->language->id; } - $sql = 'SELECT pl.`name`, COUNT(hri.`id`) AS `numberOfRooms`, hrt.`id_product`, `adults`, `children`, `max_adults`, `max_children`, `max_guests`, hrtstl.`name` AS `room_type_selling_object`, CONCAT(hrtstl.`name`, "s") AS `multiple_room_type_selling_object` + $sql = 'SELECT pl.`name`, COUNT(hri.`id`) AS `numberOfRooms`, hrt.`id_product`, `adults`, `children`, `max_adults`, `max_children`, `max_guests`, hrtstl.`name` AS `room_type_selling_object`, hrtstl.`name_plural` AS `multiple_room_type_selling_object` '.($position ? ', cp.`position`' : '').' '.($fullDetail ? ', pl.`link_rewrite`, pl.`description_short`' : '').' FROM `'._DB_PREFIX_.'htl_room_type` AS `hrt` @@ -344,8 +345,9 @@ class HotelRoomType extends ObjectModel foreach ($results as &$row) { if (!$row['room_type_selling_object']) { - $row['room_type_selling_object'] = Translate::getModuleTranslation('hotelreservationsystem', 'Room', 'HotelRoomType'); - $row['multiple_room_type_selling_object'] = Translate::getModuleTranslation('hotelreservationsystem', 'Rooms', 'HotelRoomType'); + $module = Module::getInstanceByName('hotelreservationsystem'); + $row['room_type_selling_object'] = $module->l('Room', 'HotelRoomType'); + $row['multiple_room_type_selling_object'] = $module->l('Rooms', 'HotelRoomType'); } } unset($row); diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelPropertyTypesController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelPropertyTypesController.php index 4992e4af0..c1fe01534 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelPropertyTypesController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelPropertyTypesController.php @@ -159,4 +159,43 @@ class AdminHotelPropertyTypesController extends ModuleAdminController parent::postProcess(); } } + + public function processDelete() + { + $object = $this->loadObject(); + if (!$this->checkDeletion($object)) { + return false; + } + return parent::processDelete(); + } + + protected function processBulkDelete() + { + if (is_array($this->boxes) && !empty($this->boxes)) { + foreach ($this->boxes as $idPropertyType) { + $object = new HotelPropertyType((int) $idPropertyType); + if (!$this->checkDeletion($object)) { + return false; + } + } + } + + return parent::processBulkDelete(); + } + + protected function checkDeletion($object) + { + if (Validate::isLoadedObject($object)) { + if ($object->isUsed()) { + $this->errors[] = $this->l('You cannot delete this property type because it is currently assigned to one or more properties.'); + } else { + return true; + } + } else { + $this->errors[] = Tools::displayError('An error occurred while deleting the object.').' + '.$this->table.' '.Tools::displayError('(cannot load object)'); + } + + return false; + } } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php index c25c6af0a..a741ca00b 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php @@ -314,9 +314,12 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $booking['id'] ); - $roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($booking['id_product']); - $booking['room_type_info'] = $roomTypeInfo; $booking = array_merge($booking, array_shift($bookingCharges)); + + if (!empty($booking['room_type_selling_object_name'])) { + $sellingObjectNames = explode('|', $booking['room_type_selling_object_name']); + $booking['room_type_selling_object_name'] = $sellingObjectNames[0]; + } } } diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl index 135c2d37d..d980b664e 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl @@ -16,10 +16,10 @@