Merge pull request #833 from abhishek-webkul/gli-1043
Added: 'Show at front office' option to enable/disable booking from front office
This commit is contained in:
@@ -391,7 +391,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="allow_multiple_quantity_container" {if (!$product->available_for_order && $product->isAssociatedToShop()) || $product->auto_add_to_cart}style="display:none;"{/if}>
|
||||
<div id="allow_multiple_quantity_container" {if $product->auto_add_to_cart && $product->isAssociatedToShop()}style="display:none;"{/if}>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-lg-3">
|
||||
<span class="label-tooltip" data-toggle="tooltip" title="{l s='When enabled, customer can order multiple quantity of product otherwise only one quantity can be purchased by customer per room/hotel'}">
|
||||
@@ -412,7 +412,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="max_quantity_container" class="form-group" {if (!$product->available_for_order && $product->isAssociatedToShop()) || $product->auto_add_to_cart || !$product->allow_multiple_quantity}style="display:none;"{/if}>
|
||||
<div id="max_quantity_container" class="form-group" {if ($product->auto_add_to_cart && $product->isAssociatedToShop()) || !$product->allow_multiple_quantity}style="display:none;"{/if}>
|
||||
<label class="control-label col-lg-3" for="max_quantity">
|
||||
<span class="label-tooltip" data-toggle="tooltip"
|
||||
title="{l s='Enter max allowed quantity per room, enter 0 for unlimited.'}">
|
||||
|
||||
@@ -273,6 +273,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="show_at_front_container">
|
||||
<label class="control-label col-lg-3">
|
||||
<span class="label-tooltip" data-toggle="tooltip" title="{l s='Enable if you want this room type to be shown and to be available for booking from front office.'}">
|
||||
{l s='Show at front office'}
|
||||
</span>
|
||||
</label>
|
||||
<div class="col-lg-3">
|
||||
<span class="switch prestashop-switch fixed-width-lg">
|
||||
<input type="radio" name="show_at_front" id="show_at_front_on" value="1" {if $product->show_at_front || !$product->isAssociatedToShop()}checked="checked"{/if}/>
|
||||
<label for="show_at_front_on" class="radioCheck">
|
||||
{l s='Yes'}
|
||||
</label>
|
||||
<input type="radio" name="show_at_front" id="show_at_front_off" value="0" {if !$product->show_at_front && $product->isAssociatedToShop()}checked="checked"{/if}/>
|
||||
<label for="show_at_front_off" class="radioCheck">
|
||||
{l s='No'}
|
||||
</label>
|
||||
<a class="slide-button btn"></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="product_options" class="form-group hidden">
|
||||
<div class="col-lg-12">
|
||||
<div class="form-group">
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user