Updated: Service product updation process on the front in the product controller

This commit is contained in:
vishalsingh.qlo325
2024-03-28 19:45:43 +05:30
parent 2268abe924
commit eee9b34aa8
4 changed files with 187 additions and 117 deletions

View File

@@ -45,13 +45,18 @@
{if !$PS_CATALOG_MODE && !$order_date_restrict && ($product.show_price && !isset($restricted_country_mode))}
<span class="service-product-price">
{if !$priceDisplay}{convertPrice price=$product.price_tax_incl}{else}{convertPrice price=$product.price_tax_exc}{/if}{if $product.price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY}<span class="price-label">{l s='/Night'}</span>{/if}
{if $product.allow_multiple_quantity && $product.available_for_order}
<span class="service-product-max-quantity-info">
{l s='Maximum '} {$product.max_quantity} {l s='quantity can be added'}.
</span>
{/if}
</span>
{/if}
<div>
{if ($product.show_price && !isset($restricted_country_mode))}
{if $product.available_for_order && !$PS_CATALOG_MODE && !$order_date_restrict && !((isset($restricted_country_mode) && $restricted_country_mode))}
<button class="btn btn-service-product{if isset($product.selected) && $product.selected} btn-danger remove_roomtype_product{else} btn-success add_roomtype_product{/if} pull-right" data-id-product="{$product.id_product}">{if isset($product.selected) && $product.selected}{l s='Remove'}{else}{l s='Select'}{/if}</button>
<button class="btn btn-service-product {if isset($product.selected) && $product.selected} btn-danger remove_roomtype_product{else} btn-success add_roomtype_product selected_room_type_product_{$product.id_product} {/if} pull-right" data-id-product="{$product.id_product}">{if isset($product.selected) && $product.selected}{l s='Remove'}{else}{l s='Select'}{/if}</button>
{if $product.allow_multiple_quantity && $product.available_for_order}
<div class="qty_container pull-right">
<input type="hidden" class="service_product_qty" id="service_product_qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" data-max_quantity="{$product.max_quantity}" value="{if isset($product.quantity_added) && $product.quantity_added}{$product.quantity_added|escape:'html':'UTF-8'}{else}1{/if}">

View File

