From f81882a31e069b94c61d114eaa83419a3a0aa2bd Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Fri, 22 May 2026 14:34:46 +0530 Subject: [PATCH 01/15] Fixed: booking flow must work independently from blockcart module --- classes/Cart.php | 35 ++++++++- controllers/front/CartController.php | 20 ++++- controllers/front/ProductController.php | 9 ++- modules/blockcart/ajax-cart.js | 46 ------------ .../_partials/booking-form.tpl | 14 ++-- .../_partials/room_type_list.tpl | 2 +- themes/hotel-reservation-theme/global.tpl | 10 +++ .../js/cart-summary.js | 2 +- .../js/modules/blockcart/ajax-cart.js | 47 ------------ .../hotel-reservation-theme/js/occupancy.js | 73 ++++++++++++++++++- themes/hotel-reservation-theme/js/product.js | 64 +++++++++++++++- 11 files changed, 210 insertions(+), 112 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index ad5ee4302..4deaee6d1 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -3930,6 +3930,38 @@ class CartCore extends ObjectModel } } + $totalRoomsCount = 0; + if ($htlCartData = HotelCartBookingData::getHotelCartBookingData(0)) { + foreach ($htlCartData as $roomTypeCart) { + $totalRoomsCount += $roomTypeCart['total_num_rooms']; + } + } + $nbTotalProducts = 0; + $objServiceProductCartDetail = new ServiceProductCartDetail(); + foreach ($products as &$product) { + if (!$product['booking_product']) { + if (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']) { + $nbTotalProducts += (int) $product['cart_quantity']; + } elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type'] + || Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type'] + ) { + if ($serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart( + $this->id, + [Product::SELLING_PREFERENCE_HOTEL_STANDALONE, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE], + null, + 0, + null, + $product['id_product'] + )) { + foreach ($serviceProducts as $serviceProduct) { + if ($serviceProduct['id_hotel'] && $serviceProduct['id_product'] == $product['id_product']) { + $nbTotalProducts += (int) $serviceProduct['quantity']; + } + } + } + } + } + } $objHotelAdvancedPayment = new HotelAdvancedPayment(); $total_rooms_with_services_without_discount_te = $total_rooms + $total_demands + $total_additional_services + $total_additional_services_auto_add + $total_standalone_service_products; $total_rooms_with_services_without_discount_ti = $total_rooms_wt + $total_demands_wt + $total_additional_services_wt + $total_additional_services_auto_add_wt + $total_standalone_service_products_wt; @@ -3986,7 +4018,8 @@ class CartCore extends ObjectModel 'total_rooms_with_services_without_discount_ti' => $total_rooms_with_services_without_discount_ti, 'cart_total_without_discount_te' => $cart_total_without_discount_te, 'cart_total_without_discount_ti' => $cart_total_without_discount_ti, - 'total_tax_without_discount' => $total_tax_without_discount + 'total_tax_without_discount' => $total_tax_without_discount, + 'total_products_in_cart' => $totalRoomsCount + $nbTotalProducts, ); $hook = Hook::exec('actionCartSummary', $summary, null, true); if (is_array($hook)) { diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 76f2e5982..080a605b5 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -315,7 +315,7 @@ class CartControllerCore extends FrontController } if ($occupancyRequiredForBooking && $operator == 'up') { - if ($occupancy = json_decode(Tools::getValue('occupancy'), true)) { + if ($occupancy = is_array(Tools::getValue('occupancy')) ? Tools::getValue('occupancy') : json_decode(Tools::getValue('occupancy'), true)) { $this->qty = count($occupancy); } else { $this->errors[] = Tools::displayError('Invalid occupnacy.'); @@ -341,7 +341,23 @@ class CartControllerCore extends FrontController $date_to = Tools::getValue('dateTo'); $date_from = date("Y-m-d H:i:s", strtotime($date_from)); $date_to = date("Y-m-d H:i:s", strtotime($date_to)); - $serviceProducts = json_decode(Tools::getValue('serviceProducts'),true); + + $serviceProducts = Tools::getValue('service_product'); + if (is_array($serviceProducts) && !empty($serviceProducts)) { + $formattedServiceProducts = []; + + foreach ($serviceProducts as $id_product => $data) { + $formattedServiceProducts[] = [ + 'id_product' => (int) $id_product, + 'quantity' => isset($data['quantity']) ? (int) $data['quantity'] : 1, + ]; + } + + $serviceProducts = $formattedServiceProducts; + } else { + $serviceProducts = json_decode(Tools::getValue('serviceProducts'), true); + } + $serviceProducts = is_array($serviceProducts) ? $serviceProducts : []; // valdiate occupancy if providede if ($operator == 'up' && $occupancyRequiredForBooking) { diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index ef4f509f7..a40ccab6f 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -1449,8 +1449,8 @@ class ProductControllerCore extends FrontController $response = array('status' => false); $idProduct = (int) Tools::getValue('id_product'); if ($this->product->booking_product) { - $dateFrom = Tools::getValue('room_check_in'); - $dateTo = Tools::getValue('room_check_out'); + $dateFrom = Tools::getValue('dateFrom'); + $dateTo = Tools::getValue('dateTo'); $occupancy = Tools::getValue('occupancy'); if (Configuration::get('PS_FRONT_ROOM_UNIT_SELECTION_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) { if (!Validate::isOccupancy($occupancy)) { @@ -1474,9 +1474,9 @@ class ProductControllerCore extends FrontController )) { } } else { - $idHotel = Tools::getValue('service_id_hotel'); + $idHotel = Tools::getValue('id_hotel'); $id_product_option = Tools::getValue('id_product_option'); - $quantity = Tools::getValue('service_product_qty'); + $quantity = Tools::getValue('qty'); $this->assignServiceProductVars( $id_product_option, $quantity, @@ -1484,6 +1484,7 @@ class ProductControllerCore extends FrontController ); } + $this->context->smarty->assign('static_token', Tools::getToken(false)); $html = $this->context->smarty->fetch('_partials/booking-form.tpl'); $response['status'] = true; $response['html_booking_form'] = $html; diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index ca2ad2695..360d1b577 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -1450,49 +1450,3 @@ function getRoomsServiceProducts() return serviceProducts; } -function getBookingOccupancyDetails(bookingform, booking_product) -{ - let occupancy; - if (booking_product) { - if (occupancy_required_for_booking) { - $('.booking_guest_occupancy_conatiner .dropdown').removeClass('open'); - let selected_occupancy = $(bookingform).find(".occupancy_info_block.selected") - if (selected_occupancy.length) { - occupancy = []; - $(selected_occupancy).each(function(ind, element) { - if (parseInt($(element).find('.num_adults').val())) { - let child_ages = []; - $(element).find('.guest_child_age').each(function(index) { - if ($(this).val() > -1) { - child_ages.push($(this).val()); - } - }); - if ($(element).find('.num_children').val()) { - if (child_ages.length != $(element).find('.num_children').val()) { - $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') - occupancy = false; - } - } - occupancy.push({ - 'adults': $(element).find('.num_adults').val(), - 'children': $(element).find('.num_children').val(), - 'child_ages': child_ages - }); - } else { - $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') - occupancy = false; - } - }); - } else { - $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') - occupancy = false; - } - } else { - occupancy = parseInt($(bookingform).find(".quantity_wanted").val()); - } - } else { - occupancy = parseInt($('#service_product_qty').val()); - } - - return occupancy; -} diff --git a/themes/hotel-reservation-theme/_partials/booking-form.tpl b/themes/hotel-reservation-theme/_partials/booking-form.tpl index 439363d23..e18c6cc6c 100644 --- a/themes/hotel-reservation-theme/_partials/booking-form.tpl +++ b/themes/hotel-reservation-theme/_partials/booking-form.tpl @@ -23,7 +23,7 @@
{block name='booking_form_content'} -
+ {block name='product_hidden_fields'}
{l s='Check-in'}    {l s='Check-out'}
- - + +
{/block}
@@ -192,7 +192,7 @@ @@ -231,7 +231,7 @@ {if isset($associated_hotels) && $associated_hotels}
- {foreach $associated_hotels as $hotel} {/foreach} @@ -276,7 +276,7 @@
- +
{if isset($quantity)}{$quantity|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}
@@ -292,7 +292,7 @@
{/if} {else} - + {/if} {/block} {block name='booking_form_actions'} diff --git a/themes/hotel-reservation-theme/_partials/room_type_list.tpl b/themes/hotel-reservation-theme/_partials/room_type_list.tpl index aaa0f3ec0..a85302439 100644 --- a/themes/hotel-reservation-theme/_partials/room_type_list.tpl +++ b/themes/hotel-reservation-theme/_partials/room_type_list.tpl @@ -118,7 +118,7 @@ {/if} {block name='room_type_list_room_book_now_button'}
- {l s='Book Now'} + {l s='Book Now'}
{/block}
diff --git a/themes/hotel-reservation-theme/global.tpl b/themes/hotel-reservation-theme/global.tpl index eaa7cd71a..7d8bfda70 100644 --- a/themes/hotel-reservation-theme/global.tpl +++ b/themes/hotel-reservation-theme/global.tpl @@ -37,6 +37,9 @@ {addJsDef currencySign=$currency->sign|html_entity_decode:2:"UTF-8"} {addJsDef currencyFormat=$currency->format|intval} {addJsDef currencyBlank=$currency->blank|intval} +{addJsDef currency_sign=$currency->sign} +{addJsDef currency_format=$currency->format} +{addJsDef currency_blank=$currency->blank} {addJsDef isLogged=$is_logged|intval} {addJsDef isGuest=$is_guest|intval} {addJsDef page_name=$page_name|escape:'html':'UTF-8'} @@ -62,6 +65,7 @@ {addJsDef is_occupancy_wise_search=$is_occupancy_wise_search|boolval} {addJsDef occupancy_required_for_booking=$occupancy_required_for_booking|boolval} {addJsDef max_child_age=$max_child_age} +{addJsDef hasDeliveryAddress=(isset($cart->id_address_delivery) && $cart->id_address_delivery)} {addJsDefL name='max_occupancy_reached_txt'}{l s='Maximum room occupancy reached' js=1}{/addJsDefL} {addJsDefL name='max_adults_txt'}{l s='Maximum adult occupancy reached' js=1}{/addJsDefL} @@ -81,4 +85,10 @@ {addJsDefL name='years_txt'}{l s='years' js=1}{/addJsDefL} {addJsDefL name='all_children_txt'}{l s='All Children' js=1}{/addJsDefL} {addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL} +{addJsDefL name=customizationIdMessage}{l s='Customization #' mod='blockcart' js=1}{/addJsDefL} +{addJsDefL name=removingLinkText}{l s='remove this product from my cart' mod='blockcart' js=1}{/addJsDefL} +{addJsDefL name=freeShippingTranslation}{l s='Free shipping!' mod='blockcart' js=1}{/addJsDefL} +{addJsDefL name=freeProductTranslation}{l s='Free!' mod='blockcart' js=1}{/addJsDefL} +{addJsDefL name=delete_txt}{l s='Delete' mod='blockcart' js=1}{/addJsDefL} +{addJsDefL name=toBeDetermined}{l s='To be determined' mod='blockcart' js=1}{/addJsDefL} {/strip} diff --git a/themes/hotel-reservation-theme/js/cart-summary.js b/themes/hotel-reservation-theme/js/cart-summary.js index d715077f5..7e3c538ca 100644 --- a/themes/hotel-reservation-theme/js/cart-summary.js +++ b/themes/hotel-reservation-theme/js/cart-summary.js @@ -942,8 +942,8 @@ function updateCartSummary(json) $('input[name=quantity_' + key_for_blockcart_nocustom + '_hidden]').val(product_list[i].id_customization? product_list[i].quantity_without_customization : product_list[i].cart_quantity); if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0) $('#cart_quantity_custom_' + key_for_blockcart).html(product_list[i].customizationQuantityTotal); - nbrProducts += parseInt(product_list[i].quantity); } + nbrProducts += parseInt(json.total_products_in_cart); // Update discounts var discount_count = 0; diff --git a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js index ca2ad2695..c200f5a15 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -1449,50 +1449,3 @@ function getRoomsServiceProducts() return serviceProducts; } - -function getBookingOccupancyDetails(bookingform, booking_product) -{ - let occupancy; - if (booking_product) { - if (occupancy_required_for_booking) { - $('.booking_guest_occupancy_conatiner .dropdown').removeClass('open'); - let selected_occupancy = $(bookingform).find(".occupancy_info_block.selected") - if (selected_occupancy.length) { - occupancy = []; - $(selected_occupancy).each(function(ind, element) { - if (parseInt($(element).find('.num_adults').val())) { - let child_ages = []; - $(element).find('.guest_child_age').each(function(index) { - if ($(this).val() > -1) { - child_ages.push($(this).val()); - } - }); - if ($(element).find('.num_children').val()) { - if (child_ages.length != $(element).find('.num_children').val()) { - $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') - occupancy = false; - } - } - occupancy.push({ - 'adults': $(element).find('.num_adults').val(), - 'children': $(element).find('.num_children').val(), - 'child_ages': child_ages - }); - } else { - $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') - occupancy = false; - } - }); - } else { - $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') - occupancy = false; - } - } else { - occupancy = parseInt($(bookingform).find(".quantity_wanted").val()); - } - } else { - occupancy = parseInt($('#service_product_qty').val()); - } - - return occupancy; -} diff --git a/themes/hotel-reservation-theme/js/occupancy.js b/themes/hotel-reservation-theme/js/occupancy.js index 56b59edea..1f463b85c 100644 --- a/themes/hotel-reservation-theme/js/occupancy.js +++ b/themes/hotel-reservation-theme/js/occupancy.js @@ -19,9 +19,30 @@ * @copyright Since 2010 Webkul * @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0 */ - - $(document).ready(function(){ + $(document).off('click', '.ajax_add_to_cart_button').on('click', '.ajax_add_to_cart_button', function (e) { + e.preventDefault(); + var baseUrl = $(this).attr('href'); + var occupancy = getBookingOccupancyDetails($(this).closest('.booking_room_fields'), true); + if ($(this).prop('disabled') != 'disabled' && occupancy) { + var occupancyParams = ''; + if (Array.isArray(occupancy)) { + $.each(occupancy, function(i, room) { + occupancyParams += '&occupancy[' + i + '][adults]=' + encodeURIComponent(room.adults); + occupancyParams += '&occupancy[' + i + '][children]=' + encodeURIComponent(room.children); + if (room.child_ages && room.child_ages.length) { + $.each(room.child_ages, function(_, age) { + occupancyParams += '&occupancy[' + i + '][child_ages][]=' + encodeURIComponent(age); + }); + } + }); + } else { + occupancyParams += '&qty=' + encodeURIComponent(occupancy); + } + window.location.href = baseUrl + occupancyParams; + } + }); + $(document).on('click', '.booking_occupancy_wrapper .remove-room-link', function(e) { e.preventDefault(); @@ -412,3 +433,51 @@ function resetOccupancyField(booking_occupancy_wrapper) } }); } + + +function getBookingOccupancyDetails(bookingform, booking_product) +{ + let occupancy; + if (booking_product) { + if (occupancy_required_for_booking) { + $('.booking_guest_occupancy_conatiner .dropdown').removeClass('open'); + let selected_occupancy = $(bookingform).find(".occupancy_info_block.selected") + if (selected_occupancy.length) { + occupancy = []; + $(selected_occupancy).each(function(ind, element) { + if (parseInt($(element).find('.num_adults').val())) { + let child_ages = []; + $(element).find('.guest_child_age').each(function(index) { + if ($(this).val() > -1) { + child_ages.push($(this).val()); + } + }); + if ($(element).find('.num_children').val()) { + if (child_ages.length != $(element).find('.num_children').val()) { + $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') + occupancy = false; + } + } + occupancy.push({ + 'adults': $(element).find('.num_adults').val(), + 'children': $(element).find('.num_children').val(), + 'child_ages': child_ages + }); + } else { + $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') + occupancy = false; + } + }); + } else { + $(bookingform).find('.booking_occupancy_wrapper').parent().addClass('open') + occupancy = false; + } + } else { + occupancy = parseInt($(bookingform).find(".quantity_wanted").val()); + } + } else { + occupancy = parseInt($('#service_product_qty').val()); + } + + return occupancy; +} \ No newline at end of file diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index b0771177c..3da768218 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1269,7 +1269,7 @@ function addProductToRoomType(that) { } else { $('').attr({ id: 'service_product_'+ id_product, - name: 'service_product['+ id_product +'][]', + name: 'service_product['+ id_product +'][quantity]', class: 'service_product', 'data-id_product': id_product, value: qty @@ -1590,4 +1590,66 @@ function getBookingOccupancy() } return occupancy; +} + +function resetRoomtypeServices(refresh = true) { + $('.room_demands_container').find('input.id_room_type_demand:checked').prop('checked', false).uniform(); + $('#additional_products').empty(); + $('#additional_products div') + $('.remove_roomtype_product').text(select_txt).removeClass('btn-danger remove_roomtype_product').addClass('btn-success add_roomtype_product'); + if (refresh) { + BookingForm.refresh(); + } +} + +function disableRoomTypeDemands(show) { + if (show) { + $('.room_demands_container_overlay').show(); + $('.room_demands_container').find('input:checkbox.id_room_type_demand').prop('checked', false); + $('.room_demand_block').find('.id_room_type_demand').prop('checked', false).parent().removeClass('checked'); + $('.room_demands_container').find('input:checkbox.id_room_type_demand').attr('disabled', 'disabled'); + } else { + $('.room_demands_container_overlay').hide(); + $('.room_demands_container').find('input:checkbox.id_room_type_demand').removeAttr('disabled'); + $('.room_demands_container').find('.checker').removeClass('disabled'); + } +} + +function disableRoomTypeServices(disable) { + if (disable) { + resetRoomtypeServices(false); + $('#service_products_cont').find('button.add_roomtype_product').attr('disabled', 'disabled'); + $('#service_products_cont').find('.qty_container .qty_direction a').attr('disabled', 'disabled'); + } else { + $('#service_products_cont').find('button.add_roomtype_product').removeAttr('disabled'); + $('#service_products_cont').find('.qty_container .qty_direction a').removeAttr('disabled'); + } +} + +function getRoomsExtraDemands() +{ + var roomDemands = []; + + $('input:checkbox.id_room_type_demand:checked').each(function () { + roomDemands.push({ + 'id_global_demand':$(this).val(), + 'id_option': $(this).closest('.room_demand_block').find('.id_option').val() + }); + }); + + return roomDemands; +} + +function getRoomsServiceProducts() +{ + var serviceProducts = []; + + $('#additional_products input.service_product').each(function () { + serviceProducts.push({ + 'id_product': $(this).data('id_product'), + 'quantity':$(this).val(), + }); + }); + + return serviceProducts; } \ No newline at end of file From debabcc33b5983e4f6c33d126603ed5c79328e1a Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Fri, 22 May 2026 16:36:37 +0530 Subject: [PATCH 02/15] =?UTF-8?q?Fixed:=20Fix=20CartController=20error=20h?= =?UTF-8?q?andling=20using=C2=A0=20errors=20with=20blockcart=20AJAX=20chec?= =?UTF-8?q?ks=20and=20checkout=20redirects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Name --- controllers/front/CartController.php | 21 ++++++++++++++++++--- controllers/front/OrderOpcController.php | 10 ++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 080a605b5..cbfe4071f 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -105,6 +105,9 @@ class CartControllerCore extends FrontController } } + Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product : '')); + } elseif ($this->errors && !$this->ajax) { + $this->context->cookie->__set('cart_errors', json_encode($this->errors)); Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product : '')); } } elseif (!$this->isTokenValid()) { @@ -435,7 +438,11 @@ class CartControllerCore extends FrontController $total_available_rooms = $hotelRoomData['stats']['num_avail']; if (Tools::getValue('op', 'up') == 'up') { if ($total_available_rooms < $req_rm) { - die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms))); + if (Module::isInstalled('blockcart') && Module::isEnabled('blockcart') && Configuration::get('PS_BLOCK_CART_AJAX')) { + die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms))); + } else { + $this->errors[] = Tools::displayError('All rooms are sold out for the selected dates. Please try with different dates.'); + } } else { // validate service products if available if ($serviceProducts) { @@ -466,10 +473,18 @@ class CartControllerCore extends FrontController } } } else { - die(json_encode(array('status' => 'failed3'))); + if (Module::isInstalled('blockcart') && Module::isEnabled('blockcart') && Configuration::get('PS_BLOCK_CART_AJAX')) { + die(json_encode(array('status' => 'failed3'))); + } else { + $this->errors[] = Tools::displayError('An error occurred while processing your request.'); + } } } else { - die(json_encode(array('status' => 'failed4'))); + if (Module::isInstalled('blockcart') && Module::isEnabled('blockcart') && Configuration::get('PS_BLOCK_CART_AJAX')) { + die(json_encode(array('status' => 'failed4'))); + } else { + $this->errors[] = Tools::displayError('An error occurred while processing your request.'); + } } } } else { diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index d1814c445..cd3ed1624 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -44,6 +44,16 @@ class OrderOpcControllerCore extends ParentOrderController { parent::init(); + if ($this->context->cookie->__isset('cart_errors')) { + $cartErrors = json_decode($this->context->cookie->__get('cart_errors'), true); + if (is_array($cartErrors)) { + foreach ($cartErrors as $cartError) { + $this->errors[] = $cartError; + } + } + $this->context->cookie->__unset('cart_errors'); + } + if ($this->nbProducts) { $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart()); } From 3d6b493b5a7878174c24bd3b0d95a2fdc3106bd8 Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Wed, 27 May 2026 17:34:56 +0530 Subject: [PATCH 03/15] remove unused code and use optimized way to fix this issue --- controllers/front/CartController.php | 45 ++++------ controllers/front/OrderOpcController.php | 10 --- controllers/front/ProductController.php | 4 +- modules/blockcart/ajax-cart.js | 89 ++++--------------- .../_partials/booking-form.tpl | 4 +- .../_partials/room_type_list.tpl | 2 +- themes/hotel-reservation-theme/global.tpl | 9 -- .../js/cart-summary.js | 4 +- themes/hotel-reservation-theme/js/category.js | 87 +++++++++++++++++- .../js/modules/blockcart/ajax-cart.js | 86 ++++-------------- .../hotel-reservation-theme/js/occupancy.js | 23 ----- themes/hotel-reservation-theme/order-opc.tpl | 2 + 12 files changed, 148 insertions(+), 217 deletions(-) diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index cbfe4071f..f646f1be3 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -105,9 +105,6 @@ class CartControllerCore extends FrontController } } - Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product : '')); - } elseif ($this->errors && !$this->ajax) { - $this->context->cookie->__set('cart_errors', json_encode($this->errors)); Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product : '')); } } elseif (!$this->isTokenValid()) { @@ -158,8 +155,8 @@ class CartControllerCore extends FrontController $result = $this->context->cart->deleteProduct($this->id_product, $this->id_product_attribute, $this->customization_id, $this->id_address_delivery); // now get updated available rooms - $date_from = Tools::getValue('dateFrom'); - $date_to = Tools::getValue('dateTo'); + $date_from = Tools::getValue('date_from'); + $date_to = Tools::getValue('date_to'); $date_from = date("Y-m-d H:i:s", strtotime($date_from)); $date_to = date("Y-m-d H:i:s", strtotime($date_to)); $objRoomType = new HotelRoomType(); @@ -318,7 +315,7 @@ class CartControllerCore extends FrontController } if ($occupancyRequiredForBooking && $operator == 'up') { - if ($occupancy = is_array(Tools::getValue('occupancy')) ? Tools::getValue('occupancy') : json_decode(Tools::getValue('occupancy'), true)) { + if ($occupancy = Tools::getValue('occupancy')) { $this->qty = count($occupancy); } else { $this->errors[] = Tools::displayError('Invalid occupnacy.'); @@ -340,27 +337,21 @@ class CartControllerCore extends FrontController if (!$this->errors) { $objRoomType = new HotelRoomType(); if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($this->id_product)) { - $date_from = Tools::getValue('dateFrom'); - $date_to = Tools::getValue('dateTo'); + $date_from = Tools::getValue('date_from'); + $date_to = Tools::getValue('date_to'); $date_from = date("Y-m-d H:i:s", strtotime($date_from)); $date_to = date("Y-m-d H:i:s", strtotime($date_to)); - $serviceProducts = Tools::getValue('service_product'); - if (is_array($serviceProducts) && !empty($serviceProducts)) { - $formattedServiceProducts = []; - - foreach ($serviceProducts as $id_product => $data) { - $formattedServiceProducts[] = [ - 'id_product' => (int) $id_product, - 'quantity' => isset($data['quantity']) ? (int) $data['quantity'] : 1, - ]; - } - - $serviceProducts = $formattedServiceProducts; - } else { - $serviceProducts = json_decode(Tools::getValue('serviceProducts'), true); + $rawServiceProducts = Tools::getValue('service_product'); + $serviceProducts = []; + if (is_array($rawServiceProducts) && !empty($rawServiceProducts)) { + foreach ($rawServiceProducts as $id_product => $data) { + $serviceProducts[] = [ + 'id_product' => (int) $id_product, + 'quantity' => isset($data['quantity']) ? (int) $data['quantity'] : 1, + ]; + } } - $serviceProducts = is_array($serviceProducts) ? $serviceProducts : []; // valdiate occupancy if providede if ($operator == 'up' && $occupancyRequiredForBooking) { @@ -438,7 +429,7 @@ class CartControllerCore extends FrontController $total_available_rooms = $hotelRoomData['stats']['num_avail']; if (Tools::getValue('op', 'up') == 'up') { if ($total_available_rooms < $req_rm) { - if (Module::isInstalled('blockcart') && Module::isEnabled('blockcart') && Configuration::get('PS_BLOCK_CART_AJAX')) { + if (Tools::getValue('ajax')) { die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms))); } else { $this->errors[] = Tools::displayError('All rooms are sold out for the selected dates. Please try with different dates.'); @@ -473,14 +464,14 @@ class CartControllerCore extends FrontController } } } else { - if (Module::isInstalled('blockcart') && Module::isEnabled('blockcart') && Configuration::get('PS_BLOCK_CART_AJAX')) { + if (Tools::getValue('ajax')) { die(json_encode(array('status' => 'failed3'))); } else { $this->errors[] = Tools::displayError('An error occurred while processing your request.'); } } } else { - if (Module::isInstalled('blockcart') && Module::isEnabled('blockcart') && Configuration::get('PS_BLOCK_CART_AJAX')) { + if (Tools::getValue('ajax')) { die(json_encode(array('status' => 'failed4'))); } else { $this->errors[] = Tools::displayError('An error occurred while processing your request.'); @@ -638,7 +629,7 @@ class CartControllerCore extends FrontController */ if ($product->booking_product) { $objHotelCartBookingData = new HotelCartBookingData(); - $roomDemand = json_decode(Tools::getValue('roomDemands'), true); + $roomDemand = json_decode(Tools::getValue('room_demands'), true); $roomDemand = json_encode($roomDemand); $availQty = $total_available_rooms; $update_quantity = $objHotelCartBookingData->updateCartBooking( diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index cd3ed1624..d1814c445 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -44,16 +44,6 @@ class OrderOpcControllerCore extends ParentOrderController { parent::init(); - if ($this->context->cookie->__isset('cart_errors')) { - $cartErrors = json_decode($this->context->cookie->__get('cart_errors'), true); - if (is_array($cartErrors)) { - foreach ($cartErrors as $cartError) { - $this->errors[] = $cartError; - } - } - $this->context->cookie->__unset('cart_errors'); - } - if ($this->nbProducts) { $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart()); } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index a40ccab6f..1fe70ea20 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -1449,8 +1449,8 @@ class ProductControllerCore extends FrontController $response = array('status' => false); $idProduct = (int) Tools::getValue('id_product'); if ($this->product->booking_product) { - $dateFrom = Tools::getValue('dateFrom'); - $dateTo = Tools::getValue('dateTo'); + $dateFrom = Tools::getValue('date_from'); + $dateTo = Tools::getValue('date_to'); $occupancy = Tools::getValue('occupancy'); if (Configuration::get('PS_FRONT_ROOM_UNIT_SELECTION_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) { if (!Validate::isOccupancy($occupancy)) { diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index 360d1b577..eaa8a6bd9 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -394,19 +394,29 @@ var ajaxCart = { if (parseInt(booking_product)) { // get the selected extra demands by customer if (typeof dateFrom != 'undefined') - req.append('dateFrom', dateFrom); + req.append('date_from', dateFrom); if (typeof dateTo != 'undefined') - req.append('dateTo', dateTo); + req.append('date_to', dateTo); - if (occupancy_required_for_booking) { - req.append('occupancy', JSON.stringify(occupancy)); + if (occupancy_required_for_booking) { + occupancy.forEach(function(room, i) { + req.append('occupancy['+i+'][adults]', room.adults); + req.append('occupancy['+i+'][children]', room.children || 0); + if (room.child_ages && room.child_ages.length) { + room.child_ages.forEach(function(age) { + req.append('occupancy['+i+'][child_ages][]', age); + }); + } + }); } else { req.append('qty', ((occupancy && occupancy != null) ? occupancy : '1')); } var roomDemands = getRoomsExtraDemands(); - req.append('roomDemands', JSON.stringify(roomDemands) ); - req.append('serviceProducts', JSON.stringify(getRoomsServiceProducts()) ); + req.append('room_demands', JSON.stringify(roomDemands) ); + getRoomsServiceProducts().forEach(function(product) { + req.append('service_product['+product.id_product+'][quantity]', product.quantity); + }); } else { req.append('qty', ((occupancy && occupancy != null) ? occupancy : '1')); } @@ -555,7 +565,7 @@ var ajaxCart = { async: true, cache: false, dataType: "json", - data: 'controller=cart&add=1&op=down&dateFrom=' + dateFrom + '&dateTo=' + dateTo + '&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ((parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination) : '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)), + data: 'controller=cart&add=1&op=down&date_from=' + dateFrom + '&date_to=' + dateTo + '&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ((parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination) : '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)), success: function(jsonData, textStatus, jqXHR) { /*by webkul checking and setting availability of rooms*/ /*for product page add to cart quantity management*/ @@ -629,7 +639,7 @@ var ajaxCart = { async: true, cache: false, dataType: "json", - data: 'controller=cart&delete=1&dateFrom=' + dateFrom + '&dateTo=' + dateTo + '&id_product=' + idProduct + '&id_hotel=' + idHotel + '&id_product_option=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') + '&id_address_delivery=' + idAddressDelivery + '&token=' + static_token + '&ajax=true', + data: 'controller=cart&delete=1&date_from=' + dateFrom + '&date_to=' + dateTo + '&id_product=' + idProduct + '&id_hotel=' + idHotel + '&id_product_option=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') + '&id_address_delivery=' + idAddressDelivery + '&token=' + static_token + '&ajax=true', success: function(jsonData) { if (pagename == 'product') { disableRoomTypeDemands(0); @@ -1387,66 +1397,3 @@ function crossselling_serialScroll() { pager: false }); } - -function resetRoomtypeServices(refresh = true) { - $('.room_demands_container').find('input.id_room_type_demand:checked').prop('checked', false).uniform(); - $('#additional_products').empty(); - $('#additional_products div') - $('.remove_roomtype_product').text(select_txt).removeClass('btn-danger remove_roomtype_product').addClass('btn-success add_roomtype_product'); - if (refresh) { - BookingForm.refresh(); - } -} - -function disableRoomTypeDemands(show) { - if (show) { - $('.room_demands_container_overlay').show(); - $('.room_demands_container').find('input:checkbox.id_room_type_demand').prop('checked', false); - $('.room_demand_block').find('.id_room_type_demand').prop('checked', false).parent().removeClass('checked'); - $('.room_demands_container').find('input:checkbox.id_room_type_demand').attr('disabled', 'disabled'); - } else { - $('.room_demands_container_overlay').hide(); - $('.room_demands_container').find('input:checkbox.id_room_type_demand').removeAttr('disabled'); - $('.room_demands_container').find('.checker').removeClass('disabled'); - } -} - -function disableRoomTypeServices(disable) { - if (disable) { - resetRoomtypeServices(false); - $('#service_products_cont').find('button.add_roomtype_product').attr('disabled', 'disabled'); - $('#service_products_cont').find('.qty_container .qty_direction a').attr('disabled', 'disabled'); - } else { - $('#service_products_cont').find('button.add_roomtype_product').removeAttr('disabled'); - $('#service_products_cont').find('.qty_container .qty_direction a').removeAttr('disabled'); - } -} - -function getRoomsExtraDemands() -{ - var roomDemands = []; - - $('input:checkbox.id_room_type_demand:checked').each(function () { - roomDemands.push({ - 'id_global_demand':$(this).val(), - 'id_option': $(this).closest('.room_demand_block').find('.id_option').val() - }); - }); - - return roomDemands; -} - -function getRoomsServiceProducts() -{ - var serviceProducts = []; - - $('#additional_products input.service_product').each(function () { - serviceProducts.push({ - 'id_product': $(this).data('id_product'), - 'quantity':$(this).val(), - }); - }); - - return serviceProducts; -} - diff --git a/themes/hotel-reservation-theme/_partials/booking-form.tpl b/themes/hotel-reservation-theme/_partials/booking-form.tpl index e18c6cc6c..c54f6e695 100644 --- a/themes/hotel-reservation-theme/_partials/booking-form.tpl +++ b/themes/hotel-reservation-theme/_partials/booking-form.tpl @@ -51,8 +51,8 @@
{l s='Check-in'}    {l s='Check-out'}
- - + +
{/block}
diff --git a/themes/hotel-reservation-theme/_partials/room_type_list.tpl b/themes/hotel-reservation-theme/_partials/room_type_list.tpl index a85302439..1633ebb26 100644 --- a/themes/hotel-reservation-theme/_partials/room_type_list.tpl +++ b/themes/hotel-reservation-theme/_partials/room_type_list.tpl @@ -118,7 +118,7 @@ {/if} {block name='room_type_list_room_book_now_button'}
- {l s='Book Now'} + {l s='Book Now'}
{/block}
diff --git a/themes/hotel-reservation-theme/global.tpl b/themes/hotel-reservation-theme/global.tpl index 7d8bfda70..f8f62346a 100644 --- a/themes/hotel-reservation-theme/global.tpl +++ b/themes/hotel-reservation-theme/global.tpl @@ -37,9 +37,6 @@ {addJsDef currencySign=$currency->sign|html_entity_decode:2:"UTF-8"} {addJsDef currencyFormat=$currency->format|intval} {addJsDef currencyBlank=$currency->blank|intval} -{addJsDef currency_sign=$currency->sign} -{addJsDef currency_format=$currency->format} -{addJsDef currency_blank=$currency->blank} {addJsDef isLogged=$is_logged|intval} {addJsDef isGuest=$is_guest|intval} {addJsDef page_name=$page_name|escape:'html':'UTF-8'} @@ -85,10 +82,4 @@ {addJsDefL name='years_txt'}{l s='years' js=1}{/addJsDefL} {addJsDefL name='all_children_txt'}{l s='All Children' js=1}{/addJsDefL} {addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL} -{addJsDefL name=customizationIdMessage}{l s='Customization #' mod='blockcart' js=1}{/addJsDefL} -{addJsDefL name=removingLinkText}{l s='remove this product from my cart' mod='blockcart' js=1}{/addJsDefL} -{addJsDefL name=freeShippingTranslation}{l s='Free shipping!' mod='blockcart' js=1}{/addJsDefL} -{addJsDefL name=freeProductTranslation}{l s='Free!' mod='blockcart' js=1}{/addJsDefL} -{addJsDefL name=delete_txt}{l s='Delete' mod='blockcart' js=1}{/addJsDefL} -{addJsDefL name=toBeDetermined}{l s='To be determined' mod='blockcart' js=1}{/addJsDefL} {/strip} diff --git a/themes/hotel-reservation-theme/js/cart-summary.js b/themes/hotel-reservation-theme/js/cart-summary.js index 7e3c538ca..cd3461070 100644 --- a/themes/hotel-reservation-theme/js/cart-summary.js +++ b/themes/hotel-reservation-theme/js/cart-summary.js @@ -601,8 +601,8 @@ function deleteRoomFromSummary(el) + '&op=down' + '&qty='+qty + '&id_product='+id_product - + '&dateFrom='+date_from - + '&dateTo='+date_to + + '&date_from='+date_from + + '&date_to='+date_to + '&token=' + static_token + '&allow_refresh=1', success: function(jsonData) diff --git a/themes/hotel-reservation-theme/js/category.js b/themes/hotel-reservation-theme/js/category.js index c872efdfb..50fcbf200 100644 --- a/themes/hotel-reservation-theme/js/category.js +++ b/themes/hotel-reservation-theme/js/category.js @@ -66,4 +66,89 @@ function resizeCatimg() $( "#check_out_time" ).datepicker( "option", "maxDate", max_order_date_format); } });*/ -/*End*/ \ No newline at end of file +/*End*/ + +$(document).off('click', '.ajax_add_to_cart_button').on('click', '.ajax_add_to_cart_button', function (e) { + e.preventDefault(); + var baseUrl = $(this).attr('href'); + var occupancy = getBookingOccupancyDetails($(this).closest('.booking_room_fields'), true); + if ($(this).prop('disabled') != 'disabled' && occupancy) { + var occupancyParams = ''; + if (Array.isArray(occupancy)) { + $.each(occupancy, function(i, room) { + occupancyParams += '&occupancy[' + i + '][adults]=' + encodeURIComponent(room.adults); + occupancyParams += '&occupancy[' + i + '][children]=' + encodeURIComponent(room.children); + if (room.child_ages && room.child_ages.length) { + $.each(room.child_ages, function(_, age) { + occupancyParams += '&occupancy[' + i + '][child_ages][]=' + encodeURIComponent(age); + }); + } + }); + } else { + occupancyParams += '&qty=' + encodeURIComponent(occupancy); + } + window.location.href = baseUrl + occupancyParams; + } +}); + +function resetRoomtypeServices(refresh = true) { + $('.room_demands_container').find('input.id_room_type_demand:checked').prop('checked', false).uniform(); + $('#additional_products').empty(); + $('#additional_products div') + $('.remove_roomtype_product').text(select_txt).removeClass('btn-danger remove_roomtype_product').addClass('btn-success add_roomtype_product'); + if (refresh) { + BookingForm.refresh(); + } +} + +function disableRoomTypeDemands(show) { + if (show) { + $('.room_demands_container_overlay').show(); + $('.room_demands_container').find('input:checkbox.id_room_type_demand').prop('checked', false); + $('.room_demand_block').find('.id_room_type_demand').prop('checked', false).parent().removeClass('checked'); + $('.room_demands_container').find('input:checkbox.id_room_type_demand').attr('disabled', 'disabled'); + } else { + $('.room_demands_container_overlay').hide(); + $('.room_demands_container').find('input:checkbox.id_room_type_demand').removeAttr('disabled'); + $('.room_demands_container').find('.checker').removeClass('disabled'); + } +} + +function disableRoomTypeServices(disable) { + if (disable) { + resetRoomtypeServices(false); + $('#service_products_cont').find('button.add_roomtype_product').attr('disabled', 'disabled'); + $('#service_products_cont').find('.qty_container .qty_direction a').attr('disabled', 'disabled'); + } else { + $('#service_products_cont').find('button.add_roomtype_product').removeAttr('disabled'); + $('#service_products_cont').find('.qty_container .qty_direction a').removeAttr('disabled'); + } +} + +function getRoomsExtraDemands() +{ + var roomDemands = []; + + $('input:checkbox.id_room_type_demand:checked').each(function () { + roomDemands.push({ + 'id_global_demand':$(this).val(), + 'id_option': $(this).closest('.room_demand_block').find('.id_option').val() + }); + }); + + return roomDemands; +} + +function getRoomsServiceProducts() +{ + var serviceProducts = []; + + $('#additional_products input.service_product').each(function () { + serviceProducts.push({ + 'id_product': $(this).data('id_product'), + 'quantity':$(this).val(), + }); + }); + + return serviceProducts; +} \ No newline at end of file diff --git a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js index c200f5a15..49b65b0db 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -394,19 +394,29 @@ var ajaxCart = { if (parseInt(booking_product)) { // get the selected extra demands by customer if (typeof dateFrom != 'undefined') - req.append('dateFrom', dateFrom); + req.append('date_from', dateFrom); if (typeof dateTo != 'undefined') - req.append('dateTo', dateTo); + req.append('date_to', dateTo); if (occupancy_required_for_booking) { - req.append('occupancy', JSON.stringify(occupancy)); + occupancy.forEach(function(room, i) { + req.append('occupancy['+i+'][adults]', room.adults); + req.append('occupancy['+i+'][children]', room.children || 0); + if (room.child_ages && room.child_ages.length) { + room.child_ages.forEach(function(age) { + req.append('occupancy['+i+'][child_ages][]', age); + }); + } + }); } else { req.append('qty', ((occupancy && occupancy != null) ? occupancy : '1')); } var roomDemands = getRoomsExtraDemands(); - req.append('roomDemands', JSON.stringify(roomDemands) ); - req.append('serviceProducts', JSON.stringify(getRoomsServiceProducts()) ); + req.append('room_demands', JSON.stringify(roomDemands) ); + getRoomsServiceProducts().forEach(function(product) { + req.append('service_product['+product.id_product+'][quantity]', product.quantity); + }); } else { req.append('qty', ((occupancy && occupancy != null) ? occupancy : '1')); } @@ -555,7 +565,7 @@ var ajaxCart = { async: true, cache: false, dataType: "json", - data: 'controller=cart&add=1&op=down&dateFrom=' + dateFrom + '&dateTo=' + dateTo + '&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ((parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination) : '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)), + data: 'controller=cart&add=1&op=down&date_from=' + dateFrom + '&date_to=' + dateTo + '&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ((parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination) : '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)), success: function(jsonData, textStatus, jqXHR) { /*by webkul checking and setting availability of rooms*/ /*for product page add to cart quantity management*/ @@ -629,7 +639,7 @@ var ajaxCart = { async: true, cache: false, dataType: "json", - data: 'controller=cart&delete=1&dateFrom=' + dateFrom + '&dateTo=' + dateTo + '&id_product=' + idProduct + '&id_hotel=' + idHotel + '&id_product_option=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') + '&id_address_delivery=' + idAddressDelivery + '&token=' + static_token + '&ajax=true', + data: 'controller=cart&delete=1&date_from=' + dateFrom + '&date_to=' + dateTo + '&id_product=' + idProduct + '&id_hotel=' + idHotel + '&id_product_option=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') + '&id_address_delivery=' + idAddressDelivery + '&token=' + static_token + '&ajax=true', success: function(jsonData) { if (pagename == 'product') { disableRoomTypeDemands(0); @@ -1387,65 +1397,3 @@ function crossselling_serialScroll() { pager: false }); } - -function resetRoomtypeServices(refresh = true) { - $('.room_demands_container').find('input.id_room_type_demand:checked').prop('checked', false).uniform(); - $('#additional_products').empty(); - $('#additional_products div') - $('.remove_roomtype_product').text(select_txt).removeClass('btn-danger remove_roomtype_product').addClass('btn-success add_roomtype_product'); - if (refresh) { - BookingForm.refresh(); - } -} - -function disableRoomTypeDemands(show) { - if (show) { - $('.room_demands_container_overlay').show(); - $('.room_demands_container').find('input:checkbox.id_room_type_demand').prop('checked', false); - $('.room_demand_block').find('.id_room_type_demand').prop('checked', false).parent().removeClass('checked'); - $('.room_demands_container').find('input:checkbox.id_room_type_demand').attr('disabled', 'disabled'); - } else { - $('.room_demands_container_overlay').hide(); - $('.room_demands_container').find('input:checkbox.id_room_type_demand').removeAttr('disabled'); - $('.room_demands_container').find('.checker').removeClass('disabled'); - } -} - -function disableRoomTypeServices(disable) { - if (disable) { - resetRoomtypeServices(false); - $('#service_products_cont').find('button.add_roomtype_product').attr('disabled', 'disabled'); - $('#service_products_cont').find('.qty_container .qty_direction a').attr('disabled', 'disabled'); - } else { - $('#service_products_cont').find('button.add_roomtype_product').removeAttr('disabled'); - $('#service_products_cont').find('.qty_container .qty_direction a').removeAttr('disabled'); - } -} - -function getRoomsExtraDemands() -{ - var roomDemands = []; - - $('input:checkbox.id_room_type_demand:checked').each(function () { - roomDemands.push({ - 'id_global_demand':$(this).val(), - 'id_option': $(this).closest('.room_demand_block').find('.id_option').val() - }); - }); - - return roomDemands; -} - -function getRoomsServiceProducts() -{ - var serviceProducts = []; - - $('#additional_products input.service_product').each(function () { - serviceProducts.push({ - 'id_product': $(this).data('id_product'), - 'quantity':$(this).val(), - }); - }); - - return serviceProducts; -} diff --git a/themes/hotel-reservation-theme/js/occupancy.js b/themes/hotel-reservation-theme/js/occupancy.js index 1f463b85c..b435429b6 100644 --- a/themes/hotel-reservation-theme/js/occupancy.js +++ b/themes/hotel-reservation-theme/js/occupancy.js @@ -20,29 +20,6 @@ * @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0 */ $(document).ready(function(){ - $(document).off('click', '.ajax_add_to_cart_button').on('click', '.ajax_add_to_cart_button', function (e) { - e.preventDefault(); - var baseUrl = $(this).attr('href'); - var occupancy = getBookingOccupancyDetails($(this).closest('.booking_room_fields'), true); - if ($(this).prop('disabled') != 'disabled' && occupancy) { - var occupancyParams = ''; - if (Array.isArray(occupancy)) { - $.each(occupancy, function(i, room) { - occupancyParams += '&occupancy[' + i + '][adults]=' + encodeURIComponent(room.adults); - occupancyParams += '&occupancy[' + i + '][children]=' + encodeURIComponent(room.children); - if (room.child_ages && room.child_ages.length) { - $.each(room.child_ages, function(_, age) { - occupancyParams += '&occupancy[' + i + '][child_ages][]=' + encodeURIComponent(age); - }); - } - }); - } else { - occupancyParams += '&qty=' + encodeURIComponent(occupancy); - } - window.location.href = baseUrl + occupancyParams; - } - }); - $(document).on('click', '.booking_occupancy_wrapper .remove-room-link', function(e) { e.preventDefault(); diff --git a/themes/hotel-reservation-theme/order-opc.tpl b/themes/hotel-reservation-theme/order-opc.tpl index 81115a208..f9bcef63f 100644 --- a/themes/hotel-reservation-theme/order-opc.tpl +++ b/themes/hotel-reservation-theme/order-opc.tpl @@ -395,6 +395,8 @@ {addJsDefL name=txtExtraDemandSucc}{l s='Updated Successfully' js=1}{/addJsDefL} {addJsDefL name=txtMaxQuantityAdded}{l s='Maximum quantity of service added' js=1}{/addJsDefL} {addJsDefL name=txtExtraDemandErr}{l s='Some error occurred while updating demands' js=1}{/addJsDefL} + {addJsDefL name=freeShippingTranslation}{l s='Free shipping!' mod='blockcart' js=1}{/addJsDefL} + {/strip} {/block} {/if} From 7db96c3b9f3dee2e499a1f064072d5e8007582e1 Mon Sep 17 00:00:00 2001 From: shazar rahman Date: Tue, 7 Jul 2026 10:37:35 +0530 Subject: [PATCH 04/15] Added: Image categorization for Hotel images at back-office Co-authored-by: Name sumit201@webkul.in --- controllers/front/ProductController.php | 4 + .../classes/HotelImage.php | 34 ++- .../classes/HotelImageCategory.php | 89 ++++++ .../classes/HotelReservationSystemDb.php | 19 ++ .../admin/AdminAddHotelController.php | 23 +- .../AdminHotelImageCategoryController.php | 140 +++++++++ modules/hotelreservationsystem/define.php | 1 + .../hotelreservationsystem.php | 3 +- .../views/js/hotelImage.js | 92 ++++-- .../_partials/htl-images-list-row.tpl | 9 +- .../add_hotel/_partials/htl-images-list.tpl | 3 +- .../admin/add_hotel/helpers/form/form.tpl | 110 ++++++- .../_partials/hotel_images.tpl | 7 +- .../hotel-reservation-theme/css/product.css | 274 +++++++++++++++++- themes/hotel-reservation-theme/js/product.js | 201 ++++++++++++- themes/hotel-reservation-theme/product.tpl | 25 ++ 16 files changed, 979 insertions(+), 55 deletions(-) create mode 100644 modules/hotelreservationsystem/classes/HotelImageCategory.php create mode 100644 modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index ef4f509f7..1791c8f3c 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -1511,6 +1511,10 @@ class ProductControllerCore extends FrontController $objHotelImage->getImageLink($hotelImage['id'], ImageType::getFormatedName('large')) ); + $hotelImage['small_link'] = $this->context->link->getMediaLink( + $objHotelImage->getImageLink($hotelImage['id'], + ImageType::getFormatedName('medium')) + ); } if (is_array($hotelImages) && count($hotelImages)) { diff --git a/modules/hotelreservationsystem/classes/HotelImage.php b/modules/hotelreservationsystem/classes/HotelImage.php index 1a94b8744..0e153dea7 100644 --- a/modules/hotelreservationsystem/classes/HotelImage.php +++ b/modules/hotelreservationsystem/classes/HotelImage.php @@ -99,7 +99,7 @@ class HotelImage extends ObjectModel * @param [int] $n [number of images per page for paginated images data] * @return [array|boolean] [if data found returns array containing information of the images of the hotel which id is passed] */ - public function getImagesByHotelId($id_hotel, $p = 1, $n = null) + public function getImagesByHotelId($id_hotel, $p = 1, $n = null, $idLang = null) { $p = (int) $p; $n = $n !== null ? (int) $n : $n; // n = null for no pagination @@ -107,9 +107,16 @@ class HotelImage extends ObjectModel $p = 1; } - $sql = 'SELECT * - FROM `'._DB_PREFIX_.'htl_image` - WHERE `id_hotel` = '.(int) $id_hotel. + if (!$idLang) { + $idLang = (int) Context::getContext()->language->id; + } + + $sql = 'SELECT hi.*, hicl.`name` AS `category_name` + FROM `'._DB_PREFIX_.'htl_image` hi + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl + ON (hicl.`id_htl_image_category` = hi.`id_htl_image_category` + AND hicl.`id_lang` = '.(int) $idLang.') + WHERE hi.`id_hotel` = '.(int) $id_hotel. ($n ? ' LIMIT '.(int) (($p - 1) * $n).', '.(int) ($n) : ''); return Db::getInstance()->executeS($sql); @@ -174,11 +181,12 @@ class HotelImage extends ObjectModel ); } - public function uploadHotelImages($images, $idHotel) + public function uploadHotelImages($images, $idHotel, $idHtlImageCategory = 0) { if (isset($images) && $idHotel) { $objHotelHelper = new HotelHelper(); $hotelImages = $images['tmp_name']; + $idHtlImageCategory = (int) $idHtlImageCategory; if (is_array($images['tmp_name'])) { foreach ($hotelImages as $image) { $objHtlImage = new HotelImage(); @@ -189,6 +197,7 @@ class HotelImage extends ObjectModel $objHtlImage->cover = 1; } if ($objHtlImage->save()) { + self::updateImageCategory($objHtlImage->id, $idHtlImageCategory ?: null); if ($path = $objHtlImage->getPathForCreation()) { if (ImageManager::resize( $image, @@ -234,6 +243,7 @@ class HotelImage extends ObjectModel $objHtlImage->cover = 1; } if ($objHtlImage->save()) { + self::updateImageCategory($objHtlImage->id, $idHtlImageCategory ?: null); if ($path = $objHtlImage->getPathForCreation()) { if (ImageManager::resize( $hotelImages, @@ -265,6 +275,8 @@ class HotelImage extends ObjectModel $addedImage = array( 'id' => $objHtlImage->id, 'cover' => $objHtlImage->cover, + 'id_htl_image_category' => $idHtlImageCategory, + 'category_name' => HotelImageCategory::getCategoryName($idHtlImageCategory), 'image_link' => Context::getContext()->link->getMediaLink($objHtlImage->getImageLink($objHtlImage->id)), ); return $addedImage; @@ -312,4 +324,16 @@ class HotelImage extends ObjectModel { return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_image`'); } + + public static function updateImageCategory($idImage, $idHtlImageCategory = null) + { + return Db::getInstance()->update('htl_image', + array( + 'id_htl_image_category' => $idHtlImageCategory ? (int) $idHtlImageCategory : null, + ), + '`id` = '.(int) $idImage, + 0, + true + ); + } } diff --git a/modules/hotelreservationsystem/classes/HotelImageCategory.php b/modules/hotelreservationsystem/classes/HotelImageCategory.php new file mode 100644 index 000000000..4f8f44389 --- /dev/null +++ b/modules/hotelreservationsystem/classes/HotelImageCategory.php @@ -0,0 +1,89 @@ + 'htl_image_category', + 'primary' => 'id_htl_image_category', + 'multilang' => true, + 'fields' => array( + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), + ), + ); + + public static function getImageCategories($idLang = null) + { + if (!$idLang) { + $idLang = (int) Context::getContext()->language->id; + } + + $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT'); + + return Db::getInstance()->executeS( + 'SELECT hic.`id_htl_image_category`, COALESCE(hicl.`name`, hiclDefault.`name`) AS `name` + FROM `'._DB_PREFIX_.'htl_image_category` hic + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl + ON (hicl.`id_htl_image_category` = hic.`id_htl_image_category` + AND hicl.`id_lang` = '.(int) $idLang.') + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hiclDefault + ON (hiclDefault.`id_htl_image_category` = hic.`id_htl_image_category` + AND hiclDefault.`id_lang` = '.(int) $defaultLangId.') + WHERE COALESCE(hicl.`name`, hiclDefault.`name`) IS NOT NULL + ORDER BY `name` ASC' + ); + } + + public static function getCategoryName($idHtlImageCategory, $idLang = null) + { + $idHtlImageCategory = (int) $idHtlImageCategory; + if (!$idHtlImageCategory) { + return ''; + } + + if (!$idLang) { + $idLang = (int) Context::getContext()->language->id; + } + + $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT'); + + return (string) Db::getInstance()->getValue( + 'SELECT COALESCE(hicl.`name`, hiclDefault.`name`) AS `name` + FROM `'._DB_PREFIX_.'htl_image_category` hic + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl + ON (hicl.`id_htl_image_category` = hic.`id_htl_image_category` + AND hicl.`id_lang` = '.(int) $idLang.') + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hiclDefault + ON (hiclDefault.`id_htl_image_category` = hic.`id_htl_image_category` + AND hiclDefault.`id_lang` = '.(int) $defaultLangId.') + WHERE hic.`id_htl_image_category` = '.(int) $idHtlImageCategory + ); + } +} diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index ca44a2826..b81a27d78 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -87,10 +87,27 @@ class HotelReservationSystemDb "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, + `id_htl_image_category` int(10) unsigned DEFAULT NULL, `cover` tinyint(1) NOT NULL DEFAULT '0', + KEY `id_hotel` (`id_hotel`), + KEY `id_htl_image_category` (`id_htl_image_category`), PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image_category` ( + `id_htl_image_category` int(10) unsigned NOT NULL AUTO_INCREMENT, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_htl_image_category`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image_category_lang` ( + `id_htl_image_category` int(10) unsigned NOT NULL, + `id_lang` int(10) unsigned NOT NULL, + `name` varchar(128) NOT NULL, + PRIMARY KEY (`id_htl_image_category`, `id_lang`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_features` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, @@ -578,6 +595,8 @@ class HotelReservationSystemDb `'._DB_PREFIX_.'htl_branch_info`, `'._DB_PREFIX_.'htl_branch_info_lang`, `'._DB_PREFIX_.'htl_image`, + `'._DB_PREFIX_.'htl_image_category`, + `'._DB_PREFIX_.'htl_image_category_lang`, `'._DB_PREFIX_.'htl_branch_features`, `'._DB_PREFIX_.'htl_features`, `'._DB_PREFIX_.'htl_features_lang`, diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 868012630..d7cc21171 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -224,6 +224,9 @@ class AdminAddHotelController extends ModuleAdminController } else { $idCountry = Tools::getValue('hotel_country'); } + + $smartyVars['hotelImageCategories'] = HotelImageCategory::getImageCategories((int) $this->context->language->id); + // manage state option $stateOptions = null; if ($idCountry) { @@ -831,10 +834,12 @@ class AdminAddHotelController extends ModuleAdminController $conf = 4; } + $tabParam = Tools::getValue('htl_active_tab') ? '&htl_active_tab='.urlencode(Tools::getValue('htl_active_tab')) : ''; + if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { - Tools::redirectAdmin(self::$currentIndex.'&id='.(int) $newIdHotel.'&update'.$this->table.'&conf='.$conf.'&token='.$this->token ); + Tools::redirectAdmin(self::$currentIndex.'&id='.(int) $newIdHotel.'&update'.$this->table.'&conf='.$conf.'&token='.$this->token.$tabParam); } else { - Tools::redirectAdmin(self::$currentIndex.'&conf='.$conf.'&token='.$this->token); + Tools::redirectAdmin(self::$currentIndex.'&conf='.$conf.'&token='.$this->token.$tabParam); } } @@ -886,7 +891,15 @@ class AdminAddHotelController extends ModuleAdminController { $response = array('success' => false); $idHotel = Tools::getValue('id_hotel'); + $idHtlImageCategory = (int) Tools::getValue('id_htl_image_category'); if ($idHotel) { + if ($idHtlImageCategory) { + if (!Validate::isLoadedObject(new HotelImageCategory($idHtlImageCategory))) { + $response['errors'][] = $this->l('Selected image category is invalid.'); + $this->ajaxDie(json_encode($response)); + } + } + $invalidImg = ImageManager::validateUpload( $_FILES['hotel_image'], Tools::getMaxUploadSize() @@ -894,11 +907,15 @@ class AdminAddHotelController extends ModuleAdminController if (!$invalidImg) { // Add Hotel images $objHotelImage = new HotelImage(); - $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'], $idHotel); + $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'],$idHotel,$idHtlImageCategory); if ($imageDetail) { $response['success'] = true; $imageDetail['image_link'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($imageDetail['id'],ImageType::getFormatedName('large'))); $imageDetail['image_link_small'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($imageDetail['id'], ImageType::getFormatedName('small'))); + $imageDetail['id_htl_image_category'] = $idHtlImageCategory; + if (!isset($imageDetail['category_name'])) { + $imageDetail['category_name'] = HotelImageCategory::getCategoryName($idHtlImageCategory); + } $response['data']['image_info'] = $imageDetail; // get image row $this->context->smarty->assign(array( diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php new file mode 100644 index 000000000..d35cd573b --- /dev/null +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php @@ -0,0 +1,140 @@ +bootstrap = true; + $this->table = 'htl_image_category'; + $this->className = 'HotelImageCategory'; + $this->identifier = 'id_htl_image_category'; + $this->lang = true; + $this->context = Context::getContext(); + + parent::__construct(); + + $this->_new_list_header_design = true; + $this->addRowAction('edit'); + $this->addRowAction('delete'); + + $this->fields_list = array( + 'id_htl_image_category' => array( + 'title' => $this->l('ID'), + 'align' => 'center', + 'class' => 'fixed-width-xs', + ), + 'name' => array( + 'title' => $this->l('Name'), + 'align' => 'center', + ), + 'date_add' => array( + 'title' => $this->l('Created On'), + 'type' => 'datetime', + 'align' => 'center', + ), + ); + + $this->bulk_actions = array( + 'delete' => array( + 'text' => $this->l('Delete selected'), + 'icon' => 'icon-trash', + 'confirm' => $this->l('Delete selected items?'), + ), + ); + } + + public function initToolbar() + { + parent::initToolbar(); + if (!$this->display || $this->display == 'list') { + $this->page_header_toolbar_btn['new'] = array( + 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, + 'desc' => $this->l('Add new category'), + ); + } + } + + public function renderForm() + { + if (!$this->loadObject(true)) { + return; + } + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Hotel Image Category'), + 'icon' => 'icon-tags', + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name'), + 'name' => 'name', + 'required' => true, + 'lang' => true, + 'col' => 4, + 'hint' => $this->l('Enter the name of the hotel image category.'), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + ), + 'buttons' => array( + 'save-and-stay' => array( + 'title' => $this->l('Save and stay'), + 'name' => 'submitAdd'.$this->table.'AndStay', + 'type' => 'submit', + 'class' => 'btn btn-default pull-right', + 'icon' => 'process-icon-save', + ), + ), + ); + + return parent::renderForm(); + } + + public function processSave() + { + if (!$this->loadObject(true)) { + return; + } + + $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT'); + $defaultLanguage = Language::getLanguage($defaultLangId); + $languages = Language::getLanguages(false); + + if (!trim(Tools::getValue('name_'.$defaultLangId))) { + $this->errors[] = $this->l('Category name is required at least in ').$defaultLanguage['name']; + } else { + foreach ($languages as $lang) { + $langName = trim(Tools::getValue('name_'.$lang['id_lang'])); + if ($langName && !Validate::isCatalogName($langName)) { + $this->errors[] = $this->l('Invalid category name in ').$lang['name']; + } + } + } + + return parent::processSave(); + } +} diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php index e8a7cc909..e7b41db6c 100644 --- a/modules/hotelreservationsystem/define.php +++ b/modules/hotelreservationsystem/define.php @@ -26,6 +26,7 @@ require_once 'classes/HotelRoomType.php'; require_once 'classes/HotelRoomInformation.php'; require_once 'classes/HotelBranchInformation.php'; require_once 'classes/HotelImage.php'; +require_once 'classes/HotelImageCategory.php'; require_once 'classes/HotelFeatures.php'; require_once 'classes/HotelBranchFeatures.php'; require_once 'classes/HotelBookingDetail.php'; diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 5246337d7..fdd5874c9 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -33,7 +33,7 @@ class HotelReservationSystem extends Module { $this->name = 'hotelreservationsystem'; $this->tab = 'administration'; - $this->version = '1.7.0'; + $this->version = '1.7.1'; $this->author = 'Webkul'; $this->need_instance = 0; $this->bootstrap = true; @@ -523,6 +523,7 @@ class HotelReservationSystem extends Module $this->installTab('AdminHotelFeatures', 'Manage Hotel Features', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminOrderRefundRules', 'Manage Order Refund Rules', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminOrderRefundRequests', 'Manage Order Refund Requests', 'AdminHotelReservationSystemManagement'); + $this->installTab('AdminHotelImageCategory', 'Hotel Image Category', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminHotelConfigurationSetting', 'General Settings', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminHotelBedTypes', 'Bed Types', 'AdminCatalog'); diff --git a/modules/hotelreservationsystem/views/js/hotelImage.js b/modules/hotelreservationsystem/views/js/hotelImage.js index c1fd5f666..ba095fd97 100644 --- a/modules/hotelreservationsystem/views/js/hotelImage.js +++ b/modules/hotelreservationsystem/views/js/hotelImage.js @@ -21,32 +21,62 @@ */ $(document).ready(function () { - $('.htl-img-preview').fancybox({ - width: 'auto', - height: 'auto', - autoSize : false, - maxWidth: 700, - 'hideOnContentClick': false, - }); - - $("#hotel_images").on("change", function(event) { - const files = Array.from(event.target.files); - uploadSelectedImages(files); - }); - - function uploadSelectedImages(files) + function initHotelImagePreview() { - if (files.length == 0) return; // all done - let file = files[0]; - files.splice(0, 1); - createImageUploadRequest(file).then((formData) => { - uploadHotelImages(formData).then(() => { - uploadSelectedImages(files) - }); - }) + $('.htl-img-preview').fancybox({ + width: 'auto', + height: 'auto', + autoSize : false, + maxWidth: 700, + 'hideOnContentClick': false, + }); } - function createImageUploadRequest(file) + initHotelImagePreview(); + + $('body').on('click', '#upload_hotel_images_btn', function(event) { + event.preventDefault(); + var files = Array.from($('#hotel_images')[0].files || []); + var idHtlImageCategory = parseInt($('#id_htl_image_category').val(), 10); + var triggerElement = $(this); + + if (isNaN(idHtlImageCategory) || idHtlImageCategory < 0) { + idHtlImageCategory = 0; + } + + if (!files.length) { + showErrorMessage(imgSelectErrorMsg); + return; + } + + triggerElement.prop('disabled', true).addClass('disabled'); + uploadSelectedImages(files, idHtlImageCategory).then(function() { + $('#hotel_images').val(''); + $('#hotel_images-name').val(''); + showSuccessMessage(imgUploadSuccessMsg); + }, function(errorMsg) { + showErrorMessage(errorMsg || imgUploadErrorMsg); + }).then(function() { + triggerElement.prop('disabled', false).removeClass('disabled'); + }); + }); + + function uploadSelectedImages(files, idHtlImageCategory) + { + if (files.length == 0) { + return Promise.resolve(); + } + + let file = files[0]; + files.splice(0, 1); + return createImageUploadRequest(file, idHtlImageCategory).then((formData) => { + return uploadHotelImages(formData).then(() => { + return uploadSelectedImages(files, idHtlImageCategory); + }); + }); + } + + function createImageUploadRequest(file, idHtlImageCategory) { return new Promise((resolve, reject) => { if (typeof file != 'undefined') { @@ -57,10 +87,13 @@ $(document).ready(function () { var idHotel = $("#id-hotel").val(); formData.append('hotel_image', file); formData.append('id_hotel', idHotel); + formData.append('id_htl_image_category', idHtlImageCategory); formData.append('ajax', true); formData.append('action', 'uploadHotelImages'); resolve(formData); } + } else { + reject(imgUploadErrorMsg); } }); } @@ -79,20 +112,17 @@ $(document).ready(function () { if (response.success) { $('.list-empty-tr').remove(); $("#hotel-image-table tbody").append(response.data.image_row); - showSuccessMessage(imgUploadSuccessMsg); - resolve(imgUploadSuccessMsg); + initHotelImagePreview(); + resolve(response); } else { - if (typeof response.errors != 'undefined') { - showErrorMessage(response.errors); - reject(response.errors); + if (typeof response.errors != 'undefined' && response.errors.length) { + reject(response.errors.join('
')); } else { - showErrorMessage(imgUploadErrorMsg); reject(imgUploadErrorMsg); } } }, error: function(data) { - showErrorMessage(imgUploadErrorMsg); reject(imgUploadErrorMsg); } }); @@ -184,4 +214,4 @@ $(document).ready(function () { showErrorMessage(deleteImgErrorMsg); } }); -}); \ No newline at end of file +}); diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl index 4a28112c7..de398e705 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl @@ -27,6 +27,13 @@ + + {if isset($image.category_name) && $image.category_name} + {$image.category_name|escape:'html':'UTF-8'} + {else} + — + {/if} + {if $image.cover == 1} @@ -39,4 +46,4 @@ - \ No newline at end of file + diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl index d03600bda..49e7c250a 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl @@ -26,6 +26,7 @@ {l s='Image Id' mod='hotelreservationsystem'} {l s='Image' mod='hotelreservationsystem'} + {l s='Category' mod='hotelreservationsystem'} {l s='Cover' mod='hotelreservationsystem'} {l s='Action' mod='hotelreservationsystem'} @@ -47,4 +48,4 @@ {/if} - \ No newline at end of file + diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 978872548..19ea0244b 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -30,6 +30,7 @@ + {if isset($edit)} {assign var=hook_arg_id_hotel value=$hotel_info.id} {else} @@ -438,11 +439,90 @@ {if isset($hotel_info.id) && $hotel_info.id}
- -
- + {* *} +
+
+
+
+
+ + +
+ + + + + +
+

{l s='You can select multiple images.' mod='hotelreservationsystem'}

+ +
+
+
+ + +
+
+
+

@@ -651,10 +731,11 @@
-{strip} - {addJsDef adminHotelCtrlUrl = $link->getAdminlink('AdminAddHotel')} - {addJsDefL name=imgUploadSuccessMsg}{l s='Image Successfully Uploaded' js=1 mod='hotelreservationsystem'}{/addJsDefL} - {addJsDefL name=imgUploadErrorMsg}{l s='Something went wrong while uploading images. Please try again later !!' js=1 mod='hotelreservationsystem'}{/addJsDefL} + {strip} + {addJsDef adminHotelCtrlUrl = $link->getAdminlink('AdminAddHotel')} + {addJsDefL name=imgUploadSuccessMsg}{l s='Image Successfully Uploaded' js=1 mod='hotelreservationsystem'}{/addJsDefL} + {addJsDefL name=imgSelectErrorMsg}{l s='Please select at least one image before uploading.' js=1 mod='hotelreservationsystem'}{/addJsDefL} + {addJsDefL name=imgUploadErrorMsg}{l s='Something went wrong while uploading images. Please try again later !!' js=1 mod='hotelreservationsystem'}{/addJsDefL} {addJsDefL name=coverImgSuccessMsg}{l s='Cover image changed successfully' js=1 mod='hotelreservationsystem'}{/addJsDefL} {addJsDefL name=coverImgErrorMsg}{l s='Error while changing cover image' js=1 mod='hotelreservationsystem'}{/addJsDefL} @@ -705,6 +786,17 @@ $(document).on('wk.lang.changed', function(e, idLang) { $(window).trigger('resize.autosize'); }); + + // Restore active tab from controller redirect param + var _htlActiveTab = '{if !empty($smarty.get.htl_active_tab)}{$smarty.get.htl_active_tab|escape:'javascript':'UTF-8'}{/if}'; + if (_htlActiveTab && $('a[href="' + _htlActiveTab + '"]').length) { + $('a[href="' + _htlActiveTab + '"]').tab('show'); + } + + // Keep hidden input in sync so active tab survives form submission + $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + $('#htl_active_tab').val($(e.target).attr('href')); + }); }); $(".textarea-autosize").autosize(); // After full page load, reinit visible textareas so they start at the correct height diff --git a/themes/hotel-reservation-theme/_partials/hotel_images.tpl b/themes/hotel-reservation-theme/_partials/hotel_images.tpl index 489cd2938..f20e7268a 100644 --- a/themes/hotel-reservation-theme/_partials/hotel_images.tpl +++ b/themes/hotel-reservation-theme/_partials/hotel_images.tpl @@ -24,7 +24,12 @@ {if is_array($hotel_images) && count($hotel_images)} {foreach from=$hotel_images item=hotel_image} diff --git a/themes/hotel-reservation-theme/css/product.css b/themes/hotel-reservation-theme/css/product.css index cee78c595..7662875e9 100644 --- a/themes/hotel-reservation-theme/css/product.css +++ b/themes/hotel-reservation-theme/css/product.css @@ -44,7 +44,10 @@ a.fancybox-nav { .pb-left-column #image-block img { background: #fbfbfb; border-radius: 4px; - width: 100%; } + width: 100%; + min-height: 420px; + -o-object-fit: cover; + object-fit: cover; } .pb-left-column #image-block #view_full_size .span_link { position: absolute; bottom: 20px; @@ -1770,4 +1773,271 @@ ul.service-product-nav > li:hover { #hotel_rating { display: block; } -} \ No newline at end of file +} + +.htl-full-gallery-modal { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 10000; +} + +.htl-full-gallery__overlay { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.92); +} + +.htl-full-gallery__container { + position: relative; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -ms-flex-direction: column; + flex-direction: column; + width: 100%; + height: 100%; + padding: 1.5rem; + box-sizing: border-box; +} + +.htl-full-gallery__close { + position: absolute; + top: 0.75rem; + right: 0.75rem; + z-index: 10001; + width: 3.25rem; + height: 3.25rem; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + color: #fff; + font-size: 1.1rem; + border: 2px solid rgba(255,255,255,0.6); + border-radius: 50%; + background: rgba(0,0,0,0.35); + cursor: pointer; + line-height: 1; + transition: background 0.2s, border-color 0.2s; +} + +.htl-full-gallery__close:hover { + background: rgba(0,0,0,0.7); + border-color: #fff; +} + +.htl-full-gallery__header { + text-align: center; + padding-top: 0.25rem; +} + +.htl-full-gallery__hotel-name { + color: #fff; + font-size: 1.6rem; + font-weight: 400; + margin: 0 3rem 0.5rem; + letter-spacing: 0.02em; +} + +.htl-full-gallery__tabs { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + margin-top: 2rem; +} + +.htl-full-gallery__tabs-wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + gap: 0.4rem; +} + +.htl-gallery-tab { + font-size: 13px; + padding: 5px 16px; + background: transparent; + border: 1px solid rgba(255,255,255,0.7); + border-radius: 20px; + color: rgba(255,255,255,0.85); + cursor: pointer; + transition: background 0.2s, border-color 0.2s, color 0.2s; + line-height: 1.4; +} + +.htl-gallery-tab:hover { + background: rgba(255,255,255,0.12); + border-color: #fff; + color: #fff; +} + +.htl-gallery-tab.active { + background: #379BF0; + border-color: #379BF0; + color: #fff; +} + +.htl-full-gallery__main { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + position: relative; + overflow: hidden; + min-height: 0; +} + +.htl-full-gallery__nav { + position: absolute; + top: 50%; + -webkit-transform: translateY(-50%); + transform: translateY(-50%); + width: 2.75rem; + height: 2.75rem; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + background: rgba(0,0,0,0.4); + border: 1px solid rgba(255,255,255,0.5); + border-radius: 50%; + color: #fff; + font-size: 1rem; + cursor: pointer; + z-index: 10; + transition: background 0.2s, border-color 0.2s; +} + +.htl-full-gallery__nav:hover { + background: rgba(55,155,240,0.75); + border-color: #379BF0; +} + +.htl-full-gallery__nav--prev { left: 0.75rem; } +.htl-full-gallery__nav--next { right: 0.75rem; } + +.htl-full-gallery__image-container { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + max-width: calc(100% - 8rem); + max-height: 100%; +} + +.htl-full-gallery__main-image { + max-width: 100%; + max-height: 60vh; + -o-object-fit: contain; + object-fit: contain; + border-radius: 3px; + display: block; + box-shadow: 0 4px 24px rgba(0,0,0,0.5); +} + +.htl-full-gallery__thumbnails { + width: 100%; + padding: 0.5rem 0 0; +} + +.htl-gallery-thumbnails__scroll { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + gap: 0.35rem; + overflow-x: auto; + padding: 0.4rem 0.5rem; + scroll-behavior: smooth; + -webkit-overflow-scrolling: touch; +} + +.htl-gallery-thumbnails__scroll::-webkit-scrollbar { height: 3px; } +.htl-gallery-thumbnails__scroll::-webkit-scrollbar-track { background: rgba(255,255,255,0.08); } +.htl-gallery-thumbnails__scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.35); border-radius: 2px; } + +.htl-gallery-thumbnail { + -ms-flex-negative: 0; + flex-shrink: 0; + width: 5.5rem; + height: 4rem; + border-radius: 3px; + overflow: hidden; + cursor: pointer; + opacity: 0.5; + -webkit-transition: opacity 0.2s ease, -webkit-transform 0.15s ease; + transition: opacity 0.2s ease, transform 0.15s ease; + border: 2px solid transparent; +} + +.htl-gallery-thumbnail:hover { opacity: 0.8; } + +.htl-gallery-thumbnail.active { + opacity: 1; + border-color: #379BF0; + -webkit-transform: scale(1.08); + transform: scale(1.08); +} + +.htl-gallery-thumbnail img { + width: 100%; + height: 100%; + -o-object-fit: cover; + object-fit: cover; + display: block; +} + +body.gallery-open { overflow: hidden; } + +@media (max-width: 575px) { + .htl-full-gallery__container { padding: 0.6rem; } + .htl-full-gallery__hotel-name { font-size: 1rem; margin: 0 2.5rem 0.4rem; } + .htl-gallery-tab { font-size: 12px; padding: 4px 12px; } + .htl-full-gallery__nav { width: 2rem; height: 2rem; font-size: 0.85rem; } + .htl-full-gallery__nav--prev { left: 0.25rem; } + .htl-full-gallery__nav--next { right: 0.25rem; } + .htl-full-gallery__image-container { max-width: calc(100% - 5rem); } + .htl-full-gallery__main-image { max-height: 45vh; } + .htl-gallery-thumbnail { width: 3rem; height: 2rem; } +} diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index b0771177c..12ca94bd4 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -205,6 +205,7 @@ $(document).ready(function() { } if ($('.room_info_hotel_images_wrap').length) { + hotelImagesGallery.init(); loadHotelImagesByPage(1); } }); @@ -1505,6 +1506,193 @@ var BookingForm = { } } +var hotelImagesGallery = { + modal: null, + images: [], + filteredImages: [], + currentIndex: 0, + currentCategory: 'all', + categories: {}, + loadedSrcs: {}, + + init: function () { + this.modal = $('#htl-img-gallery-modal'); + this.bindEvents(); + }, + + addImages: function (newImages) { + for (var i = 0; i < newImages.length; i++) { + var img = newImages[i]; + if (this.loadedSrcs[img.src]) { continue; } + this.loadedSrcs[img.src] = true; + this.images.push(img); + if (img.categoryId && img.categoryName && !this.categories[img.categoryId]) { + this.categories[img.categoryId] = img.categoryName; + } + } + this.renderCategoryTabs(); + }, + + bindEvents: function () { + var self = this; + + $(document).on('click', '.htl-img-gallery-trigger', function (e) { + e.preventDefault(); + e.stopPropagation(); + var clickedUrl = $(this).data('large-url'); + var startIndex = 0; + for (var i = 0; i < self.images.length; i++) { + if (self.images[i].src === clickedUrl) { + startIndex = i; + break; + } + } + self.open(startIndex); + }); + + this.modal.on('click', '.htl-full-gallery__close, .htl-full-gallery__overlay', function () { + self.close(); + }); + + this.modal.on('click', '.htl-full-gallery__nav--prev', function () { + self.prevImage(); + }); + + this.modal.on('click', '.htl-full-gallery__nav--next', function () { + self.nextImage(); + }); + + $(document).on('keydown', function (e) { + if (!self.modal || !self.modal.is(':visible')) return; + if (e.key === 'Escape') { self.close(); } + else if (e.key === 'ArrowLeft') { self.prevImage(); } + else if (e.key === 'ArrowRight') { self.nextImage(); } + }); + + this.modal.on('click', '.htl-gallery-tab', function () { + var category = $(this).data('category'); + self.filterByCategory(category); + self.modal.find('.htl-gallery-tab').removeClass('active'); + $(this).addClass('active'); + }); + + this.modal.on('click', '.htl-gallery-thumbnail', function () { + var index = parseInt($(this).data('index')); + self.showImage(index); + }); + }, + + open: function (startIndex) { + if (!this.modal || !this.modal.length) return; + this.currentCategory = 'all'; + this.filteredImages = this.images.slice(); + this.modal.find('.htl-gallery-tab').removeClass('active'); + this.modal.find('.htl-gallery-tab[data-category="all"]').addClass('active'); + this.renderThumbnails(); + this.showImage(startIndex || 0); + this.modal.fadeIn(300); + $('body').addClass('gallery-open'); + }, + + close: function () { + if (!this.modal) return; + this.modal.fadeOut(300); + $('body').removeClass('gallery-open'); + }, + + filterByCategory: function (categoryId) { + this.currentCategory = categoryId; + if (categoryId === 'all') { + this.filteredImages = this.images.slice(); + } else { + var targetId = String(categoryId); + this.filteredImages = this.images.filter(function (img) { + return String(img.categoryId) === targetId; + }); + } + this.renderThumbnails(); + if (this.filteredImages.length > 0) { + this.showImage(0); + } + }, + + showImage: function (index) { + if (index < 0 || index >= this.filteredImages.length) return; + this.currentIndex = index; + var image = this.filteredImages[index]; + this.modal.find('#htl-main-image').attr('src', image.src); + this.modal.find('.htl-gallery-thumbnail').removeClass('active'); + this.modal.find('.htl-gallery-thumbnail[data-index="' + index + '"]').addClass('active'); + var thumbContainer = this.modal.find('#htl-gallery-thumbnail'); + var activeThumb = thumbContainer.find('.htl-gallery-thumbnail.active'); + if (activeThumb.length) { + var scrollTarget = activeThumb.position().left + thumbContainer.scrollLeft() - (thumbContainer.width() / 2) + (activeThumb.outerWidth() / 2); + thumbContainer.animate({ scrollLeft: scrollTarget }, 200); + } + }, + + prevImage: function () { + var newIndex = this.currentIndex - 1; + if (newIndex < 0) { newIndex = this.filteredImages.length - 1; } + this.showImage(newIndex); + }, + + nextImage: function () { + var newIndex = this.currentIndex + 1; + if (newIndex >= this.filteredImages.length) { newIndex = 0; } + this.showImage(newIndex); + }, + + renderCategoryTabs: function () { + var self = this; + var tabWrapper = this.modal.find('.htl-full-gallery__tabs-wrapper'); + if (!tabWrapper.length) return; + tabWrapper.empty(); + + var catKeys = Object.keys(this.categories); + var allPhotosLabel = (typeof htl_gallery_all_photos !== 'undefined') ? htl_gallery_all_photos : 'All Photos'; + + var activeCategory = this.currentCategory; + + /* "All Photos" tab is always visible */ + var allTab = $(' + + + + + + {/if} {/block}