Fix service product option display based on selling type.

This commit is contained in:
Amit sharma
2026-03-02 18:44:24 +05:30
parent 37ff12c22a
commit cd047d34d3
3 changed files with 88 additions and 125 deletions

View File

@@ -614,66 +614,4 @@
var SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE = {Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE|intval};
var SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE = {Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE|intval};
var SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE = {Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE|intval};
function toggleAssociationFieldNames(containerSelector, shouldShow)
{
var $container = $(containerSelector);
if (shouldShow) {
$container.show('fast').find('input').each(function() {
$(this).attr('name', $(this).attr('data-name'));
$(this).removeAttr('data-name');
});
} else {
$container.hide('fast').find('input').each(function() {
$(this).attr('data-name', $(this).attr('name'));
$(this).removeAttr('name');
});
}
}
function applySellingPreferenceUIState()
{
var sellingPreference = parseInt($('#selling_preference_type').val(), 10);
var showHotelTree = $.inArray(sellingPreference, [
SELLING_PREFERENCE_HOTEL_STANDALONE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE
]) !== -1;
var showRoomTypeTree = $.inArray(sellingPreference, [
0,
SELLING_PREFERENCE_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE
]) !== -1;
var showAutoAddToCart = $.inArray(sellingPreference, [
0,
SELLING_PREFERENCE_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE
]) !== -1;
toggleAssociationFieldNames('#associated_hotel_tree', showHotelTree);
toggleAssociationFieldNames('#associated_hotel_rooms_tree', showRoomTypeTree);
if (showAutoAddToCart) {
$('#auto_add_to_cart_container').show('fast');
} else {
$('#auto_add_to_cart_container').hide('fast');
$('input[name="auto_add_to_cart"]').trigger('change');
}
$('#show_at_front_container').show('fast');
$('#product_options').show('fast');
}
$(document).on('change.sellingPreferenceExtended', '#selling_preference_type', function() {
applySellingPreferenceUIState();
});
$(function() {
setTimeout(function() {
applySellingPreferenceUIState();
}, 0);
});
</script>

View File

