Update: centralized the room price calculation process, updated function get getRoomTypeTotalPrice()

This commit is contained in:
vishalsingh.qlo325
2024-08-16 15:32:42 +05:30
parent 14e5b11b4a
commit 898477c76e
4 changed files with 71 additions and 13 deletions

View File

@@ -653,7 +653,18 @@ class ProductControllerCore extends FrontController
// calculate room type price first
$useTax = HotelBookingDetail::useTax();
$totalPrice = 0;
$productPriceWithoutReduction = $objProduct->getPriceWithoutReduct(!$useTax);
$priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$dateFrom,
$dateTo,
0,
0,
0,
0,
0,
1,
0
);
$roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$dateFrom,
@@ -669,6 +680,8 @@ class ProductControllerCore extends FrontController
true
);
$roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_incl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl'];
} else {
$featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay(
$idProduct,
@@ -677,9 +690,10 @@ class ProductControllerCore extends FrontController
false
);
$roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_excl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl'];
}
$featurePriceDiff = (float) ($productPriceWithoutReduction - $featurePrice);
$totalPriceWithoutDiscount *= $quantity;
$totalRoomPrice = $roomTypeDateRangePrice * $quantity;
// calculate demand price now
$demandsPricePerRoom = 0;
@@ -767,7 +781,6 @@ class ProductControllerCore extends FrontController
$demandsPrice = $demandsPricePerRoom * $quantity;
// calculate total price
$totalPrice = $totalRoomPrice + $demandsPrice;
$totalPriceWithoutDiscount = $objProduct->getPriceWithoutReduct(!$useTax, false, 6, 1) * $numDays * $quantity;
// send occupancy information searched by the user
if ($occupancy && is_array($occupancy)) {
$smartyVars['occupancies'] = $occupancy;

View File

@@ -1574,13 +1574,26 @@ class HotelCartBookingData extends ObjectModel
$data_v['id_room'],
0
);
$totalPriceWithoutDiscount = $objProduct->getPriceWithoutReduct(!$price_tax, false, 6, 1) * $numDays;
$priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
$data_v['date_to'],
0,
0,
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room'],
1,
0
);
if (!$price_tax) {
$amount = $roomTypeDateRangePrice['total_price_tax_excl'];
$amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_excl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl'];
} else {
$amount = $roomTypeDateRangePrice['total_price_tax_incl'];
$amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl'];
}
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] = $amount * $varQty;
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['total_price_without_discount'] = $totalPriceWithoutDiscount * $varQty;
@@ -1623,13 +1636,26 @@ class HotelCartBookingData extends ObjectModel
$data_v['id_room'],
0
);
$totalPriceWithoutDiscount = $objProduct->getPriceWithoutReduct(!$price_tax, false, 6, 1) * $numDays;
$priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
$data_v['date_to'],
0,
0,
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room'],
1,
0
);
if (!$price_tax) {
$amount = $roomTypeDateRangePrice['total_price_tax_excl'];
$amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_excl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl'];
} else {
$amount = $roomTypeDateRangePrice['total_price_tax_incl'];
$amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl'];
}
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] = $amount;
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount_without_auto_add'] = $amountWithoutAutoAdd;

View File

@@ -647,15 +647,16 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$id_cart = 0,
$id_guest = 0,
$id_room = 0,
$with_auto_room_services = 1
$with_auto_room_services = 1,
$usereduc = 1
) {
$totalPrice = array();
$totalPrice['total_price_tax_incl'] = 0;
$totalPrice['total_price_tax_excl'] = 0;
$featureImpactPriceTE = 0;
$featureImpactPriceTI = 0;
$productPriceTI = Product::getPriceStatic((int) $id_product, true);
$productPriceTE = Product::getPriceStatic((int) $id_product, false);
$productPriceTI = Product::getPriceStatic((int) $id_product, true, false, 6, null, false, $usereduc);
$productPriceTE = Product::getPriceStatic((int) $id_product, false, false, 6, null, false, $usereduc);
if ($productPriceTE) {
$taxRate = (($productPriceTI-$productPriceTE)/$productPriceTE)*100;
} else {
@@ -678,14 +679,14 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$date_from = date('Y-m-d', strtotime($date_from));
$date_to = date('Y-m-d', strtotime($date_to));
for($currentDate = $date_from; $currentDate < $date_to; $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) {
if ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority(
if ($usereduc && ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority(
$id_product,
$currentDate,
$id_group,
$id_cart,
$id_guest,
$id_room
)) {
))) {
if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) {
//percentage
$featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100);

View File

@@ -65,14 +65,32 @@ class WkHotelRoom extends Module
ImageType::getFormatedName('large')
);
}
$productPriceWithoutReduction = $product->getPriceWithoutReduct(!$useTax, false, 6, 1);
$productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$dateFrom,
$dateTo,
$useTax,
0,
0,
0,
0,
1,
0
);
if ($useTax) {
$priceWithoutReduction = $productPriceWithoutReduction['total_price_tax_incl'];
} else {
$priceWithoutReduction = $productPriceWithoutReduction['total_price_tax_excl'];
}
$product_price = Product::getPriceStatic($idProduct, $useTax);
$htlRoom['image'] = $prodImg;
$htlRoom['description'] = $product->description_short;
$htlRoom['name'] = $product->name;
$htlRoom['show_price'] = $product->show_price;
$htlRoom['price'] = $product_price;
$htlRoom['price_without_reduction'] = $productPriceWithoutReduction;
$htlRoom['price_without_reduction'] = $priceWithoutReduction;
$featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay(
$idProduct,
$dateFrom,
@@ -220,7 +238,7 @@ class WkHotelRoom extends Module
}
return true;
}
public function deleteConfigKeys()
{
$configVars = array(