Fixed: Function naming, idLang not optional, Wrong class for features query, and added Return type declarations
Co-authored-by: Name <sumit201@webkul.in>
This commit is contained in:
@@ -1191,7 +1191,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
protected function getRoomTypeAmenitiesTree($idProduct)
|
||||
{
|
||||
$selectedAmenityRows = array();
|
||||
foreach (HotelRoomTypeAmenities::getAmenityIdsByProduct($idProduct) as $selectedAmenityId) {
|
||||
foreach (HotelRoomTypeAmenities::getAmenityIds($idProduct) as $selectedAmenityId) {
|
||||
$selectedAmenityRows[] = array('amenity_id' => $selectedAmenityId);
|
||||
}
|
||||
|
||||
@@ -2038,7 +2038,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
if (!is_array($selectedAmenities)) {
|
||||
$selectedAmenities = array($selectedAmenities);
|
||||
}
|
||||
if (!(new HotelRoomTypeAmenities())->assignAmenitiesToProduct((int)$this->object->id, $selectedAmenities)) {
|
||||
if (!(new HotelRoomTypeAmenities())->saveRoomTypeAmenities((int)$this->object->id, $selectedAmenities)) {
|
||||
$this->errors[] = Tools::displayError('An error occurred while saving room type amenities.');
|
||||
return false;
|
||||
}
|
||||
@@ -2294,7 +2294,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
if (!is_array($selectedAmenities)) {
|
||||
$selectedAmenities = array($selectedAmenities);
|
||||
}
|
||||
if (!(new HotelRoomTypeAmenities())->assignAmenitiesToProduct((int)$object->id, $selectedAmenities)) {
|
||||
if (!(new HotelRoomTypeAmenities())->saveRoomTypeAmenities((int)$object->id, $selectedAmenities)) {
|
||||
$this->errors[] = Tools::displayError('An error occurred while saving room type amenities.');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -409,9 +409,9 @@ class ProductControllerCore extends FrontController
|
||||
}
|
||||
}
|
||||
|
||||
$roomFeatures = HotelRoomType::getFrontFeatures($this->product->id, $this->context->language->id);
|
||||
$roomAmenities = HotelRoomTypeAmenities::getFrontAmenities($this->product->id, $this->context->language->id);
|
||||
$hotelAmenities = HotelBranchAmenities::getFrontAmenities($hotel_id, $this->context->language->id);
|
||||
$roomFeatures = $this->product->getFrontFeatures($this->context->language->id);
|
||||
$roomAmenities = HotelRoomTypeAmenities::getAmenities($this->product->id, $this->context->language->id);
|
||||
$hotelAmenities = HotelBranchAmenities::getAmenities($hotel_id, $this->context->language->id);
|
||||
|
||||
$this->context->smarty->assign(
|
||||
array(
|
||||
|
||||
@@ -61,8 +61,6 @@ class HotelAmenities extends ObjectModel
|
||||
public function delete()
|
||||
{
|
||||
if ($id = $this->id) {
|
||||
Db::getInstance()->delete('htl_branch_amenity', '`amenity_id` = '.(int)$id);
|
||||
Db::getInstance()->delete('htl_room_type_amenity', '`amenity_id` = '.(int)$id);
|
||||
$imgFile = dirname(__FILE__).'/../views/img/hotel_amenities/'.(int)$id.'.jpg';
|
||||
if (file_exists($imgFile)) {
|
||||
unlink($imgFile);
|
||||
@@ -215,17 +213,17 @@ class HotelAmenities extends ObjectModel
|
||||
* @param int $deleteId
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteHotelAmenities($deleteId)
|
||||
public function deleteCategory($idCategory)
|
||||
{
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT `id_htl_amenity` FROM `'._DB_PREFIX_.'htl_amenity`
|
||||
WHERE `parent_amenity_id` = '.(int)$deleteId.' OR `id_htl_amenity` = '.(int)$deleteId
|
||||
WHERE `parent_amenity_id` = '.(int)$idCategory.' OR `id_htl_amenity` = '.(int)$idCategory
|
||||
);
|
||||
|
||||
if ($rows) {
|
||||
foreach ($rows as $row) {
|
||||
$obj = new HotelAmenities((int)$row['id_htl_amenity']);
|
||||
$obj->delete();
|
||||
$objHotelAmenities = new HotelAmenities((int)$row['id_htl_amenity']);
|
||||
$objHotelAmenities->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +235,7 @@ class HotelAmenities extends ObjectModel
|
||||
* @param int $idLang
|
||||
* @return array|false
|
||||
*/
|
||||
public function searchByName($query, $idLang = false)
|
||||
public function searchByName($query, $idLang = 0)
|
||||
{
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
|
||||
@@ -1701,9 +1701,10 @@ class HotelBookingDetail extends ObjectModel
|
||||
if (!empty($bookingData)) {
|
||||
foreach ($bookingData['rm_data'] as $key => $value) {
|
||||
// featured amenities for display in room type list
|
||||
$product_feature = HotelRoomTypeAmenities::getFeaturedAmenities(
|
||||
$product_feature = HotelRoomTypeAmenities::getAmenities(
|
||||
$value['id_product'],
|
||||
$context->language->id
|
||||
$context->language->id,
|
||||
true
|
||||
);
|
||||
// PS core features used by the amenities filter block
|
||||
$prod_amen = array();
|
||||
|
||||
@@ -42,40 +42,15 @@ class HotelBranchAmenities extends ObjectModel
|
||||
|
||||
/**
|
||||
* @param int $idHotel
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteBranchAmenitiesByHotelId($idHotel)
|
||||
{
|
||||
return Db::getInstance()->delete('htl_branch_amenity', '`id_hotel` = '.(int)$idHotel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $idHotel
|
||||
* @param array $amenities array of amenity IDs
|
||||
* @return bool
|
||||
*/
|
||||
public function assignAmenitiesToHotel($idHotel, $amenities)
|
||||
{
|
||||
if ($amenities) {
|
||||
foreach ($amenities as $amenityId) {
|
||||
$objHotelAmenities = new HotelBranchAmenities();
|
||||
$objHotelAmenities->id_hotel = (int)$idHotel;
|
||||
$objHotelAmenities->amenity_id = (int)$amenityId;
|
||||
$objHotelAmenities->save();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return active child amenities assigned to a hotel, formatted for front-end display.
|
||||
*
|
||||
* @param int $idHotel
|
||||
* @param int $idLang
|
||||
* @param int $idLang defaults to current context language
|
||||
* @return array
|
||||
*/
|
||||
public static function getFrontAmenities($idHotel, $idLang)
|
||||
public static function getAmenities($idHotel, $idLang = 0): array
|
||||
{
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
}
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT ha.`id_htl_amenity` AS `id`, ha.`logo_type`, ha.`logo`, hal.`name`
|
||||
FROM `'._DB_PREFIX_.'htl_branch_amenity` hba
|
||||
@@ -89,4 +64,25 @@ class HotelBranchAmenities extends ObjectModel
|
||||
ORDER BY ha.`position` ASC, hal.`name` ASC'
|
||||
) ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete existing assignments then save new ones for a hotel.
|
||||
*
|
||||
* @param int $idHotel
|
||||
* @param array $amenityIds
|
||||
* @return bool
|
||||
*/
|
||||
public function saveBranchAmenities($idHotel, array $amenityIds): bool
|
||||
{
|
||||
Db::getInstance()->delete('htl_branch_amenity', '`id_hotel` = '.(int)$idHotel);
|
||||
|
||||
foreach ($amenityIds as $amenityId) {
|
||||
$obj = new self();
|
||||
$obj->id_hotel = (int)$idHotel;
|
||||
$obj->amenity_id = (int)$amenityId;
|
||||
$obj->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +795,7 @@ class HotelBranchInformation extends ObjectModel
|
||||
}
|
||||
$objHotelAmenities = new HotelBranchAmenities();
|
||||
$objHotelImage = new HotelImage();
|
||||
if (!$objHotelAmenities->deleteBranchAmenitiesByHotelId($idHotel)) {
|
||||
if (!$objHotelAmenities->saveBranchAmenities($idHotel, array())) {
|
||||
$contextController->errors[] = $this->moduleInstance->l(
|
||||
'Some error has occurred while deleting hotel amenity data.',
|
||||
'HotelBranchInformation'
|
||||
|
||||
@@ -91,26 +91,6 @@ class HotelReservationSystemDb
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_amenity` (
|
||||
`id_htl_branch_amenity` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_hotel` int(10) unsigned NOT NULL,
|
||||
`amenity_id` int(10) unsigned NOT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_htl_branch_amenity`)
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_amenity` (
|
||||
`id_htl_room_type_amenity` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_product` int(10) unsigned NOT NULL,
|
||||
`amenity_id` int(10) unsigned NOT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_htl_room_type_amenity`),
|
||||
KEY `id_product` (`id_product`),
|
||||
KEY `amenity_id` (`amenity_id`)
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_amenity` (
|
||||
`id_htl_amenity` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`parent_amenity_id` int(10) unsigned NOT NULL,
|
||||
@@ -131,6 +111,29 @@ class HotelReservationSystemDb
|
||||
PRIMARY KEY (`id_htl_amenity`, `id_lang`)
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_amenity` (
|
||||
`id_htl_branch_amenity` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_hotel` int(10) unsigned NOT NULL,
|
||||
`amenity_id` int(10) unsigned NOT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_htl_branch_amenity`),
|
||||
CONSTRAINT `fk_htl_branch_amenity_amenity` FOREIGN KEY (`amenity_id`)
|
||||
REFERENCES `"._DB_PREFIX_."htl_amenity` (`id_htl_amenity`) ON DELETE CASCADE
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_amenity` (
|
||||
`id_htl_room_type_amenity` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_product` int(10) unsigned NOT NULL,
|
||||
`amenity_id` int(10) unsigned NOT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_htl_room_type_amenity`),
|
||||
KEY `id_product` (`id_product`),
|
||||
CONSTRAINT `fk_htl_room_type_amenity_amenity` FOREIGN KEY (`amenity_id`)
|
||||
REFERENCES `"._DB_PREFIX_."htl_amenity` (`id_htl_amenity`) ON DELETE CASCADE
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_cart_booking_data` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id_cart` int(11) NOT NULL,
|
||||
|
||||
@@ -456,41 +456,4 @@ class HotelRoomType extends ObjectModel
|
||||
return parent::validateFields($die, $error_return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PS core features for a room type product, grouped by feature name for front-end display.
|
||||
*
|
||||
* @param int $idProduct
|
||||
* @param int $idLang
|
||||
* @return array Each element: array('name' => string, 'values' => string[])
|
||||
*/
|
||||
public static function getFrontFeatures($idProduct, $idLang)
|
||||
{
|
||||
$rows = 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)$idLang.')
|
||||
INNER JOIN `'._DB_PREFIX_.'feature_value_lang` fvl
|
||||
ON (fvl.`id_feature_value` = fp.`id_feature_value` AND fvl.`id_lang` = '.(int)$idLang.')
|
||||
WHERE fp.`id_product` = '.(int)$idProduct.'
|
||||
ORDER BY f.`position` ASC, fl.`name` ASC'
|
||||
);
|
||||
|
||||
if (!$rows) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$grouped = array();
|
||||
foreach ($rows as $row) {
|
||||
$name = $row['feature_name'];
|
||||
if (!isset($grouped[$name])) {
|
||||
$grouped[$name] = array('name' => $name, 'values' => array());
|
||||
}
|
||||
$grouped[$name]['values'][] = $row['feature_value'];
|
||||
}
|
||||
|
||||
return array_values($grouped);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ class HotelRoomTypeAmenities extends ObjectModel
|
||||
|
||||
/**
|
||||
* @param int $idProduct
|
||||
* @return int[]
|
||||
* @return array
|
||||
*/
|
||||
public static function getAmenityIdsByProduct($idProduct)
|
||||
public static function getAmenityIds($idProduct): array
|
||||
{
|
||||
$rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT `amenity_id`
|
||||
@@ -56,28 +56,43 @@ class HotelRoomTypeAmenities extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all amenity assignments for a room type product.
|
||||
*
|
||||
* @param int $idProduct
|
||||
* @return bool
|
||||
* @param int $idProduct
|
||||
* @param int $idLang defaults to current context language
|
||||
* @param bool $featuredOnly true = is_featured=1 only; false = all active child amenities
|
||||
* @return array
|
||||
*/
|
||||
public function deleteByProductId($idProduct)
|
||||
public static function getAmenities($idProduct, $idLang = 0, $featuredOnly = false): array
|
||||
{
|
||||
return Db::getInstance()->delete('htl_room_type_amenity', '`id_product` = '.(int)$idProduct);
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
}
|
||||
|
||||
$filter = $featuredOnly ? 'AND ha.`is_featured` = 1' : 'AND ha.`parent_amenity_id` > 0';
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT ha.`id_htl_amenity` AS `id`, ha.`logo_type`, ha.`logo`, hal.`name`
|
||||
FROM `'._DB_PREFIX_.'htl_room_type_amenity` hrta
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_amenity` ha
|
||||
ON (ha.`id_htl_amenity` = hrta.`amenity_id`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_amenity_lang` hal
|
||||
ON (hal.`id_htl_amenity` = hrta.`amenity_id` AND hal.`id_lang` = '.(int)$idLang.')
|
||||
WHERE hrta.`id_product` = '.(int)$idProduct.'
|
||||
AND ha.`active` = 1
|
||||
'.$filter.'
|
||||
ORDER BY ha.`position` ASC, hal.`name` ASC'
|
||||
) ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all amenity assignments for a room type product.
|
||||
* Delete existing assignments then save new ones for a room type.
|
||||
*
|
||||
* @param int $idProduct
|
||||
* @param int[] $amenityIds
|
||||
* @param array $amenityIds
|
||||
* @return bool
|
||||
*/
|
||||
public function assignAmenitiesToProduct($idProduct, array $amenityIds)
|
||||
public function saveRoomTypeAmenities($idProduct, array $amenityIds): bool
|
||||
{
|
||||
if (!$this->deleteByProductId($idProduct)) {
|
||||
return false;
|
||||
}
|
||||
Db::getInstance()->delete('htl_room_type_amenity', '`id_product` = '.(int)$idProduct);
|
||||
|
||||
foreach (array_unique(array_filter(array_map('intval', $amenityIds))) as $amenityId) {
|
||||
$obj = new self();
|
||||
@@ -90,50 +105,4 @@ class HotelRoomTypeAmenities extends ObjectModel
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return featured amenities assigned to a room type, for room type list display.
|
||||
*
|
||||
* @param int $idProduct
|
||||
* @param int $idLang
|
||||
* @return array
|
||||
*/
|
||||
public static function getFeaturedAmenities($idProduct, $idLang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT ha.`id_htl_amenity` AS `id`, ha.`logo_type`, ha.`logo`, hal.`name`
|
||||
FROM `'._DB_PREFIX_.'htl_room_type_amenity` hrta
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_amenity` ha
|
||||
ON (ha.`id_htl_amenity` = hrta.`amenity_id`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_amenity_lang` hal
|
||||
ON (hal.`id_htl_amenity` = hrta.`amenity_id` AND hal.`id_lang` = '.(int)$idLang.')
|
||||
WHERE hrta.`id_product` = '.(int)$idProduct.'
|
||||
AND ha.`is_featured` = 1
|
||||
AND ha.`active` = 1
|
||||
ORDER BY ha.`position` ASC'
|
||||
) ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return active child amenities assigned to a room type, formatted for front-end display.
|
||||
*
|
||||
* @param int $idProduct
|
||||
* @param int $idLang
|
||||
* @return array
|
||||
*/
|
||||
public static function getFrontAmenities($idProduct, $idLang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT ha.`id_htl_amenity` AS `id`, ha.`logo_type`, ha.`logo`, hal.`name`
|
||||
FROM `'._DB_PREFIX_.'htl_room_type_amenity` hrta
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_amenity` ha
|
||||
ON (ha.`id_htl_amenity` = hrta.`amenity_id`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_amenity_lang` hal
|
||||
ON (hal.`id_htl_amenity` = hrta.`amenity_id` AND hal.`id_lang` = '.(int)$idLang.')
|
||||
WHERE hrta.`id_product` = '.(int)$idProduct.'
|
||||
AND ha.`active` = 1
|
||||
AND ha.`parent_amenity_id` > 0
|
||||
ORDER BY ha.`position` ASC, hal.`name` ASC'
|
||||
) ?: array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,8 +803,7 @@ class AdminAddHotelController extends ModuleAdminController
|
||||
$objHotelOrderRestrictDate->save();
|
||||
|
||||
$objHotelAmenities = new HotelBranchAmenities();
|
||||
$objHotelAmenities->deleteBranchAmenitiesByHotelId($idHotel);
|
||||
if (!$objHotelAmenities->assignAmenitiesToHotel($idHotel, $hotelAmenities)) {
|
||||
if (!$objHotelAmenities->saveBranchAmenities($idHotel, $hotelAmenities)) {
|
||||
$this->errors[] = $this->l('Some problem occurred while assigning amenities to the hotel.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
|
||||
if ($this->display == 'view') {
|
||||
$this->page_header_toolbar_btn['add_category'] = array(
|
||||
'href' => self::$currentIndex.'&addhtl_amenity&token='.$this->token,
|
||||
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
|
||||
'desc' => $this->l('Add new Amenity Category'),
|
||||
'imgclass' => 'new',
|
||||
);
|
||||
@@ -54,8 +54,8 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
if (Tools::isSubmit('addhtl_amenity') || Tools::isSubmit('updatehtl_amenity')
|
||||
|| Tools::isSubmit('addhtl_amenity_item') || Tools::isSubmit('updatehtl_amenity_item')
|
||||
if (Tools::isSubmit('add'.$this->table) || Tools::isSubmit('update'.$this->table)
|
||||
|| Tools::isSubmit('add'.$this->table.'_item') || Tools::isSubmit('update'.$this->table.'_item')
|
||||
) {
|
||||
$this->display = 'edit';
|
||||
}
|
||||
@@ -81,9 +81,9 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$obj = new HotelAmenities();
|
||||
$objHotelAmenities = new HotelAmenities();
|
||||
$this->context->smarty->assign(array(
|
||||
'amenities_tree' => $obj->getAllAmenitiesTree(),
|
||||
'amenities_tree' => $objHotelAmenities->getAllAmenitiesTree(),
|
||||
'img_base_url' => $this->module->getPathUri().self::IMG_DIR,
|
||||
'current_index' => self::$currentIndex,
|
||||
'token' => $this->token,
|
||||
@@ -99,23 +99,23 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
$adminLink = Context::getContext()->link->getAdminLink('AdminHotelAmenities');
|
||||
|
||||
if (Tools::isSubmit('addhtl_amenity_item') || Tools::isSubmit('updatehtl_amenity_item')) {
|
||||
if (Tools::isSubmit('add'.$this->table.'_item') || Tools::isSubmit('update'.$this->table.'_item')) {
|
||||
$idAmenity = (int)Tools::getValue('id');
|
||||
$idCategory = (int)Tools::getValue('id_category');
|
||||
$amenity = array();
|
||||
|
||||
if ($idAmenity) {
|
||||
$obj = new HotelAmenities($idAmenity);
|
||||
if (Validate::isLoadedObject($obj)) {
|
||||
$idCategory = (int)$obj->parent_amenity_id;
|
||||
$objHotelAmenities = new HotelAmenities($idAmenity);
|
||||
if (Validate::isLoadedObject($objHotelAmenities)) {
|
||||
$idCategory = (int)$objHotelAmenities->parent_amenity_id;
|
||||
$amenity = array(
|
||||
'id' => $obj->id,
|
||||
'id' => $objHotelAmenities->id,
|
||||
'parent_amenity_id' => $idCategory,
|
||||
'active' => (int)$obj->active,
|
||||
'is_featured' => (int)$obj->is_featured,
|
||||
'logo_type' => $obj->logo_type,
|
||||
'logo' => $obj->logo,
|
||||
'name' => is_array($obj->name) ? $obj->name : array(),
|
||||
'active' => (int)$objHotelAmenities->active,
|
||||
'is_featured' => (int)$objHotelAmenities->is_featured,
|
||||
'logo_type' => $objHotelAmenities->logo_type,
|
||||
'logo' => $objHotelAmenities->logo,
|
||||
'name' => is_array($objHotelAmenities->name) ? $objHotelAmenities->name : array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -146,12 +146,12 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
$category = array();
|
||||
|
||||
if ($idCategory) {
|
||||
$obj = new HotelAmenities($idCategory);
|
||||
if (Validate::isLoadedObject($obj)) {
|
||||
$objHotelAmenities = new HotelAmenities($idCategory);
|
||||
if (Validate::isLoadedObject($objHotelAmenities)) {
|
||||
$category = array(
|
||||
'id' => $obj->id,
|
||||
'position' => $obj->position,
|
||||
'name' => is_array($obj->name) ? $obj->name : array(),
|
||||
'id' => $objHotelAmenities->id,
|
||||
'position' => $objHotelAmenities->position,
|
||||
'name' => is_array($objHotelAmenities->name) ? $objHotelAmenities->name : array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -194,16 +194,16 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
return;
|
||||
}
|
||||
|
||||
$obj = $idCategory ? new HotelAmenities($idCategory) : new HotelAmenities();
|
||||
$objHotelAmenities = $idCategory ? new HotelAmenities($idCategory) : new HotelAmenities();
|
||||
foreach ($languages as $lang) {
|
||||
$val = trim(Tools::getValue('cat_name_'.$lang['id_lang']));
|
||||
$obj->name[$lang['id_lang']] = $val ?: $nameDefault;
|
||||
$objHotelAmenities->name[$lang['id_lang']] = $val ?: $nameDefault;
|
||||
}
|
||||
$obj->parent_amenity_id = 0;
|
||||
$obj->position = $pos;
|
||||
$obj->active = 1;
|
||||
$objHotelAmenities->parent_amenity_id = 0;
|
||||
$objHotelAmenities->position = $pos;
|
||||
$objHotelAmenities->active = 1;
|
||||
|
||||
if (!$obj->save()) {
|
||||
if (!$objHotelAmenities->save()) {
|
||||
$this->errors[] = $this->l('Error saving category.');
|
||||
$this->display = 'edit';
|
||||
return;
|
||||
@@ -254,25 +254,25 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
return;
|
||||
}
|
||||
|
||||
$obj = $idAmenity ? new HotelAmenities($idAmenity) : new HotelAmenities();
|
||||
$objHotelAmenities = $idAmenity ? new HotelAmenities($idAmenity) : new HotelAmenities();
|
||||
foreach ($languages as $lang) {
|
||||
$val = trim(Tools::getValue('amenity_name_'.$lang['id_lang']));
|
||||
$obj->name[$lang['id_lang']] = $val ?: $nameDefault;
|
||||
$objHotelAmenities->name[$lang['id_lang']] = $val ?: $nameDefault;
|
||||
}
|
||||
$obj->parent_amenity_id = $idCategory;
|
||||
$obj->active = $active;
|
||||
$obj->is_featured = $isFeatured;
|
||||
$obj->logo_type = ($logoType === 'icon') ? 'icon' : 'image';
|
||||
$obj->logo = ($logoType === 'icon') ? $logoValue : $obj->logo;
|
||||
$objHotelAmenities->parent_amenity_id = $idCategory;
|
||||
$objHotelAmenities->active = $active;
|
||||
$objHotelAmenities->is_featured = $isFeatured;
|
||||
$objHotelAmenities->logo_type = ($logoType === 'icon') ? 'icon' : 'image';
|
||||
$objHotelAmenities->logo = ($logoType === 'icon') ? $logoValue : $objHotelAmenities->logo;
|
||||
|
||||
if (!$obj->save()) {
|
||||
if (!$objHotelAmenities->save()) {
|
||||
$this->errors[] = $this->l('Error saving amenity.');
|
||||
$this->display = 'edit';
|
||||
return;
|
||||
}
|
||||
|
||||
if ($logoType === 'icon') {
|
||||
$imgFile = $this->module->getLocalPath().self::IMG_DIR.$obj->id.'.jpg';
|
||||
$imgFile = $this->module->getLocalPath().self::IMG_DIR.$objHotelAmenities->id.'.jpg';
|
||||
if (file_exists($imgFile)) {
|
||||
unlink($imgFile);
|
||||
}
|
||||
@@ -287,9 +287,9 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
if (!is_dir($imgDir)) {
|
||||
mkdir($imgDir, 0755, true);
|
||||
}
|
||||
if (ImageManager::resize($imgFile['tmp_name'], $imgDir.$obj->id.'.jpg')) {
|
||||
$obj->logo = $obj->id.'.jpg';
|
||||
$obj->save();
|
||||
if (ImageManager::resize($imgFile['tmp_name'], $imgDir.$objHotelAmenities->id.'.jpg')) {
|
||||
$objHotelAmenities->logo = $objHotelAmenities->id.'.jpg';
|
||||
$objHotelAmenities->save();
|
||||
} else {
|
||||
$this->errors[] = $this->l('Error uploading amenity image.');
|
||||
}
|
||||
@@ -315,8 +315,8 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
$response = array('status' => false);
|
||||
|
||||
if ($this->tabAccess['delete']) {
|
||||
$obj = new HotelAmenities();
|
||||
if ($obj->deleteHotelAmenities((int)Tools::getValue('id_category'))) {
|
||||
$objHotelAmenities = new HotelAmenities();
|
||||
if ($objHotelAmenities->deleteCategory((int)Tools::getValue('id_category'))) {
|
||||
$response['status'] = true;
|
||||
} else {
|
||||
$response['msg'] = $this->l('Error deleting category.');
|
||||
@@ -333,8 +333,8 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
$response = array('status' => false);
|
||||
|
||||
if ($this->tabAccess['delete']) {
|
||||
$obj = new HotelAmenities((int)Tools::getValue('id_amenity'));
|
||||
if (Validate::isLoadedObject($obj) && $obj->delete()) {
|
||||
$objHotelAmenities = new HotelAmenities((int)Tools::getValue('id_amenity'));
|
||||
if (Validate::isLoadedObject($objHotelAmenities) && $objHotelAmenities->delete()) {
|
||||
$response['status'] = true;
|
||||
} else {
|
||||
$response['msg'] = $this->l('Error deleting amenity.');
|
||||
@@ -351,12 +351,12 @@ class AdminHotelAmenitiesController extends ModuleAdminController
|
||||
$response = array('status' => false);
|
||||
|
||||
if ($this->tabAccess['edit']) {
|
||||
$obj = new HotelAmenities((int)Tools::getValue('id_amenity'));
|
||||
if (Validate::isLoadedObject($obj)) {
|
||||
$obj->is_featured = $obj->is_featured ? 0 : 1;
|
||||
if ($obj->save()) {
|
||||
$objHotelAmenities = new HotelAmenities((int)Tools::getValue('id_amenity'));
|
||||
if (Validate::isLoadedObject($objHotelAmenities)) {
|
||||
$objHotelAmenities->is_featured = $objHotelAmenities->is_featured ? 0 : 1;
|
||||
if ($objHotelAmenities->save()) {
|
||||
$response['status'] = true;
|
||||
$response['is_featured'] = (bool)$obj->is_featured;
|
||||
$response['is_featured'] = (bool)$objHotelAmenities->is_featured;
|
||||
} else {
|
||||
$response['msg'] = $this->l('Error updating amenity.');
|
||||
}
|
||||
|
||||
@@ -265,21 +265,23 @@
|
||||
{block name='product_info_tab_room_features'}
|
||||
{if isset($room_dynamic_features) && $room_dynamic_features}
|
||||
<div class="info_margin_div">
|
||||
{assign var="current_feature_name" value=""}
|
||||
{foreach from=$room_dynamic_features item=feature}
|
||||
<div class="room_feature_group">
|
||||
<div class="room_info_heading">
|
||||
<span>{$feature.name|escape:'html':'UTF-8'}</span>
|
||||
</div>
|
||||
<div class="room_info_content row">
|
||||
{foreach from=$feature.values item=val}
|
||||
<div class="col-sm-4 col-xs-12">
|
||||
<div class="rm_ftr_wrapper">
|
||||
{$val|escape:'html':'UTF-8'}
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
{if $feature.name != $current_feature_name}
|
||||
{if $current_feature_name != ""}</div></div>{/if}
|
||||
{assign var="current_feature_name" value=$feature.name}
|
||||
<div class="room_feature_group">
|
||||
<div class="room_info_heading">
|
||||
<span>{$feature.name|escape:'html':'UTF-8'}</span>
|
||||
</div>
|
||||
<div class="room_info_content row">
|
||||
{/if}
|
||||
<div class="col-sm-4 col-xs-12">
|
||||
<div class="rm_ftr_wrapper">
|
||||
{$feature.value|escape:'html':'UTF-8'}
|
||||
</div>
|
||||
</div>
|
||||
{if $feature@last}</div></div>{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user