diff --git a/admin/themes/default/template/controllers/normal_products/features.tpl b/admin/themes/default/template/controllers/normal_products/features.tpl index dc02a8aa8..04eb139ef 100644 --- a/admin/themes/default/template/controllers/normal_products/features.tpl +++ b/admin/themes/default/template/controllers/normal_products/features.tpl @@ -23,7 +23,7 @@ {if isset($product->id)}
-

{l s='Assign features to this room type'}

+

{l s='Features'}

{l s='You can specify a value for each relevant feature regarding this room type. Empty fields will not be displayed.'}
diff --git a/admin/themes/default/template/controllers/products/amenities.tpl b/admin/themes/default/template/controllers/products/amenities.tpl new file mode 100644 index 000000000..64b110605 --- /dev/null +++ b/admin/themes/default/template/controllers/products/amenities.tpl @@ -0,0 +1,61 @@ +{* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if isset($product->id)} +
+ +

{l s='Amenities'}

+ +
+ {l s='Select the amenities available for this room type using the tree below.'} + + {l s='Manage amenities'} + +
+ + {if isset($room_type_amenities_tree) && $room_type_amenities_tree} +
+ +
+ {$room_type_amenities_tree} +
+
+ {else} +
+ {l s='No amenities have been defined yet.'} +
+ {/if} + + +
+{/if} diff --git a/admin/themes/default/template/controllers/products/features.tpl b/admin/themes/default/template/controllers/products/features.tpl index 494a0208a..702e38864 100644 --- a/admin/themes/default/template/controllers/products/features.tpl +++ b/admin/themes/default/template/controllers/products/features.tpl @@ -29,42 +29,25 @@

{l s='Assign features to this room type'}

- {l s='Select one value for each room feature. Unselected features will not be displayed for this room type.'} + {l s='Select one or more values for each room feature using the tree below.'}
-
- {foreach from=$available_features item=available_feature} -
-
- {$available_feature.name|escape:'html':'UTF-8'} -
-
- {if isset($available_feature.featureValues) && $available_feature.featureValues} -
- -
- {foreach from=$available_feature.featureValues item=value} -
- -
- {/foreach} - {else} -

{l s='No values available for this feature.'}

