Fixed: Improved amenities management, filtering, and room type display across the frontend

Co-authored-by: Name <azharbhat.qlo098@webkul.in>
This commit is contained in:
amit sharma
2026-10-16 12:56:32 +05:30
parent 71d31c9872
commit ed1af74362
21 changed files with 563 additions and 44 deletions

View File

@@ -60,7 +60,7 @@ class AdminFeaturesControllerCore extends AdminController
'logo' => array(
'title' => $this->l('Icon'),
'align' => 'text-center',
'image' => 'rf',
'callback' => 'displayLogo',
'orderby' => false,
'search' => false,
'class' => 'fixed-width-xs'
@@ -72,6 +72,17 @@ class AdminFeaturesControllerCore extends AdminController
'align' => 'center',
'class' => 'fixed-width-xs'
),*/
'is_featured' => array(
'title' => $this->l('Is Featured'),
'type' => 'select',
'list' => array(1 => $this->l('Yes'), 0 => $this->l('No')),
'align' => 'center',
'callback' => 'displayIsFeatured',
'filter_key' => 'a!is_featured',
'filter_type' => 'int',
'class' => 'fixed-width-sm',
'orderby' => false
),
'position' => array(
'title' => $this->l('Position'),
'filter_key' => 'a!position',
@@ -181,7 +192,7 @@ class AdminFeaturesControllerCore extends AdminController
// $ps_img_url = _PS_IMG_DIR_.'rf/'.$obj->id.'.jpg';
$img_url = $this->context->link->getMediaLink(_PS_IMG_.'rf/'.$obj->id.'.jpg');
if ($img_exist = Tools::file_get_contents($img_url)) {
$image = "<img class='img-thumbnail img-responsive' style='max-width:100px' src='".$img_url."'>";
$image = "<img class='img-thumbnail img-responsive' src='".$img_url."'>";
}
$this->toolbar_title = $this->l('Add a new room feature');
@@ -200,14 +211,50 @@ class AdminFeaturesControllerCore extends AdminController
'hint' => $this->l('Enter a name for the room feature. Invalid characters:').' <>;=#{}',
'required' => true
),
array(
'type' => 'switch',
'label' => $this->l('Is Featured'),
'name' => 'is_featured',
'is_bool' => true,
'values' => array(
array('id' => 'is_featured_on', 'value' => 1, 'label' => $this->l('Yes')),
array('id' => 'is_featured_off', 'value' => 0, 'label' => $this->l('No')),
),
),
array(
'type' => 'select',
'label' => $this->l('Logo Type'),
'name' => 'logo_type',
'required' => true,
'options' => array(
'query' => array(
array('id' => 'image', 'name' => $this->l('Image (Upload)')),
array('id' => 'icon', 'name' => $this->l('Icon (Font Awesome)')),
),
'id' => 'id',
'name' => 'name',
),
),
array(
'type' => 'file',
'label' => $this->l('Room Feature Logo'),
'name' => 'logo',
'name' => 'logo_image',
'image' => $img_exist ? $image : false,
'display_image' => true,
'hint' => $this->l('Upload a room feature logo.'),
'required' => true
),
array(
'type' => 'text',
'label' => $this->l('Icon Class'),
'name' => 'logo_icon',
'required' => true,
'col' => 4,
'hint' => $this->l('Font Awesome icon class. Replace fa- with icon- (e.g. fa-wifi becomes icon-wifi).'),
'desc' => sprintf(
$this->l('Refer to %s for available icons.'),
'<a href="https://fontawesome.com/v4/cheatsheet" target="_blank">https://fontawesome.com/v4/cheatsheet</a>'
),
)
)
);
@@ -234,9 +281,50 @@ class AdminFeaturesControllerCore extends AdminController
)
);
$this->fields_value['logo_icon'] = ($obj->logo_type == 'icon') ? $obj->logo : '';
return parent::renderForm();
}
/**
* List callback: render the feature logo as an icon or as the uploaded image thumbnail.
*
* @param string $logo Icon class (when logo type is icon)
* @param array $row List row
* @return string
*/
public function displayLogo($logo, $row)
{
if (isset($row['logo_type']) && $row['logo_type'] == 'icon') {
return $logo ? '<i class="'.Tools::safeOutput($logo).'"></i>' : '';
}
$idFeature = (int) $row['id_feature'];
return ImageManager::thumbnail(
_PS_IMG_DIR_.'rf/'.$idFeature.'.jpg',
'feature_mini_'.$idFeature.'_'.(int) $this->context->shop->id.'.jpg',
45,
'jpg'
);
}
/**
* List callback: render the Is Featured value as a status-like label.
*
* @param int $isFeatured Is featured flag
* @param array $row List row
* @return string
*/
public function displayIsFeatured($isFeatured, $row)
{
if ((int) $isFeatured) {
return '<span class="label label-success">'.$this->l('Yes').'</span>';
}
return '<span class="label label-default">'.$this->l('No').'</span>';
}
public function initPageHeaderToolbar()
{
if (empty($this->display)) {
@@ -622,21 +710,63 @@ class AdminFeaturesControllerCore extends AdminController
$_POST[$key] = str_replace('\n', '', str_replace('\r', '', $value));
}
}
$featureImage = $_FILES['logo'];
if (!$idFeature || (isset($featureImage['tmp_name']) && $featureImage['tmp_name'])) {
if ($featureImage && $featureImage['tmp_name'] && $featureImage['name']) {
$logoType = Tools::getValue('logo_type');
$featureImage = isset($_FILES['logo_image']) ? $_FILES['logo_image'] : null;
if (!in_array($logoType, array('image', 'icon'))) {
$this->errors[] = $this->l('Logo type is invalid.');
$logoType = 'image';
}
if (!in_array(Tools::getValue('is_featured', 0), array('0', '1', 0, 1), true)) {
$this->errors[] = $this->l('Is Featured value is invalid.');
}
$_POST['logo_type'] = $logoType;
// Empty logo would be saved as NULL (Feature::add() uses null values), so image type keeps a placeholder until the image is saved.
$_POST['logo'] = 'image';
if ($logoType === 'icon') {
$logoIcon = trim(Tools::getValue('logo_icon'));
if (!$logoIcon) {
$this->errors[] = $this->l('Icon class is required.');
} elseif (Tools::strlen($logoIcon) > 255) {
$this->errors[] = $this->l('Icon class is too long.');
} elseif (!preg_match('/^icon-[a-z0-9]+(-[a-z0-9]+)*$/', $logoIcon)) {
$this->errors[] = $this->l('Icon class is invalid. It must start with "icon-" and contain only lowercase letters, numbers and hyphens (e.g. icon-wifi).');
} else {
$_POST['logo'] = $logoIcon;
}
} else {
$hasUpload = $featureImage && !empty($featureImage['tmp_name']);
$hasExisting = $idFeature && file_exists(_PS_IMG_DIR_.'rf/'.$idFeature.'.jpg');
if ($hasUpload) {
if ($error = ImageManager::validateUpload($featureImage, Tools::getMaxUploadSize())) {
$this->errors[] = $error;
}
} else {
} elseif (!$hasExisting) {
$this->errors[] = $this->l('Please select a logo for this feature.');
}
}
if (count($this->errors)) {
$this->display = $idFeature ? 'edit' : 'add';
return false;
}
$objFeature = parent::processSave();
if (!count($this->errors)) {
// icon type does not need the uploaded image
if ($logoType === 'icon' && file_exists(_PS_IMG_DIR_.'rf/'.$objFeature->id.'.jpg')) {
unlink(_PS_IMG_DIR_.'rf/'.$objFeature->id.'.jpg');
}
// image type stores the image file name
if ($logoType === 'image' && $objFeature->logo !== $objFeature->id.'.jpg') {
$objFeature->logo = $objFeature->id.'.jpg';
$objFeature->update();
}
// save feature image
if (isset($featureImage['tmp_name']) && $featureImage['tmp_name']) {
if ($logoType === 'image' && isset($featureImage['tmp_name']) && $featureImage['tmp_name']) {
// if already feature image then delete it once before uploading new image
if ($idFeature) {
$currentImg = _PS_TMP_IMG_DIR_.'feature_mini_'.$objFeature->id.'_'.$this->context->shop->id.'.jpg';