diff --git a/classes/Cart.php b/classes/Cart.php
index 5b3711f25..42bc4d6fa 100644
--- a/classes/Cart.php
+++ b/classes/Cart.php
@@ -532,7 +532,7 @@ class CartCore extends ObjectModel
$sql = new DbQuery();
// Build SELECT
- $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`, p.`booking_product`, p.`service_product_type`, p.`auto_add_to_cart`, p.`price_addition_type`, product_shop.`allow_multiple_quantity`, product_shop.`price_calculation_method`,
+ $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`, p.`booking_product`, p.`service_product_type`, p.`auto_add_to_cart`, p.`price_addition_type`, p.`show_at_front`, product_shop.`allow_multiple_quantity`, product_shop.`price_calculation_method`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`,
p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`,
diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php
index 639b8bb56..7b0ca74e3 100644
--- a/controllers/front/OrderOpcController.php
+++ b/controllers/front/OrderOpcController.php
@@ -423,14 +423,11 @@ class OrderOpcControllerCore extends ParentOrderController
*/
public function initContent()
{
- // check all service products are available
- RoomTypeServiceProductCartDetail::validateServiceProductsInCart();
+ // validate room types before payment by customer
+ $orderRestrictErr = HotelCartBookingData::validateCartBookings();
parent::initContent();
- // check ORDER RESTRICT condition before payment by the customer
- $orderRestrictErr = HotelOrderRestrictDate::validateOrderRestrictDateOnPayment($this);
-
/* id_carrier is not defined in database before choosing a carrier, set it to a default one to match a potential cart _rule */
if (empty($this->context->cart->id_carrier)) {
$checked = $this->context->cart->simulateCarrierSelectedOutput();
diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php
index 9f0503da7..75f503faa 100644
--- a/controllers/front/ProductController.php
+++ b/controllers/front/ProductController.php
@@ -128,7 +128,7 @@ class ProductControllerCore extends FrontController
$this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
}
- if (!$this->product->booking_product) {
+ if (!$this->product->booking_product || ($this->product->booking_product && !$this->product->show_at_front)) {
Tools::redirect($this->context->link->getPageLink('pagenotfound'));
}
diff --git a/js/admin/normal_products.js b/js/admin/normal_products.js
index e15945f8b..e602d75f1 100644
--- a/js/admin/normal_products.js
+++ b/js/admin/normal_products.js
@@ -442,10 +442,8 @@ product_tabs['Informations'] = new function(){
$('input[name=available_for_order]').on('change', function(e) {
if ($(this).val() == 1) {
$('#show_price_container').hide('fast');
- $('#allow_multiple_quantity_container').show('fast');
} else {
$('#show_price_container').show('fast');
- $('#allow_multiple_quantity_container').hide('fast');
}
});
@@ -495,8 +493,9 @@ product_tabs['Informations'] = new function(){
if ($('input[name=available_for_order]:checked').val() == 0) {
$('#show_price_container').show('fast');
}
- if ($('input[name=available_for_order]:checked').val() == 1) {
- $("#allow_multiple_quantity_container").show('fast');
+ $("#allow_multiple_quantity_container").show('fast');
+ if ($('input[name=allow_multiple_quantity]:checked').val() == 1) {
+ $('#max_quantity_container').show('fast');
}
}
});
diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php
index 8f097142e..41660e0b1 100644
--- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php
+++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php
@@ -897,6 +897,135 @@ class HotelCartBookingData extends ObjectModel
return true;
}
+ public static function validateCartBookings()
+ {
+ $context = Context::getContext();
+
+ $errors = array();
+
+ // validate room types if bookable from front office
+ if ($cartProducts = $context->cart->getProducts()) {
+ $objHotelCartBookingData = new HotelCartBookingData();
+ foreach ($cartProducts as $product) {
+ if ($product['booking_product'] && !$product['show_at_front']) {
+ $objHotelCartBookingData->deleteCartBookingData($context->cart->id, $product['id_product']);
+ }
+ }
+ }
+
+ // validate service products
+ if ($cartProducts = $context->cart->getProducts()) {
+ $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
+ foreach ($cartProducts as $product) {
+ if (!$product['active'] && !$product['booking_product']) {
+ $serviceProducts = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart($context->cart->id, $product['id_product']);
+ foreach ($serviceProducts as $serviceProduct) {
+ $objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($serviceProduct['htl_cart_booking_id']);
+ }
+ }
+ }
+ }
+
+ // validate room types for restriction date
+ $objModule = Module::getInstanceByName('hotelreservationsystem');
+ if ($cartProducts = $context->cart->getProducts()) {
+ $objHotelCartBookingData = new HotelCartBookingData();
+ $objHotelBookingDetail = new HotelBookingDetail();
+
+ foreach ($cartProducts as $product) {
+ if ($product['active']) {
+ if ($cartBookingData = $objHotelCartBookingData->getOnlyCartBookingData(
+ $context->cart->id,
+ $context->cart->id_guest,
+ $product['id_product']
+ )) {
+ $cartData = array();
+ foreach ($cartBookingData as $bookingData) {
+ $dateJoin = strtotime($bookingData['date_from']).strtotime($bookingData['date_to']);
+ $cartData[$dateJoin]['date_from'] = $bookingData['date_from'];
+ $cartData[$dateJoin]['date_to'] = $bookingData['date_to'];
+ $cartData[$dateJoin]['id_hotel'] = $bookingData['id_hotel'];
+ $cartData[$dateJoin]['id_rms'][] = $bookingData['id_room'];
+ }
+
+ foreach ($cartData as $roomData) {
+ if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($roomData['id_hotel'])) {
+ if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($roomData['date_from'])
+ || strtotime($maxOrderDate) < strtotime($roomData['date_to'])
+ ) {
+ $objHotelBranchInformation = new HotelBranchInformation(
+ $roomData['id_hotel'],
+ $context->language->id
+ );
+ $errors[] = sprintf(
+ 'You can not book rooms for hotel \'%s\' after date %s. Please remove rooms from %s - %s to proceed.',
+ $objHotelBranchInformation->hotel_name,
+ Tools::displayDate($maxOrderDate),
+ Tools::displayDate($roomData['date_from']),
+ Tools::displayDate($roomData['date_to'])
+ );
+ $error = true;
+ }
+ }
+
+ $preparationTime = HotelOrderRestrictDate::getPreparationTime($roomData['id_hotel']);
+ if ($preparationTime !== false) {
+ $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days'));
+ if (strtotime($minOrderDate) > strtotime($roomData['date_from'])
+ || strtotime($minOrderDate . ' +1 day')> strtotime($roomData['date_to'])
+ ) {
+ $objHotelBranchInformation = new HotelBranchInformation(
+ $roomData['id_hotel'],
+ $context->language->id
+ );
+ $errors[] = sprintf(
+ 'You can not book rooms for hotel \'%s\' before date %s. Please remove rooms from %s - %s to proceed.',
+ $objHotelBranchInformation->hotel_name,
+ Tools::displayDate($minOrderDate),
+ Tools::displayDate($roomData['date_from']),
+ Tools::displayDate($roomData['date_to'])
+ );
+ $error = true;
+ }
+ }
+
+ $bookingParams = array(
+ 'date_from' => $roomData['date_from'],
+ 'date_to' => $roomData['date_to'],
+ 'hotel_id' => $roomData['id_hotel'],
+ 'id_room_type' => $product['id_product'],
+ 'only_search_data' => 1,
+ );
+ $bookingSearchData = $objHotelBookingDetail->dataForFrontSearch($bookingParams);
+ $isRmBooked = 0;
+ if (count($bookingSearchData['rm_data'][$product['id_product']]['data']['available']) < count($roomData['id_rms'])) {
+ foreach ($roomData['id_rms'] as $searchRoomData) {
+ if($isRmBooked = $objHotelBookingDetail->chechRoomBooked($searchRoomData, $roomData['date_from'], $roomData['date_to'])){
+ break;
+ }
+ }
+ if ($isRmBooked) {
+ $errors[] = sprintf($objModule->l('The Room \'%s\' has been booked by another customer from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to'])));
+ $error = true;
+ } else {
+ $errors[] = sprintf($objModule->l('The Room \'%s\' is no longer avalable from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to'])));
+ $error = true;
+ }
+ }
+ }
+ }
+ } else {
+ $error = true;
+ $errors[] = $objModule->l('You can not book rooms from "', 'HotelOrderRestrictDate'). $product['name'] .$objModule->l('". Please remove rooms from "', 'HotelOrderRestrictDate'). $product['name'] . $objModule->l('" from cart to proceed.', 'HotelOrderRestrictDate');
+ }
+ }
+ }
+
+ $context->controller->errors = array_merge($context->controller->errors, $errors);
+
+ return $errors;
+ }
+
/**
* [getCartFormatedBookinInfoByIdCart : To get cart booking information with some additional information in a custom famated way].
* @param [Int] $id_cart [Id of the cart]
diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php
index c1e001f2c..998cf362e 100644
--- a/modules/hotelreservationsystem/classes/HotelHelper.php
+++ b/modules/hotelreservationsystem/classes/HotelHelper.php
@@ -445,6 +445,7 @@ class HotelHelper
$product->active = 1;
$product->quantity = 999999999;
$product->booking_product = true;
+ $product->show_at_front = 1;
$product->is_virtual = 1;
$product->indexed = 1;
$product->save();
diff --git a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php
index 785bc515f..d623d8bf6 100644
--- a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php
+++ b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php
@@ -86,100 +86,12 @@ class HotelOrderRestrictDate extends ObjectModel
public static function validateOrderRestrictDateOnPayment(&$controller)
{
- $error = false;
- $moduleInstance = Module::getInstanceByName('hotelreservationsystem');
- $context = Context::getContext();
- if ($cartProducts = $context->cart->getProducts()) {
- foreach ($cartProducts as $product) {
- if ($product['active']) {
- $objCartBookingData = new HotelCartBookingData();
- $objBookingDetail = new HotelBookingDetail();
- $obj_rm_type = new HotelRoomType();
+ if ($errors = HotelCartBookingData::validateCartBookings()) {
+ $controller->errors = array_merge($controller->errors, $errors);
- if ($cart_bk_data = $objCartBookingData->getOnlyCartBookingData(
- $context->cart->id,
- $context->cart->id_guest,
- $product['id_product']
- )) {
- $cart_data = array();
- foreach ($cart_bk_data as $data) {
- $date_join = strtotime($data['date_from']).strtotime($data['date_to']);
- $cart_data[$date_join]['date_from'] = $data['date_from'];
- $cart_data[$date_join]['date_to'] = $data['date_to'];
- $cart_data[$date_join]['id_hotel'] = $data['id_hotel'];
- $cart_data[$date_join]['id_rms'][] = $data['id_room'];
- }
- foreach ($cart_data as $cl_key => $cl_val) {
- if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($cl_val['id_hotel'])) {
- if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($cl_val['date_from'])
- || strtotime($maxOrderDate) < strtotime($cl_val['date_to'])
- ) {
- $objBranchInfo = new HotelBranchInformation(
- $cl_val['id_hotel'],
- $context->language->id
- );
- $controller->errors[] = sprintf(
- 'You can not book rooms for hotel \'%s\' after date %s. Please remove rooms from %s - %s to proceed.',
- $objBranchInfo->hotel_name,
- Tools::displayDate($maxOrderDate),
- Tools::displayDate($cl_val['date_from']),
- Tools::displayDate($cl_val['date_to'])
- );
- $error = true;
- }
- }
- $preparationTime = HotelOrderRestrictDate::getPreparationTime($cl_val['id_hotel']);
- if ($preparationTime !== false) {
- $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days'));
- if (strtotime($minOrderDate) > strtotime($cl_val['date_from'])
- || strtotime($minOrderDate . ' +1 day')> strtotime($cl_val['date_to'])
- ) {
- $objBranchInfo = new HotelBranchInformation(
- $cl_val['id_hotel'],
- $context->language->id
- );
- $controller->errors[] = sprintf(
- 'You can not book rooms for hotel \'%s\' before date %s. Please remove rooms from %s - %s to proceed.',
- $objBranchInfo->hotel_name,
- Tools::displayDate($minOrderDate),
- Tools::displayDate($cl_val['date_from']),
- Tools::displayDate($cl_val['date_to'])
- );
- $error = true;
- }
- }
-
- $bookingParams = array(
- 'date_from' => $cl_val['date_from'],
- 'date_to' => $cl_val['date_to'],
- 'hotel_id' => $cl_val['id_hotel'],
- 'id_room_type' => $product['id_product'],
- 'only_search_data' => 1,
- );
- $avai_rm = $objBookingDetail->dataForFrontSearch($bookingParams);
- $isRmBooked = 0;
- if (count($avai_rm['rm_data'][$product['id_product']]['data']['available']) < count($cl_val['id_rms'])) {
- foreach ($cl_val['id_rms'] as $cr_key => $cr_val) {
- if($isRmBooked = $objBookingDetail->chechRoomBooked($cr_val, $cl_val['date_from'], $cl_val['date_to'])){
- break;
- }
- }
- if ($isRmBooked) {
- $controller->errors[] = sprintf($moduleInstance->l('The Room \'%s\' has been booked by another customer from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($cl_val['date_from'])), date('d-m-Y', strtotime($cl_val['date_to'])));
- $error = true;
- } else {
- $controller->errors[] = sprintf($moduleInstance->l('The Room \'%s\' is no longer avalable from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($cl_val['date_from'])), date('d-m-Y', strtotime($cl_val['date_to'])));
- $error = true;
- }
- }
- }
- }
- } else {
- $error = true;
- $controller->errors[] = $moduleInstance->l('You can not book rooms from "', 'HotelOrderRestrictDate'). $product['name'] .$moduleInstance->l('". Please remove rooms from "', 'HotelOrderRestrictDate'). $product['name'] . $moduleInstance->l('" from cart to proceed.', 'HotelOrderRestrictDate');
- }
- }
+ return true;
}
- return $error;
+
+ return false;
}
}
diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php
index 071962d21..a5445ec18 100644
--- a/modules/hotelreservationsystem/classes/HotelRoomType.php
+++ b/modules/hotelreservationsystem/classes/HotelRoomType.php
@@ -322,15 +322,19 @@ class HotelRoomType extends ObjectModel
*
* @return [array|false] [If data found returns array containing information of the room types else returns false ]
*/
- public function getIdProductByHotelId($idHotel, $idRoomType = 0, $onlyActiveProd = 0, $onlyActiveHotel = 0)
+ public function getIdProductByHotelId($idHotel, $idRoomType = 0, $onlyActiveProd = 0, $onlyActiveHotel = 0, $checkShowAtFront = null)
{
+ if (is_null($checkShowAtFront)) {
+ $checkShowAtFront = isset(Context::getContext()->employee->id) ? 0 : 1;
+ }
+
$sql = 'SELECT DISTINCT hrt.`id_product`, hrt.`adults`, hrt.`children`, hrt.`id`
FROM `'._DB_PREFIX_.'htl_room_type` AS hrt ';
if ($onlyActiveHotel) {
$sql .= 'INNER JOIN `'._DB_PREFIX_.'htl_branch_info` AS hti ON (hti.id = hrt.id_hotel AND hti.active = 1)';
}
- if ($onlyActiveProd) {
+ if ($onlyActiveProd || $checkShowAtFront) {
$sql .= 'INNER JOIN `'._DB_PREFIX_.'product` AS pp ON (hrt.id_product = pp.id_product AND pp.active = 1)';
}
$sql .= 'WHERE hrt.`id_hotel`='. (int)$idHotel;
@@ -338,6 +342,10 @@ class HotelRoomType extends ObjectModel
if ($idRoomType) {
$sql .= ' AND hrt.`id_product` = '. (int)$idRoomType;
}
+ if ($checkShowAtFront) {
+ $sql .= ' AND pp.`show_at_front` = 1';
+ }
+
return Db::getInstance()->executeS($sql);
}
diff --git a/modules/wkhotelroom/classes/WkHotelRoomDisplay.php b/modules/wkhotelroom/classes/WkHotelRoomDisplay.php
index 51406ada8..f8820c9c3 100644
--- a/modules/wkhotelroom/classes/WkHotelRoomDisplay.php
+++ b/modules/wkhotelroom/classes/WkHotelRoomDisplay.php
@@ -44,13 +44,25 @@ class WkHotelRoomDisplay extends ObjectModel
);
}
- public function getHotelRoomDisplayData($active = true)
+ public function getHotelRoomDisplayData($active = true, $checkShowAtFront = true)
{
- $sql = 'SELECT * FROM `'._DB_PREFIX_.'htl_room_block_data` WHERE 1';
- if ($active !== false) {
- $sql .= ' AND `active` = '.(int)$active;
+ $sql = 'SELECT hrbd.* FROM `'._DB_PREFIX_.'htl_room_block_data` hrbd';
+
+ if ($checkShowAtFront) {
+ $sql .= ' INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hrbd.`id_product`)';
}
- $sql .= ' ORDER BY `position`';
+
+ $sql .= ' WHERE 1';
+
+ if ($active) {
+ $sql .= ' AND hrbd.`active` = 1';
+ }
+
+ if ($checkShowAtFront) {
+ $sql .= ' AND p.`show_at_front` = 1';
+ }
+
+ $sql .= ' ORDER BY hrbd.`position`';
$result = DB::getInstance()->executeS($sql);
if ($result) {