diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 427acaac3..bdf716637 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -92,43 +92,45 @@ class CategoryControllerCore extends FrontController public function init() { // Get category ID - $id_category = (int)Tools::getValue('id_category'); - if (!$id_category || !Validate::isUnsignedId($id_category)) { - $this->errors[] = Tools::displayError('Missing category ID'); - } + $idCategory = (int) Tools::getValue('id_category'); + $this->category = new Category($idCategory, $this->context->language->id); - // validate dates if available $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - $idHotel = HotelBranchInformation::getHotelIdByIdCategory($id_category); - - // If this category belongs to a hotel but that hotel is disabled, redirect to home page - if ($idHotel && !(new HotelBranchInformation())->hotelBranchInfoByCategoryId($id_category)) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } - - if (!HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } + $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); - // Instantiate category - $this->category = new Category($id_category, $this->context->language->id); - - parent::init(); - - // Check if the category is active and return 404 error if is disable. - if (!$this->category->active || !Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop() || in_array($this->category->id, array(Configuration::get('PS_HOME_CATEGORY'), Configuration::get('PS_ROOT_CATEGORY')))) { - header('HTTP/1.1 404 Not Found'); - header('Status: 404 Not Found'); + if (!$idCategory || !Validate::isUnsignedId($idCategory)) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } else - // Check if category can be accessible by current customer and return 403 if not - if (!$this->category->checkAccess($this->context->customer->id)) { + } elseif (!Validate::isLoadedObject($this->category) || !$this->category->active) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } elseif ($idHotel && !(new HotelBranchInformation())->hotelBranchInfoByCategoryId($idCategory)) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } elseif ($idHotel && !HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } else { + parent::init(); + + if ( + !$this->category->inShop() + || !$this->category->isAssociatedToShop() + || in_array( + $this->category->id, + array( + Configuration::get('PS_HOME_CATEGORY'), + Configuration::get('PS_ROOT_CATEGORY') + ) + ) + ) { + header('HTTP/1.1 404 Not Found'); + header('Status: 404 Not Found'); + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } elseif (!$this->category->checkAccess($this->context->customer->id)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this category.'); $this->customer_access = false; } + } } /** @@ -136,14 +138,15 @@ class CategoryControllerCore extends FrontController */ public function initContent() { + if (!$this->customer_access) { + $this->display_column_left = false; + $this->display_column_right = false; + } + parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'category.tpl'); - if (!$this->customer_access) { - return; - } - $id_category = Tools::getValue('id_category'); $displayAllRoomsTypes = false; diff --git a/themes/hotel-reservation-theme/category.tpl b/themes/hotel-reservation-theme/category.tpl index 914cd6b87..a8dc9e157 100644 --- a/themes/hotel-reservation-theme/category.tpl +++ b/themes/hotel-reservation-theme/category.tpl @@ -24,6 +24,11 @@ *} {block name='category'} + {block name='errors'} + {include file="$tpl_dir./errors.tpl"} + {/block} + + {if !isset($errors) OR !sizeof($errors)}
{block name='category_top_left'} @@ -54,6 +59,7 @@
+ {/if} {block name='category_js_vars'} {strip}