- {/if} -
+ {if isset($room_type_features_tree) && $room_type_features_tree} +
+ +
+ {$room_type_features_tree}
- {foreachelse} -
- {l s='No features have been defined'} -
- {/foreach} -
+
+ {else} +
+ {l s='No features have been defined'} +
+ {/if} {l s='Add a new feature'} diff --git a/admin/themes/default/template/controllers/products/informations.tpl b/admin/themes/default/template/controllers/products/informations.tpl index 045bca93e..788e99d9b 100644 --- a/admin/themes/default/template/controllers/products/informations.tpl +++ b/admin/themes/default/template/controllers/products/informations.tpl @@ -465,47 +465,6 @@
{/if} -
- -
- {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} -
-
- -
-
- {/foreach} -
- {/if} -
- {/foreach} -
-
- {else} -
- {l s='No amenities have been defined yet.'} -
- {/if} -
-
- {*
'.$obj->name[$this->context->employee->id_lang].''; + $bread_extended[] = ''.$this->getTranslatedFieldValue( + is_array($obj->name) ? $obj->name : array(), + $this->context->employee->id_lang, + $this->l('Feature') + ).''; } if (Validate::isLoadedObject($obj = new FeatureValue((int)Tools::getValue('id_feature_value')))) { - $bread_extended[] = sprintf($this->l('Edit: %s'), $obj->value[$this->context->employee->id_lang]); + $bread_extended[] = sprintf( + $this->l('Edit: %s'), + $this->getTranslatedFieldValue( + is_array($obj->value) ? $obj->value : array(), + $this->context->employee->id_lang, + $this->l('Value') + ) + ); } } else { $bread_extended[] = $this->l('Edit Value'); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 52e369f5b..0ee742f96 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -107,6 +107,7 @@ class AdminProductsControllerCore extends AdminController 'Images' => $this->l('Images'), 'ServiceProduct' => $this->l('Service Products'), // 'Associations' => $this->l('Associations'), + 'Amenities' => $this->l('Amenities'), 'Features' => $this->l('Features'), 'Configuration' => $this->l('Rooms'), 'Occupancy' => $this->l('Occupancy'), @@ -121,9 +122,10 @@ class AdminProductsControllerCore extends AdminController 'Seo' => 2, // 'Associations' => 3, 'Images' => 4, - 'Features' => 5, - 'Configuration' => 6, - 'Occupancy' => 7, + 'Amenities' => 5, + 'Features' => 6, + 'Configuration' => 7, + 'Occupancy' => 8, 'ServiceProduct' => 9, 'LengthOfStay' => 10, 'AdditionalFacilities' => 11, @@ -1156,20 +1158,29 @@ class AdminProductsControllerCore extends AdminController { $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); - } - } + $featureValues = Tools::getValue('feature_values', array()); + if (!is_array($featureValues) || empty($featureValues)) { + return true; + } + + foreach ($featureValues as $idFeature => $selectedValues) { + $idFeature = (int) $idFeature; + if (!$idFeature) { + continue; + } + + if (!is_array($selectedValues)) { + $selectedValues = array($selectedValues); + } + + $selectedValues = array_values(array_unique(array_map('intval', $selectedValues))); + foreach ($selectedValues as $idFeatureValue) { + if ($idFeatureValue) { + Db::getInstance()->insert('feature_product', array( + 'id_feature' => (int) $idFeature, + 'id_product' => (int) $product->id, + 'id_feature_value' => (int) $idFeatureValue + )); } } } @@ -1255,7 +1266,31 @@ class AdminProductsControllerCore extends AdminController $this->context->language->id ); - return $roomTypeAmenities ? $roomTypeAmenities : array(); + if (!$roomTypeAmenities) { + return array(); + } + + foreach ($roomTypeAmenities as $idAmenityGroup => &$amenityGroup) { + $amenityGroup['value'] = (int) $idAmenityGroup; + $amenityGroup['input_name'] = 'room_type_amenity_parents'; + + $selectedAmenities = 0; + if (!empty($amenityGroup['children'])) { + foreach ($amenityGroup['children'] as &$amenity) { + $amenity['value'] = (int) $amenity['id']; + $amenity['input_name'] = 'room_type_amenities'; + if (!empty($amenity['selected'])) { + ++$selectedAmenities; + } + } + + if ($selectedAmenities === count($amenityGroup['children'])) { + $amenityGroup['selected'] = true; + } + } + } + + return $roomTypeAmenities; } /** @@ -1273,20 +1308,31 @@ class AdminProductsControllerCore extends AdminController ); $selectedFeatureValues = array(); foreach ($product->getFeatures() as $productFeature) { - $selectedFeatureValues[(int) $productFeature['id_feature']] = (int) $productFeature['id_feature_value']; + $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( + $featureValues = FeatureValue::getFeatureValuesWithLang( $this->context->language->id, (int) $feature['id_feature'] ); + $feature['value'] = (int) $feature['id_feature']; + $feature['input_name'] = 'feature_value_parents'; + $feature['children'] = array(); + $selectedValues = isset($selectedFeatureValues[(int) $feature['id_feature']]) + ? $selectedFeatureValues[(int) $feature['id_feature']] + : array(); - foreach ($feature['featureValues'] as &$featureValue) { - $featureValue['selected'] = ((int) $feature['current_item'] === (int) $featureValue['id_feature_value']); + foreach ($featureValues as $featureValue) { + $featureValue['name'] = $featureValue['value']; + $featureValue['value'] = (int) $featureValue['id_feature_value']; + $featureValue['input_name'] = 'feature_values['.(int) $feature['id_feature'].']'; + $featureValue['selected'] = in_array((int) $featureValue['id_feature_value'], $selectedValues); + $feature['children'][] = $featureValue; + } + + if ($feature['children'] && count($selectedValues) === count($feature['children'])) { + $feature['selected'] = true; } } @@ -2052,7 +2098,7 @@ class AdminProductsControllerCore extends AdminController // } $this->assignRoomType($this->object); - if ($this->isTabSubmitted('Informations') && !$this->saveRoomTypeAmenities($this->object->id)) { + if ($this->isTabSubmitted('Amenities') && !$this->saveRoomTypeAmenities($this->object->id)) { $this->errors[] = Tools::displayError('An error occurred while saving room type amenities.'); return false; } @@ -2237,7 +2283,7 @@ class AdminProductsControllerCore extends AdminController } if ($object->update()) { - if ($this->isTabSubmitted('Informations') && !$this->saveRoomTypeAmenities($object->id)) { + if ($this->isTabSubmitted('Amenities') && !$this->saveRoomTypeAmenities($object->id)) { $this->errors[] = Tools::displayError('An error occurred while saving room type amenities.'); return false; } @@ -4665,15 +4711,6 @@ class AdminProductsControllerCore extends AdminController $data->assign('htl_full_info', $hotelFullInfo); } - $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(); } @@ -4916,7 +4953,15 @@ class AdminProductsControllerCore extends AdminController if ($obj->id) { if ($this->product_exists_in_shop) { $features = $this->getRoomTypeFeatureTree($obj); - $data->assign('available_features', $features); + if ($features) { + $tree = new HelperTree('room-type-features-tree', $features); + $tree->setShowCollapseExpandButton(true) + ->setUseCheckBox(true) + ->setAutoSelectChildren(true) + ->setUseBulkActions(true) + ->setHeaderTemplate('tree_header_room.tpl'); + $data->assign('room_type_features_tree', $tree->render()); + } $data->assign('product', $obj); $data->assign('link', $this->context->link); $data->assign('default_form_language', $this->default_form_language); @@ -4930,6 +4975,48 @@ class AdminProductsControllerCore extends AdminController $this->tpl_form_vars['custom_form'] = $data->fetch(); } + /** + * Prepare the amenities form tab for a room type. + * + * @param Product $obj + * + * @throws Exception + * @throws SmartyException + */ + public function initFormAmenities($obj) + { + if (!$this->default_form_language) { + $this->getLanguages(); + } + + $data = $this->createTemplate($this->tpl_form); + $data->assign('default_form_language', $this->default_form_language); + $data->assign('languages', $this->_languages); + $data->assign('link', $this->context->link); + $data->assign('product', $obj); + + if ($obj->id) { + if ($this->product_exists_in_shop) { + $roomTypeAmenities = $this->getRoomTypeAmenitiesTree((int) $obj->id); + if ($roomTypeAmenities) { + $tree = new HelperTree('room-type-amenities-tree', $roomTypeAmenities); + $tree->setShowCollapseExpandButton(true) + ->setUseCheckBox(true) + ->setAutoSelectChildren(true) + ->setUseBulkActions(true) + ->setHeaderTemplate('tree_header_room.tpl'); + $data->assign('room_type_amenities_tree', $tree->render()); + } + } else { + $this->displayWarning($this->l('You must save the room type in this shop before adding amenities.')); + } + } else { + $this->displayWarning($this->l('You must save this room type before adding amenities.')); + } + + $this->tpl_form_vars['custom_form'] = $data->fetch(); + } + public function getModalDuplicateOptions() { $idsHotel = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 7550fbcad..9a70440c5 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -830,7 +830,7 @@ CREATE TABLE `PREFIX_feature_product` ( `id_feature` int(10) unsigned NOT NULL, `id_product` int(10) unsigned NOT NULL, `id_feature_value` int(10) unsigned NOT NULL, - PRIMARY KEY (`id_feature`,`id_product`), + PRIMARY KEY (`id_feature`,`id_product`,`id_feature_value`), KEY `id_feature_value` (`id_feature_value`), KEY `id_product` (`id_product`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index a42075115..86260185f 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -558,6 +558,20 @@ class HotelReservationSystemDb } } } + + // Drop the restrictive primary key and add a multi-select capable primary key. + try { + Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'feature_product` DROP PRIMARY KEY'); + } catch (Exception $e) { + } + + try { + Db::getInstance()->execute( + 'ALTER TABLE `'._DB_PREFIX_.'feature_product` ADD PRIMARY KEY (`id_feature`, `id_product`, `id_feature_value`)' + ); + } catch (Exception $e) { + } + return true; }