-
- {l s='Bed Types'}
+
+ {l s='Amenities'}
-
-
- {foreach from=$bed_types_info item=bed_type_info}
- {$bed_type_info['name']}
- {/foreach}
-
+
+ {if isset($room_type_amenities) && $room_type_amenities}
+
+
+ {foreach from=$room_type_amenities item=amenity_group}
+
+
+ {$amenity_group.name|escape:'html':'UTF-8'}
+
+ {if isset($amenity_group.children) && $amenity_group.children}
+
+ {foreach from=$amenity_group.children item=amenity}
+
+
+
+
+ {$amenity.name|escape:'html':'UTF-8'}
+
+
+
+ {/foreach}
+
+ {/if}
+
+ {/foreach}
+
+
+ {else}
+
+ {l s='No amenities have been defined yet.'}
+
+ {/if}
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php
index 0a7acb76f..52e369f5b 100644
--- a/controllers/admin/AdminProductsController.php
+++ b/controllers/admin/AdminProductsController.php
@@ -944,12 +944,6 @@ class AdminProductsControllerCore extends AdminController
$id_hotel_new = $room_type_info['id_hotel'];
}
- $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
- if ($roomTypeBedTypes = $objHotelRoomTypeBedType->getRoomTypeBedTypes($id_product_old)) {
- $roomTypeBedTypes = array_column($roomTypeBedTypes, 'id_bed_type');
- $objHotelRoomTypeBedType->updateRoomTypeBedTypes($roomTypeBedTypes, $product->id);
- }
-
if ($product->hasAttributes()) {
Product::updateDefaultAttribute($product->id);
} else {
@@ -1143,34 +1137,162 @@ class AdminProductsControllerCore extends AdminController
}
if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))) {
- // delete all objects
- $product->deleteFeatures();
-
- // add new objects
- $languages = Language::getLanguages(false);
- foreach ($_POST as $key => $val) {
- if (preg_match('/^feature_([0-9]+)_check/i', $key, $match)) {
- if ($val) {
- $product->addFeaturesToDB($match[1], $val);
- } else {
- if ($default_value = $this->checkFeatures($languages, $match[1])) {
- $id_value = $product->addFeaturesToDB($match[1], 0, 1);
- foreach ($languages as $language) {
- if ($cust = Tools::getValue('custom_'.$match[1].'_'.(int)$language['id_lang'])) {
- $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $cust);
- } else {
- $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $default_value);
- }
- }
- }
- }
- }
+ if (!$this->saveRoomTypeFeatureAssignments($product)) {
+ $this->errors[] = Tools::displayError('An error occurred while saving room type features.');
}
} else {
$this->errors[] = Tools::displayError('A room type must be created before adding features.');
}
}
+ /**
+ * Save assigned core feature values for a room type.
+ *
+ * @param Product $product
+ *
+ * @return bool
+ */
+ protected function saveRoomTypeFeatureAssignments(Product $product)
+ {
+ $product->deleteFeatures();
+
+ $languages = Language::getLanguages(false);
+ foreach ($_POST as $key => $val) {
+ if (preg_match('/^feature_([0-9]+)_check/i', $key, $match)) {
+ if ($val) {
+ $product->addFeaturesToDB($match[1], $val);
+ } elseif ($default_value = $this->checkFeatures($languages, $match[1])) {
+ $id_value = $product->addFeaturesToDB($match[1], 0, 1);
+ foreach ($languages as $language) {
+ if ($cust = Tools::getValue('custom_'.$match[1].'_'.(int)$language['id_lang'])) {
+ $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $cust);
+ } else {
+ $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $default_value);
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Save selected room type amenities.
+ *
+ * @param int $idProduct
+ *
+ * @return bool
+ */
+ protected function saveRoomTypeAmenities($idProduct)
+ {
+ $idProduct = (int) $idProduct;
+ $selectedAmenities = Tools::getValue('room_type_amenities', array());
+ if (!is_array($selectedAmenities)) {
+ $selectedAmenities = array($selectedAmenities);
+ }
+
+ $selectedAmenities = array_map('intval', $selectedAmenities);
+ $selectedAmenities = array_values(array_unique(array_filter($selectedAmenities)));
+
+ if (!Db::getInstance()->delete('htl_room_type_features', '`id_product` = '.$idProduct)) {
+ return false;
+ }
+
+ foreach ($selectedAmenities as $idAmenity) {
+ if (!Db::getInstance()->insert('htl_room_type_features', array(
+ 'id_product' => $idProduct,
+ 'feature_id' => (int) $idAmenity,
+ 'date_add' => date('Y-m-d H:i:s'),
+ 'date_upd' => date('Y-m-d H:i:s'),
+ ))) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Get selected room type amenity ids.
+ *
+ * @param int $idProduct
+ *
+ * @return array
+ */
+ protected function getSelectedRoomTypeAmenityIds($idProduct)
+ {
+ $selectedAmenities = Db::getInstance()->executeS(
+ 'SELECT `feature_id`
+ FROM `'._DB_PREFIX_.'htl_room_type_features`
+ WHERE `id_product` = '.(int) $idProduct
+ );
+
+ if (!$selectedAmenities) {
+ return array();
+ }
+
+ return array_map('intval', array_column($selectedAmenities, 'feature_id'));
+ }
+
+ /**
+ * Prepare amenities tree data for room type form.
+ *
+ * @param int $idProduct
+ *
+ * @return array
+ */
+ protected function getRoomTypeAmenitiesTree($idProduct)
+ {
+ $selectedAmenityRows = array();
+ foreach ($this->getSelectedRoomTypeAmenityIds($idProduct) as $selectedAmenityId) {
+ $selectedAmenityRows[] = array('feature_id' => $selectedAmenityId);
+ }
+
+ $objHotelFeatures = new HotelFeatures();
+ $roomTypeAmenities = $objHotelFeatures->HotelBranchSelectedFeaturesArray(
+ $selectedAmenityRows,
+ $this->context->language->id
+ );
+
+ return $roomTypeAmenities ? $roomTypeAmenities : array();
+ }
+
+ /**
+ * Prepare grouped core features and values for the room type feature tree.
+ *
+ * @param Product $product
+ *
+ * @return array
+ */
+ protected function getRoomTypeFeatureTree(Product $product)
+ {
+ $features = Feature::getFeatures(
+ $this->context->language->id,
+ (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP)
+ );
+ $selectedFeatureValues = array();
+ foreach ($product->getFeatures() as $productFeature) {
+ $selectedFeatureValues[(int) $productFeature['id_feature']] = (int) $productFeature['id_feature_value'];
+ }
+
+ foreach ($features as &$feature) {
+ $feature['current_item'] = isset($selectedFeatureValues[(int) $feature['id_feature']])
+ ? $selectedFeatureValues[(int) $feature['id_feature']]
+ : 0;
+ $feature['featureValues'] = FeatureValue::getFeatureValuesWithLang(
+ $this->context->language->id,
+ (int) $feature['id_feature']
+ );
+
+ foreach ($feature['featureValues'] as &$featureValue) {
+ $featureValue['selected'] = ((int) $feature['current_item'] === (int) $featureValue['id_feature_value']);
+ }
+ }
+
+ return $features;
+ }
+
/**
* This function is never called at the moment (specific prices cannot be edited)
*/
@@ -1924,14 +2046,20 @@ class AdminProductsControllerCore extends AdminController
$this->copyFromPost($this->object, $this->table);
$this->object->booking_product = true;
if ($this->object->add()) {
- $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
- $objHotelRoomTypeBedType->updateRoomTypeBedTypes(Tools::getValue('id_bed_types'), $this->object->id);
// associateroom type to hotel
// if ($this->object->is_virtual) {
// }
$this->assignRoomType($this->object);
+ if ($this->isTabSubmitted('Informations') && !$this->saveRoomTypeAmenities($this->object->id)) {
+ $this->errors[] = Tools::displayError('An error occurred while saving room type amenities.');
+ return false;
+ }
+ if ($this->isTabSubmitted('Features') && !$this->saveRoomTypeFeatureAssignments($this->object)) {
+ $this->errors[] = Tools::displayError('An error occurred while saving room type features.');
+ return false;
+ }
PrestaShopLogger::addLog(sprintf($this->l('%s addition', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
@@ -2109,8 +2237,14 @@ class AdminProductsControllerCore extends AdminController
}
if ($object->update()) {
- $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
- $objHotelRoomTypeBedType->updateRoomTypeBedTypes(Tools::getValue('id_bed_types'), $object->id);
+ if ($this->isTabSubmitted('Informations') && !$this->saveRoomTypeAmenities($object->id)) {
+ $this->errors[] = Tools::displayError('An error occurred while saving room type amenities.');
+ return false;
+ }
+ if ($this->isTabSubmitted('Features') && !$this->saveRoomTypeFeatureAssignments($object)) {
+ $this->errors[] = Tools::displayError('An error occurred while saving room type features.');
+ return false;
+ }
// update position in category
$object->setPositionInCategory(Tools::getValue('category_position'));
@@ -2134,9 +2268,6 @@ class AdminProductsControllerCore extends AdminController
if ($this->isTabSubmitted('Suppliers')) {
// $this->processSuppliers();
}
- if ($this->isTabSubmitted('Features')) {
- $this->processFeatures();
- }
if ($this->isTabSubmitted('Combinations')) {
$this->processProductAttribute();
}
@@ -4534,15 +4665,15 @@ class AdminProductsControllerCore extends AdminController
$data->assign('htl_full_info', $hotelFullInfo);
}
- $objHotelBedType = new HotelBedType();
- $bedTypes = $objHotelBedType->getAllBedTypes($this->context->language->id);
- $data->assign('bed_types_info', $bedTypes);
- $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
- if ($selectedBedTypes = $objHotelRoomTypeBedType->getRoomTypeBedTypes($product->id)) {
- $selectedBedTypes = array_column($selectedBedTypes, 'id_bed_type');
- $data->assign('selected_bed_types', $selectedBedTypes);
+ $roomTypeAmenities = $this->getRoomTypeAmenitiesTree((int) $product->id);
+ if (!is_array($roomTypeAmenities) || empty($roomTypeAmenities)) {
+ $roomTypeAmenities = array();
}
+ $data->assign('bed_types_info', array());
+ $data->assign('selected_bed_types', array());
+ $data->assign('room_type_amenities', $roomTypeAmenities);
+
$this->tpl_form_vars['product'] = $product;
$this->tpl_form_vars['custom_form'] = $data->fetch();
}
@@ -4784,36 +4915,7 @@ class AdminProductsControllerCore extends AdminController
} else {
if ($obj->id) {
if ($this->product_exists_in_shop) {
- $features = Feature::getFeatures($this->context->language->id, (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP));
-
- foreach ($features as $k => $tab_features) {
- $features[$k]['current_item'] = false;
- $features[$k]['val'] = array();
-
- $custom = true;
- foreach ($obj->getFeatures() as $tab_products) {
- if ($tab_products['id_feature'] == $tab_features['id_feature']) {
- $features[$k]['current_item'] = $tab_products['id_feature_value'];
- }
- }
-
- $features[$k]['featureValues'] = FeatureValue::getFeatureValuesWithLang($this->context->language->id, (int)$tab_features['id_feature']);
- if (count($features[$k]['featureValues'])) {
- foreach ($features[$k]['featureValues'] as $value) {
- if ($features[$k]['current_item'] == $value['id_feature_value']) {
- $custom = false;
- }
- }
- }
-
- if ($custom) {
- $feature_values_lang = FeatureValue::getFeatureValueLang($features[$k]['current_item']);
- foreach ($feature_values_lang as $feature_value) {
- $features[$k]['val'][$feature_value['id_lang']] = $feature_value;
- }
- }
- }
-
+ $features = $this->getRoomTypeFeatureTree($obj);
$data->assign('available_features', $features);
$data->assign('product', $obj);
$data->assign('link', $this->context->link);
diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php
index e9fb16151..a679f55f4 100644
--- a/controllers/front/ProductController.php
+++ b/controllers/front/ProductController.php
@@ -409,19 +409,8 @@ class ProductControllerCore extends FrontController
}
}
- $objHotelBedType = new HotelBedType();
- if ($bedTypes = $objHotelBedType->getAllBedTypes($this->context->language->id)) {
- foreach ($bedTypes as $bedTypeKey => $bedType) {
- $bedTypes[$bedTypeKey]['area'] = Tools::ps_round($bedType['width'], 2).' * '.Tools::ps_round($bedType['length'], 2);
- }
-
- $bedTypes = array_column($bedTypes, null, 'id_bed_type');
- }
-
- $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
- if ($selectedBedTypes = $objHotelRoomTypeBedType->getRoomTypeBedTypes($this->product->id)) {
- $selectedBedTypes = array_column($selectedBedTypes, 'id_bed_type');
- }
+ $roomDynamicFeatures = $this->getRoomDynamicFeatures($this->product->id);
+ $roomDynamicAmenities = $this->getRoomDynamicAmenities($this->product->id);
$this->context->smarty->assign(
array(
@@ -449,14 +438,12 @@ class ProductControllerCore extends FrontController
'hotel_description' => $hotel_info_by_id['description'],
'hotel_policies' => $hotel_policies,
'hotel_features' => $htl_features,
+ 'room_dynamic_features' => $roomDynamicFeatures,
+ 'room_dynamic_amenities' => $roomDynamicAmenities,
'hotel_image_link' => $hotelImageLink,
'hotel_has_images' => (bool) HotelImage::getCover($hotel_id),
- 'ftr_img_src' => _PS_IMG_.'rf/',
'order_date_restrict' => $order_date_restrict,
'PS_SERVICE_PRODUCT_CATEGORY_FILTER' => Configuration::get('PS_SERVICE_PRODUCT_CATEGORY_FILTER'),
- 'bed_types_info' => $bedTypes,
- 'selected_bed_types' => $selectedBedTypes,
- 'dimension_unit' => Configuration::get('WK_DIMENSION_UNIT', $this->context->language->id),
)
);
@@ -580,6 +567,68 @@ class ProductControllerCore extends FrontController
$this->setTemplate(_PS_THEME_DIR_.'product.tpl');
}
+ /**
+ * Get assigned dynamic room features for the room detail page.
+ *
+ * @param int $idProduct
+ *
+ * @return array
+ */
+ protected function getRoomDynamicFeatures($idProduct)
+ {
+ $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+ SELECT fl.`name` AS `feature_name`, fvl.`value` AS `feature_value`, f.`position`
+ FROM `'._DB_PREFIX_.'feature_product` fp
+ INNER JOIN `'._DB_PREFIX_.'feature` f ON (f.`id_feature` = fp.`id_feature`)
+ INNER JOIN `'._DB_PREFIX_.'feature_lang` fl
+ ON (fl.`id_feature` = fp.`id_feature` AND fl.`id_lang` = '.(int) $this->context->language->id.')
+ INNER JOIN `'._DB_PREFIX_.'feature_value_lang` fvl
+ ON (fvl.`id_feature_value` = fp.`id_feature_value` AND fvl.`id_lang` = '.(int) $this->context->language->id.')
+ WHERE fp.`id_product` = '.(int) $idProduct.'
+ ORDER BY f.`position` ASC, fl.`name` ASC'
+ );
+
+ if (!$features) {
+ return array();
+ }
+
+ $result = array();
+ foreach ($features as $feature) {
+ $result[] = array(
+ 'name' => $feature['feature_name'],
+ 'value' => $feature['feature_value'],
+ );
+ }
+
+ return $result;
+ }
+
+ /**
+ * Get assigned dynamic room amenities for the room detail page.
+ *
+ * @param int $idProduct
+ *
+ * @return array
+ */
+ protected function getRoomDynamicAmenities($idProduct)
+ {
+ $amenities = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+ SELECT hfl.`name`
+ FROM `'._DB_PREFIX_.'htl_room_type_features` hrtf
+ INNER JOIN `'._DB_PREFIX_.'htl_features_lang` hfl
+ ON (hfl.`id` = hrtf.`feature_id` AND hfl.`id_lang` = '.(int) $this->context->language->id.')
+ INNER JOIN `'._DB_PREFIX_.'htl_features` hf ON (hf.`id` = hrtf.`feature_id`)
+ WHERE hrtf.`id_product` = '.(int) $idProduct.'
+ ORDER BY hf.`position` ASC, hfl.`name` ASC'
+ );
+
+ if (!$amenities) {
+ return array();
+ }
+
+ return $amenities;
+ }
+
public function assignRoomServiceProductVars()
{
// get service products for room type
diff --git a/modules/hotelreservationsystem/classes/HotelBedType.php b/modules/hotelreservationsystem/classes/HotelBedType.php
index 13d47d822..ee5707eca 100644
--- a/modules/hotelreservationsystem/classes/HotelBedType.php
+++ b/modules/hotelreservationsystem/classes/HotelBedType.php
@@ -41,6 +41,10 @@ class HotelBedType extends ObjectModel
public function getAllBedTypes($idLang)
{
+ if (!$this->hasLegacyBedTypeTables()) {
+ return array();
+ }
+
if (!$idLang) {
$idLang = Context::getContext()->language->id;
}
@@ -54,9 +58,25 @@ class HotelBedType extends ObjectModel
public function delete()
{
+ if (!$this->hasLegacyBedTypeTables()) {
+ return true;
+ }
+
$objHotelRoomTypeBedType = new HotelRoomTypeBedType();
$objHotelRoomTypeBedType->deleteRoomTypeBedTypes($this->id);
return parent::delete();
}
+
+ /**
+ * Checks whether the deprecated bed type schema still exists.
+ *
+ * @return bool
+ */
+ protected function hasLegacyBedTypeTables()
+ {
+ return (bool) Db::getInstance()->getValue(
+ 'SHOW TABLES LIKE \'' . pSQL(_DB_PREFIX_.$this->table) . '\''
+ );
+ }
}
diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php
index a196694f5..1484cefa4 100644
--- a/modules/hotelreservationsystem/classes/HotelHelper.php
+++ b/modules/hotelreservationsystem/classes/HotelHelper.php
@@ -1139,103 +1139,59 @@ class HotelHelper
return true;
}
- public function createHotelRoomDefaultFeatures()
+ /**
+ * Seed default core room features and values used by room types.
+ *
+ * @return bool
+ */
+ public function seedDefaultDynamicRoomFeatures()
{
- $htl_room_ftrs = array(
- 'Wi-Fi' => array(
- 'en' => 'Wi-Fi',
- 'nl' => 'Wi-Fi',
- 'fr' => 'Wi-Fi',
- 'de' => 'Wi-Fi',
- 'ru' => 'Wi-Fi',
- 'es' => 'Wi-Fi'
- ),
- 'News Paper' => array(
- 'en' => 'News Paper',
- 'nl' => 'Krant',
- 'fr' => 'Journal',
- 'de' => 'Zeitung',
- 'ru' => 'Газета',
- 'es' => 'Periódico'
- ),
- 'Power BackUp' => array(
- 'en' => 'Power BackUp',
- 'nl' => 'Stroomvoorziening',
- 'fr' => 'Alimentation de secours',
- 'de' => 'Notstromversorgung',
- 'ru' => 'Резервное электропитание',
- 'es' => 'Energía de respaldo'
- ),
- 'Refrigerator' => array(
- 'en' => 'Refrigerator',
- 'nl' => 'Koelkast',
- 'fr' => 'Réfrigérateur',
- 'de' => 'Kühlschrank',
- 'ru' => 'Холодильник',
- 'es' => 'Refrigerador'
- ),
- 'Restaurant' => array(
- 'en' => 'Restaurant',
- 'nl' => 'Restaurant',
- 'fr' => 'Restaurant',
- 'de' => 'Restaurant',
- 'ru' => 'Ресторан',
- 'es' => 'Restaurante'
- ),
- 'Room Service' => array(
- 'en' => 'Room Service',
- 'nl' => 'Roomservice',
- 'fr' => 'Service de chambre',
- 'de' => 'Zimmerservice',
- 'ru' => 'Обслуживание номеров',
- 'es' => 'Servicio de habitaciones'
- ),
- 'Gym' => array(
- 'en' => 'Gym',
- 'nl' => 'Fitnessruimte',
- 'fr' => 'Salle de sport',
- 'de' => 'Fitnessraum',
- 'ru' => 'Фитнес',
- 'es' => 'Gimnasio'
- )
- );
+ $idLang = (int) Configuration::get('PS_LANG_DEFAULT');
+ $position = 0;
- // image value in rf/ folder
- $pos = 1;
- $languages = Language::getLanguages(true);
- foreach ($htl_room_ftrs as $room_ftr_k => $room_ftr_v) {
- $obj_feature = new Feature();
- foreach ($languages as $lang) {
- if (isset($room_ftr_v[$lang['iso_code']])) {
- $obj_feature->name[$lang['id_lang']] = $room_ftr_v[$lang['iso_code']];
- } else {
- $obj_feature->name[$lang['id_lang']] = $room_ftr_v['en'];
- }
+ foreach ($this->getDefaultDynamicRoomFeatures() as $featureName => $featureValues) {
+ $idFeature = (int) Feature::addFeatureImport($featureName, $position);
+ if (!$idFeature) {
+ return false;
}
- $obj_feature->position = $pos-1;
- $obj_feature->save();
- if ($obj_feature->id) {
- $obj_feature_value = new FeatureValue();
- $obj_feature_value->id_feature = $obj_feature->id;
- foreach ($languages as $lang) {
- $obj_feature_value->value[$lang['id_lang']] = $obj_feature->id.'.jpg';
- }
-
- $obj_feature_value->save();
- if ($obj_feature_value->id) {
- if (file_exists(_PS_IMG_DIR_.'rf/'.$pos.'.jpg')) {
- rename(_PS_IMG_DIR_.'rf/'.$pos.'.jpg', _PS_IMG_DIR_.'rf/'.$obj_feature->id.'.jpg');
- }
+ foreach ($featureValues as $featureValue) {
+ $idFeatureValue = (int) FeatureValue::addFeatureValueImport($idFeature, $featureValue, null, $idLang, false);
+ if (!$idFeatureValue) {
+ return false;
}
}
- $pos++;
+ ++$position;
}
return true;
}
+ /**
+ * Return the default room feature/value seed set.
+ *
+ * @return array
+ */
+ protected function getDefaultDynamicRoomFeatures()
+ {
+ return array(
+ 'Bed Type' => array('Single', 'Double', 'Queen', 'King', 'Super King', 'Twin', 'Bunk Bed', 'Sofa Bed', 'Futon', 'Murphy Bed', 'Water Bed'),
+ 'Extra Bed Available' => array('Yes', 'No', 'On Request', 'Chargeable'),
+ 'Crib/Cot Available' => array('Yes', 'No', 'On Request'),
+ 'Room Size' => array('150 sq ft', '200 sq ft', '300 sq ft', '400 sq ft', '500 sq ft', '600 sq ft', '800 sq ft', '1000+ sq ft'),
+ 'View' => array('Sea/Ocean View', 'Garden View', 'City View', 'Pool View', 'Mountain View', 'Lake View', 'River View', 'Park View', 'Courtyard View', 'Desert View', 'No View/Interior'),
+ 'Balcony Type' => array('Private Balcony', 'Shared Terrace', 'Juliet Balcony', 'Rooftop Access', 'Patio', 'Veranda', 'None'),
+ 'Bathroom Type' => array('Private/Ensuite', 'Shared', 'Jack and Jill (shared between 2 rooms)', 'Half Bath'),
+ 'AC Type' => array('Split AC', 'Central AC', 'Window AC', 'No AC', 'Fan Only'),
+ 'Heating Type' => array('Central Heating', 'Room Heater', 'Underfloor Heating', 'Fireplace', 'No Heating'),
+ 'TV Type' => array('No TV', 'LED TV', 'Smart TV', 'OLED TV'),
+ 'Wi-Fi Speed' => array('No Wi-Fi', 'Basic', 'High Speed', 'Premium/Fiber'),
+ 'Smoke Detection' => array('Smoke Detector', 'Sprinkler', 'None'),
+ 'Smoking Policy' => array('Smoking Not Allowed', 'Smoking Allowed'),
+ );
+ }
+
public function createHotelDefaultBedTypes()
{
$htlBedTypes = array(
diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php
index ca44a2826..ea81fa565 100644
--- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php
+++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php
@@ -94,12 +94,23 @@ class HotelReservationSystemDb
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_features` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_hotel` int(10) unsigned NOT NULL,
- `feature_id` varchar(255) DEFAULT NULL,
+ `feature_id` int(10) unsigned NOT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
+ "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_features` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `id_product` int(10) unsigned NOT NULL,
+ `feature_id` int(10) unsigned NOT NULL,
+ `date_add` datetime NOT NULL,
+ `date_upd` datetime NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `id_product` (`id_product`),
+ KEY `feature_id` (`feature_id`)
+ ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
+
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_features` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_feature_id` int(10) unsigned NOT NULL,
@@ -494,26 +505,7 @@ class HotelReservationSystemDb
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_settings_link`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
- "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_bed_type` (
- `id_bed_type` INT(11) NOT NULL AUTO_INCREMENT,
- `length` DECIMAL(20,6) NOT NULL DEFAULT '0.000000',
- `width` DECIMAL(20,6) NOT NULL DEFAULT '0.000000',
- PRIMARY KEY (`id_bed_type`)
- ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
- "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_bed_type_lang`(
- `id_bed_type` INT(11) NOT NULL,
- `name` VARCHAR(255) DEFAULT NULL,
- `id_lang` INT(11) NOT NULL,
- PRIMARY KEY (`id_bed_type`, `id_lang`)
- ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
- "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_bed_type` (
- `id_room_type_bed_type` INT(11) NOT NULL AUTO_INCREMENT,
- `id_product` INT(11) NOT NULL,
- `id_bed_type` INT(11) NOT NULL,
- PRIMARY KEY (`id_room_type_bed_type`)
- ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
-
- "INSERT INTO `"._DB_PREFIX_."htl_settings_link` (`id_settings_link`, `icon`, `link`, `new_window`, `position`, `unremovable`, `active`, `date_add`, `date_upd`) VALUES
+ "INSERT IGNORE INTO `"._DB_PREFIX_."htl_settings_link` (`id_settings_link`, `icon`, `link`, `new_window`, `position`, `unremovable`, `active`, `date_add`, `date_upd`) VALUES
(1, 'icon-cogs', 'index.php?controller=AdminHotelGeneralSettings', 0, 0, 1, 1, NOW(), NOW()),
(2, 'icon-dollar', 'index.php?controller=AdminHotelFeaturePricesSettings', 0, 2, 1, 1, NOW(), NOW()),
(3, 'icon-plus-square', 'index.php?controller=AdminRoomTypeGlobalDemand', 0, 3, 1, 1, NOW(), NOW()),
@@ -528,27 +520,27 @@ class HotelReservationSystemDb
PRIMARY KEY (`id_settings_link`, `id_lang`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;",
- "INSERT INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
+ "INSERT IGNORE INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
SELECT 1, `id_lang`, 'General Settings', 'Configure Your hotel general settings using this option.'
FROM `"._DB_PREFIX_."lang`
ORDER BY `id_lang`;",
- "INSERT INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
+ "INSERT IGNORE INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
SELECT 2, `id_lang`, 'Advanced Price Rules', 'Here set Advanced price rules for specific dates.'
FROM `"._DB_PREFIX_."lang`
ORDER BY `id_lang`;",
- "INSERT INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
+ "INSERT IGNORE INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
SELECT 3, `id_lang`, 'Additional Facilities', 'Here create Additional facilities and their prices for room types.'
FROM `"._DB_PREFIX_."lang`
ORDER BY `id_lang`;",
- "INSERT INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
+ "INSERT IGNORE INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
SELECT 4, `id_lang`, 'Hotel Interior Block', 'Configure Hotel Interior block. You can display hotel interior images using this block. This block will be displayed on home page.'
FROM `"._DB_PREFIX_."lang`
ORDER BY `id_lang`;",
- "INSERT INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
+ "INSERT IGNORE INTO `"._DB_PREFIX_."htl_settings_link_lang` (`id_settings_link`, `id_lang`, `name`, `hint`)
SELECT 5, `id_lang`, 'Hotel Amenities Block', 'Configure Hotels Amenities settings. You can display hotel amenities images using this block. This block will be displayed on home page.'
FROM `"._DB_PREFIX_."lang`
ORDER BY `id_lang`;",
@@ -569,6 +561,41 @@ class HotelReservationSystemDb
return true;
}
+ /**
+ * Applies the schema changes required for the dynamic room feature migration.
+ *
+ * @return bool
+ */
+ public function migrateToDynamicRoomFeatureSchema()
+ {
+ $sql = array(
+ 'UPDATE `'._DB_PREFIX_.'htl_branch_features` SET `feature_id` = NULL WHERE `feature_id` = ""',
+ 'ALTER TABLE `'._DB_PREFIX_.'htl_branch_features`
+ MODIFY `feature_id` int(10) unsigned DEFAULT NULL',
+ 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'htl_room_type_features` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `id_product` int(10) unsigned NOT NULL,
+ `feature_id` int(10) unsigned NOT NULL,
+ `date_add` datetime NOT NULL,
+ `date_upd` datetime NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `id_product` (`id_product`),
+ KEY `feature_id` (`feature_id`)
+ ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1',
+ 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'htl_room_type_bed_type`',
+ 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'htl_bed_type_lang`',
+ 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'htl_bed_type`',
+ );
+
+ foreach ($sql as $query) {
+ if (!Db::getInstance()->execute($query)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public function dropTables()
{
return Db::getInstance()->execute(
@@ -579,6 +606,7 @@ class HotelReservationSystemDb
`'._DB_PREFIX_.'htl_branch_info_lang`,
`'._DB_PREFIX_.'htl_image`,
`'._DB_PREFIX_.'htl_branch_features`,
+ `'._DB_PREFIX_.'htl_room_type_features`,
`'._DB_PREFIX_.'htl_features`,
`'._DB_PREFIX_.'htl_features_lang`,
`'._DB_PREFIX_.'htl_cart_booking_data`,
diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeBedType.php b/modules/hotelreservationsystem/classes/HotelRoomTypeBedType.php
index e404ca4a0..67c05c114 100644
--- a/modules/hotelreservationsystem/classes/HotelRoomTypeBedType.php
+++ b/modules/hotelreservationsystem/classes/HotelRoomTypeBedType.php
@@ -37,6 +37,10 @@ class HotelRoomTypeBedType extends ObjectModel
public function getRoomTypeBedTypes($idProduct)
{
+ if (!$this->hasLegacyBedTypeTable()) {
+ return array();
+ }
+
$sql = 'SELECT * FROM `'._DB_PREFIX_.$this->table.'`
WHERE `id_product` ='.(int) $idProduct;
@@ -45,6 +49,10 @@ class HotelRoomTypeBedType extends ObjectModel
public function updateRoomTypeBedTypes($idBedTypes, $idProduct)
{
+ if (!$this->hasLegacyBedTypeTable()) {
+ return true;
+ }
+
$res = true;
if ($roomTypeBedTypes = $this->getRoomTypeBedTypes($idProduct)) {
$roomTypeBedTypes = array_column($roomTypeBedTypes, 'id_room_type_bed_type', 'id_bed_type');
@@ -74,6 +82,10 @@ class HotelRoomTypeBedType extends ObjectModel
public function deleteRoomTypeBedTypesById($idRoomTypeBedTypes)
{
+ if (!$this->hasLegacyBedTypeTable()) {
+ return true;
+ }
+
$res = true;
if ($idRoomTypeBedTypes) {
foreach ($idRoomTypeBedTypes as $idRoomTypeBedType) {
@@ -87,10 +99,26 @@ class HotelRoomTypeBedType extends ObjectModel
public function deleteRoomTypeBedTypes($idBedType = false, $idProduct = false)
{
+ if (!$this->hasLegacyBedTypeTable()) {
+ return true;
+ }
+
return Db::getInstance()->delete(
$this->table,
' 1 '.($idBedType ? ' AND `id_bed_type`='.(int) $idBedType : '').($idProduct ? ' AND `id_product`='.(int) $idProduct : '')
);
}
+ /**
+ * Checks whether the deprecated room-type bed mapping table still exists.
+ *
+ * @return bool
+ */
+ protected function hasLegacyBedTypeTable()
+ {
+ return (bool) Db::getInstance()->getValue(
+ 'SHOW TABLES LIKE \'' . pSQL(_DB_PREFIX_.$this->table) . '\''
+ );
+ }
+
}
diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php
index baa85790c..35f1bdfe2 100644
--- a/modules/hotelreservationsystem/hotelreservationsystem.php
+++ b/modules/hotelreservationsystem/hotelreservationsystem.php
@@ -33,7 +33,7 @@ class HotelReservationSystem extends Module
{
$this->name = 'hotelreservationsystem';
$this->tab = 'administration';
- $this->version = '1.7.0';
+ $this->version = '1.7.1';
$this->author = 'Webkul';
$this->need_instance = 0;
$this->bootstrap = true;
@@ -511,8 +511,7 @@ class HotelReservationSystem extends Module
'htl_room_type_global_demand',
'htl_room_type_global_demand_advance_option',
'htl_order_refund_rules',
- 'htl_settings_link',
- 'htl_bed_type'
+ 'htl_settings_link'
);
//If Admin update new language when we do entry in module all lang tables.
HotelHelper::updateLangTables($newIdLang, $langTables);
@@ -554,12 +553,11 @@ class HotelReservationSystem extends Module
$this->installTab('AdminHotelReservationSystemManagement', 'Hotel Reservation System');
$this->installTab('AdminAddHotel', 'Manage Hotel', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminHotelRoomsBooking', 'Book Now', 'AdminHotelReservationSystemManagement');
- $this->installTab('AdminHotelFeatures', 'Manage Hotel Features', 'AdminHotelReservationSystemManagement');
+ $this->installTab('AdminHotelFeatures', 'Manage Amenities', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminOrderRefundRules', 'Manage Order Refund Rules', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminOrderRefundRequests', 'Manage Order Refund Requests', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminHotelConfigurationSetting', 'General Settings', 'AdminHotelReservationSystemManagement');
- $this->installTab('AdminHotelBedTypes', 'Bed Types', 'AdminCatalog');
// Controllers without tabs
$this->installTab('AdminHotelGeneralSettings', 'Hotel General Configuration', 'AdminHotelConfigurationSetting', false);
$this->installTab('AdminHotelFeaturePricesSettings', 'Advanced Price Rules', 'AdminHotelConfigurationSetting', false);
@@ -605,11 +603,11 @@ class HotelReservationSystem extends Module
$objHtlHelper = new HotelHelper();
if (!parent::install()
|| !$objModuleDb->createTables()
+ || !$objModuleDb->migrateToDynamicRoomFeatureSchema()
|| !$this->registerModuleHooks()
|| !$this->callInstallTab()
|| !$objHtlHelper->insertDefaultHotelEntries()
- || !$objHtlHelper->createHotelRoomDefaultFeatures()
- || !$objHtlHelper->createHotelDefaultBedTypes()
+ || !$objHtlHelper->seedDefaultDynamicRoomFeatures()
|| !$objHtlHelper->insertHotelCommonFeatures()
) {
return false;
diff --git a/modules/qlocleaner/qlocleaner.php b/modules/qlocleaner/qlocleaner.php
index 8b532ef5a..15b60720a 100644
--- a/modules/qlocleaner/qlocleaner.php
+++ b/modules/qlocleaner/qlocleaner.php
@@ -727,9 +727,8 @@ class QloCleaner extends Module
array('htl_room_type_service_product', 'id_element', 'product', 'id_product'),
array('htl_room_type_service_product_price', 'id_product', 'product', 'id_product'),
array('htl_room_type_service_product_price', 'id_element', 'product', 'id_product'),
- array('htl_bed_type_lang', 'id_lang', 'lang', 'id_lang'),
- array('htl_room_type_bed_type', 'id_product', 'product', 'id_product'),
- array('htl_room_type_bed_type', 'id_bed_type', 'htl_bed_type', 'id_bed_type'),
+ array('htl_room_type_features', 'id_product', 'product', 'id_product'),
+ array('htl_room_type_features', 'feature_id', 'htl_features', 'id'),
)
);
@@ -831,9 +830,7 @@ class QloCleaner extends Module
'htl_room_type_global_demand',
'htl_room_type_service_product',
'htl_room_type_service_product_price',
- 'htl_bed_type',
- 'htl_bed_type_lang',
- 'htl_room_type_bed_type',
+ 'htl_room_type_features',
)
);
}
diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl
index 9492fbc86..562206408 100644
--- a/themes/hotel-reservation-theme/product.tpl
+++ b/themes/hotel-reservation-theme/product.tpl
@@ -262,34 +262,16 @@
{/if}
{/block}
- {block name='product_info_tab_room_bed_type'}
- {if isset($selected_bed_types) && $selected_bed_types && isset($bed_types_info) && $bed_types_info}
-
- {/if}
- {/block}
{block name='product_info_tab_room_features'}
- {if isset($features) && $features}
+ {if isset($room_dynamic_features) && $room_dynamic_features}