@@ -2483,6 +2483,9 @@ class CartCore extends ObjectModel
)) {
$array = array();
foreach($selectedServiceProducts as $selectedProduct) {
if (empty($selectedProduct['id_hotel_cart_booking'])) {
continue;
}
if (isset($array[$selectedProduct['id_room_type_hotel']])) {
$array[$selectedProduct['id_room_type_hotel']]['total_price_tax_excl'] += $selectedProduct['total_price_tax_excl'];
$array[$selectedProduct['id_room_type_hotel']]['total_price_tax_incl'] += $selectedProduct['total_price_tax_incl'];
@@ -2507,7 +2510,7 @@ class CartCore extends ObjectModel
}
}
if ($array) {
foreach($array as $selectedProduct) {
$product['cart_quantity'] = $selectedProduct['quantity'];
@@ -2544,19 +2547,27 @@ class CartCore extends ObjectModel
}
}
}
if (Product::isSellableAsStandalone($product['selling_preference_type']) && !Product::isSellableWithRoomType($product['selling_preference_type'])) {
if (!isset($standaloneProduct[$id_address])) {
$standaloneProduct[$id_address] = array(
'product_list' => array(),
'warehouse_list' => $package['warehouse_list'],
'carrier_list' => $product['carrier_list'],
'id_warehouse' => $package['id_warehouse'],
'id_carrier' => isset($package['id_carrier']) ? $package['id_carrier'] : 0
);
if (Product::isSellableAsStandalone($product['selling_preference_type'])) {
if ($selectedServiceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
$this->id,
[],
0,
0,
null,
(int)$product['id_product']
)) {
if (!isset($standaloneProduct[$id_address])) {
$standaloneProduct[$id_address] = array(
'product_list' => array(),
'warehouse_list' => $package['warehouse_list'],
'carrier_list' => $product['carrier_list'],
'id_warehouse' => $package['id_warehouse'],
'id_carrier' => isset($package['id_carrier']) ? $package['id_carrier'] : 0
);
}
$productinfo = $product;
$standaloneProduct[$id_address]['product_list'][] = $product;
}
$productinfo = $product;
// $productinfo['selling_preference_type'] = Product::SELLING_PREFERENCE_STANDALONE;
$standaloneProduct[$id_address]['product_list'][] = $product;
}
if (Product::isSellableWithHotel($product['selling_preference_type'])) {
@@ -2600,7 +2611,6 @@ class CartCore extends ObjectModel
// if (!empty($hotelProducts['products'])) {
// foreach($hotelProducts['products'] as $hotelProduct) {
$productinfo = $serviceProduct;
// $productinfo['selling_preference_type'] = Product::SELLING_PREFERENCE_HOTEL_STANDALONE;
$orderPackage[$id_address][$hotelProduct['id_hotel']]['product_list'][] = $productinfo;
if (!isset($orderPackage[$id_address][$hotelProduct['id_hotel']]['id_hotel'])) {
$orderPackage[$id_address][$hotelProduct['id_hotel']]['id_hotel'] = $hotelProduct['id_hotel'];

View File

@@ -547,57 +547,72 @@ product_tabs['Informations'] = new function(){
};
this.switchProductType = function(){
function toggleAssociationFieldNames(containerSelector, shouldShow)
{
var $container = $(containerSelector);
if (shouldShow) {
$container.show('fast').find('input').each(function() {
$(this).attr('name', $(this).attr('data-name'));
$(this).removeAttr('data-name');
});
} else {
$container.hide('fast').find('input').each(function() {
$(this).attr('data-name', $(this).attr('name'));
$(this).removeAttr('name');
});
}
}
function applySellingPreferenceUIState()
{
var sellingPreference = parseInt($('#selling_preference_type').val(), 10);
var showHotelTree = $.inArray(sellingPreference, [
SELLING_PREFERENCE_HOTEL_STANDALONE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE
]) !== -1;
var showRoomTypeTree = $.inArray(sellingPreference, [
0,
SELLING_PREFERENCE_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE
]) !== -1;
var showAutoAddToCart = $.inArray(sellingPreference, [
0,
SELLING_PREFERENCE_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE,
SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE
]) !== -1;
var $autoAddOff = $('#auto_add_to_cart_off');
var $autoAddCheckedInput;
toggleAssociationFieldNames('#associated_hotel_tree', showHotelTree);
toggleAssociationFieldNames('#associated_hotel_rooms_tree', showRoomTypeTree);
if (showAutoAddToCart) {
$('#auto_add_to_cart_container').show('fast');
$autoAddCheckedInput = $('input[name="auto_add_to_cart"]:checked');
if (!$autoAddCheckedInput.length) {
$autoAddOff.prop('checked', true);
$autoAddCheckedInput = $autoAddOff;
}
} else {
$autoAddOff.prop('checked', true);
$('#auto_add_to_cart_container').hide('fast');
$autoAddCheckedInput = $autoAddOff;
}
$autoAddCheckedInput.trigger('change');
$('#product_options').show('fast');
}
$('#selling_preference_type').on('change',function(){
if (parseInt($(this).val()) == SELLING_PREFERENCE_WITH_ROOM_TYPE) {
$('#associated_hotel_tree').hide('fast').find('input').each(function() {
$(this).attr('data-name', $(this).attr('name'));
$(this).removeAttr('name');
});
$('#associated_hotel_rooms_tree').show('fast').find('input').each(function() {
$(this).attr('name', $(this).attr('data-name'));
$(this).removeAttr('data-name');
});
$('#auto_add_to_cart_container').show('fast');
$('#show_at_front_container').show('fast');
$('#product_options').show('fast');
} else if (parseInt($(this).val()) == SELLING_PREFERENCE_HOTEL_STANDALONE) {
$('#associated_hotel_rooms_tree').hide('fast').find('input').each(function() {
$(this).attr('data-name', $(this).attr('name'));
$(this).removeAttr('name');
});
$('#associated_hotel_tree').show('fast').find('input').each(function() {
$(this).attr('name', $(this).attr('data-name'));
$(this).removeAttr('data-name');
});
$('#auto_add_to_cart_container').hide('fast');
$('#show_at_front_container').show('fast');
$('#product_options').show('fast');
} else if (parseInt($(this).val()) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) {
$('#associated_hotel_rooms_tree').show('fast').find('input').each(function() {
$(this).attr('name', $(this).attr('data-name'));
$(this).removeAttr('data-name');
});
$('#associated_hotel_tree').show('fast').find('input').each(function() {
$(this).attr('name', $(this).attr('data-name'));
$(this).removeAttr('data-name');
});
$('#auto_add_to_cart_container').hide('fast');
$('#show_at_front_container').show('fast');
$('#product_options').show('fast');
} else if (parseInt($(this).val()) == SELLING_PREFERENCE_STANDALONE) {
$('#associated_hotel_rooms_tree').hide('fast').find('input').each(function() {
$(this).attr('data-name', $(this).attr('name'));
$(this).removeAttr('name');
});
$('#associated_hotel_tree').hide('fast').find('input').each(function() {
$(this).attr('data-name', $(this).attr('name'));
$(this).removeAttr('name');
});
$('#auto_add_to_cart_container').hide('fast');
$('#show_at_front_container').show('fast');
$('#product_options').show('fast');
}
setTimeout(function() {
applySellingPreferenceUIState();
}, 0);
});
$('#selling_preference_type').trigger('change');
$('#simple_product').attr('checked', true);