@@ -1528,7 +1528,7 @@ ul.service-product-nav > li:hover {
.service_product_action_block {
display: flex;
justify-content: space-between;
align-items: end;
align-items: center;
flex-wrap: wrap;
}
.service-product-element .service-product-img {
@@ -1543,6 +1543,14 @@ ul.service-product-nav > li:hover {
font-size: 14px;
line-height: 22px;
}
.service-product-max-quantity-info, .service-product-selected-quantity-info {
display: block;
font-size: 12px;
line-height: 22px;
font-style: italic;
color: #959595;
font-weight: 400;
}
.service-product-element .service-product-price {
font-weight: 600;
font-size: 22px;

View File

@@ -1118,6 +1118,7 @@ $(document).ready(function() {
}
$(this).closest('.qty_container').find('.qty_count span').text(newQuantity);
qtyfield.val(newQuantity);
updateServiceQuantity(this);
});
// The button to decrement the product value
@@ -1132,6 +1133,7 @@ $(document).ready(function() {
$(this).closest('.qty_container').find('.qty_count span').text(1);
qtyfield.val(1);
}
updateServiceQuantity(this);
});
var ajax_check_var = '';
@@ -1204,90 +1206,110 @@ $(document).ready(function() {
}
}
function addProductToRoomType(that) {
var id_product = $(that).data('id-product');
var qty = $('input#service_product_qty_'+id_product).val();
if (typeof(qty) == 'undefined') {
qty = 1;
}
var added_service_product = [];
$('#additional_products input.service_product').each(function () {
added_service_product.push({
'id_product': $(this).data('id_product'),
'quantity':$(this).val(),
});
});
$.ajax({
type: 'POST',
headers: {
"cache-control": "no-cache"
},
url: product_controller_url,
dataType: 'JSON',
cache: false,
data: {
date_from: $('#room_check_in').val(),
date_to: $('#room_check_out').val(),
qty: qty,
id_product: $('#product_page_product_id').val(),
service_product: id_product,
added_service_product: added_service_product,
action: 'checkServiceProductWithRoomType',
ajax: true,
token: static_token
},
success: function(result) {
if (result.success) {
if (result.add) {
if ($('input#service_product_'+ id_product).length) {
var prevQty = $('input#service_product_'+ id_product).val();
if (parseInt(prevQty) > 0) {
qty = parseInt(qty) + parseInt(prevQty);
}
$('input#service_product_'+ id_product).val(qty);
} else {
$('<input type="hidden">').attr({
id: 'service_product_'+ id_product,
name: 'service_product['+ id_product +'][]',
class: 'service_product',
'data-id_product': id_product,
value: qty
}).appendTo('#additional_products');
}
}
// reset input
$(that).closest('.service_product_action_block').find('input.service_product_qty').val(1);
$(that).closest('.service_product_action_block').find('.qty_count span').text(1);
if (result.msg) {
if (result.add) {
showSuccessMessage(result.msg);
} else {
showErrorMessage(result.msg);
}
}
BookingForm.refresh();
} else {
if (result.error) {
showErrorMessage(result.error);
}
}
},
error: function(jqXHR, textStatus, errorThrown)
{
if ((textStatus != 'error' || errorThrown != '') && textStatus != 'abort')
showErrorMessage(textStatus + ': ' + errorThrown);
}
});
}
function removeRoomtypeProduct(that)
{
var id_product = $(that).data('id_product');
$(document).on('click', '.remove_roomtype_product', function(){
showSuccessMessage(cart_extra_service_remove);
var id_product = $(this).data('id-product');
$(document).find('input#service_product_'+ id_product).remove();
BookingForm.refresh();
}
$(this).closest('.service_product_action_block').find('input.service_product_qty').val(1);
$(this).closest('.service_product_action_block').find('.qty_count span').text(1);
});
});
function addProductToRoomType(that) {
var id_product = $(that).data('id-product');
var qty = $('input#service_product_qty_'+id_product).val();
if (typeof(qty) == 'undefined') {
qty = 1;
}
var added_service_product = [];
$('#additional_products input.service_product').each(function () {
added_service_product.push({
'id_product': $(this).data('id_product'),
'quantity':$(this).val(),
});
});
$.ajax({
type: 'POST',
headers: {
"cache-control": "no-cache"
},
url: product_controller_url,
dataType: 'JSON',
cache: false,
data: {
date_from: $('#room_check_in').val(),
date_to: $('#room_check_out').val(),
qty: qty,
id_product: $('#product_page_product_id').val(),
service_product: id_product,
added_service_product: added_service_product,
action: 'checkServiceProductWithRoomType',
ajax: true,
token: static_token
},
success: function(result) {
if (result.success) {
if (result.add) {
if ($('input#service_product_'+ id_product).length) {
var prevQty = $('input#service_product_'+ id_product).val();
if (parseInt(prevQty) > 0) {
qty = parseInt(qty) + parseInt(prevQty);
}
$('input#service_product_'+ id_product).val(qty);
} else {
$('<input type="hidden">').attr({
id: 'service_product_'+ id_product,
name: 'service_product['+ id_product +'][]',
class: 'service_product',
'data-id_product': id_product,
value: qty
}).appendTo('#additional_products');
}
}
// reset input
if (result.add) {
showSuccessMessage(cart_extra_service_add);
} else {
showErrorMessage(result.msg);
}
BookingForm.refresh();
} else {
if (result.error) {
showErrorMessage(result.error);
}
}
},
error: function(jqXHR, textStatus, errorThrown)
{
if ((textStatus != 'error' || errorThrown != '') && textStatus != 'abort')
showErrorMessage(textStatus + ': ' + errorThrown);
}
});
}
function removeRoomtypeProduct(that) {
var id_product = $(that).data('id_product');
$(document).find('input#service_product_'+ id_product).remove();
BookingForm.refresh();
}
function updateServiceQuantity(that) {
var buttonElement = $(that).closest('.service_product_action_block').find('.btn-service-product');
if ($(buttonElement).hasClass('remove_roomtype_product')) {
var id_product = $(buttonElement).data('id-product');
var newQuantity = parseInt($('#service_product_qty_'+id_product).val());
var oldQuantity = parseInt($('#service_product_'+id_product).val());
if (newQuantity != oldQuantity) {
$('#service_product_'+id_product).val(newQuantity);
BookingForm.refresh().then(function (res) {
showSuccessMessage(cart_extra_service_update);
});
}
}
}
function initMap() {
const map = new google.maps.Map($('#room_type_map_tab .map-wrap').get(0), {
zoom: 10,
@@ -1363,6 +1385,8 @@ var BookingForm = {
disableRoomTypeDemands(0);
disableRoomTypeServices(0);
}
updateSelectedServices();
},
initDatepicker: function(max_order_date, preparation_time, dateFrom, dateTo) {
let start_date = new Date();
@@ -1439,42 +1463,47 @@ var BookingForm = {
return data;
},
refresh: function(resetOccupancy = false) {
BookingForm.currentRequest = $.ajax({
url: product_controller_url,
type: 'POST',
headers: { 'cache-control': 'no-cache' },
dataType: 'JSON',
cache: false,
data: $.extend({
ajax: true,
action: 'refreshBookingForm',
}, BookingForm.getFormData()),
beforeSend: function() {
if(BookingForm.currentRequest != null) {
BookingForm.currentRequest.abort();
}
$('.book_now_submit').prop('disabled', true).find('span:not(#booking_action_loader)').hide();
$('#booking_action_block').find('#booking_action_loader').addClass('active');
},
success: function(response) {
if (response.status == true) {
$('.booking-form').replaceWith(response.html_booking_form);
BookingForm.init();
if (resetOccupancy) {
BookingForm.resetOccupancy();
return new Promise((resolve, reject) => {
BookingForm.currentRequest = $.ajax({
url: product_controller_url,
type: 'POST',
headers: { 'cache-control': 'no-cache' },
dataType: 'JSON',
cache: false,
data: $.extend({
ajax: true,
action: 'refreshBookingForm',
}, BookingForm.getFormData()),
beforeSend: function() {
if(BookingForm.currentRequest != null) {
BookingForm.currentRequest.abort();
}
$('.book_now_submit').prop('disabled', true).find('span:not(#booking_action_loader)').hide();
$('#booking_action_block').find('#booking_action_loader').addClass('active');
},
success: function(response) {
if (response.status == true) {
$('.booking-form').replaceWith(response.html_booking_form);
BookingForm.init();
if (resetOccupancy) {
BookingForm.resetOccupancy();
}
resolve(response);
}
},
error: function(jqXHR) {
reject(jqXHR);
if (jqXHR.readyState == 0) {
showErrorMessage(no_internet_txt);
}
},
complete: function() {
resolve(true);
$('.book_now_submit').prop('disabled', false).find('span:not(#booking_action_loader)').show();
$('#booking_action_block').find('#booking_action_loader').removeClass('active');
}
},
error: function(jqXHR) {
if (jqXHR.readyState == 0) {
showErrorMessage(no_internet_txt);
}
},
complete: function() {
$('.book_now_submit').prop('disabled', false).find('span:not(#booking_action_loader)').show();
$('#booking_action_block').find('#booking_action_loader').removeClass('active');
}
});
});
},
resetOccupancy: function () {
@@ -1482,6 +1511,31 @@ var BookingForm = {
}
}
function updateSelectedServices()
{
var room_service_products = getRoomsServiceProducts();
$('.btn-service-product').text(select_txt);
$('.btn-service-product').addClass('btn-success');
$('.btn-service-product').addClass('add_roomtype_product');
$('.btn-service-product').removeClass('btn-danger');
$('.btn-service-product').removeClass('remove_roomtype_product');
if (room_service_products.length) {
$(room_service_products).each(function(index, value) {
var element = '.selected_room_type_product_'+value['id_product'];
if ($(element).parent().find('.service_product_qty').length) {
$('#service_product_qty_'+value['id_product']).val(value.quantity);
$(element).parent().find('.qty_count span').text(value.quantity)
}
$(element).text(unselect_txt);
$(element).removeClass('btn-success');
$(element).removeClass('add_roomtype_product');
$(element).addClass('btn-danger');
$(element).addClass('remove_roomtype_product');
});
}
}
function loadHotelImagesByPage(page = 1) {
page = parseInt(page);

View File

@@ -785,7 +785,10 @@
{addJsDefL name=wrong_qty_cond}{l s='you are trying for a invalid quantity.' js=1}{/addJsDefL}
{addJsDefL name=select_txt}{l s='Select' js=1}{/addJsDefL}
{addJsDefL name=remove_txt}{l s='Remove' js=1}{/addJsDefL}
{addJsDefL name=cart_extra_service_add}{l s='Service is added to cart' js=1}{/addJsDefL}
{addJsDefL name=cart_extra_service_add}{l s='Service added' js=1}{/addJsDefL}
{addJsDefL name=unselect_txt}{l s='UnSelect' js=1}{/addJsDefL}
{addJsDefL name=cart_extra_service_remove}{l s='Service removed' js=1}{/addJsDefL}
{addJsDefL name=cart_extra_service_update}{l s='Service updated' js=1}{/addJsDefL}
{/strip}
{/if}