Updated the data for front search function to get the data for the multiple room types at once
This commit is contained in:
@@ -1679,8 +1679,17 @@ class HotelBookingDetail extends ObjectModel
|
||||
|
||||
if (!$only_search_data) {
|
||||
if (!empty($bookingData)) {
|
||||
$objRoomType = new HotelRoomType();
|
||||
|
||||
$idProducts = array_keys($bookingData['rm_data']);
|
||||
$productsFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices(
|
||||
$idProducts,
|
||||
$date_from,
|
||||
$date_to
|
||||
);
|
||||
if (!($numDays = HotelHelper::getNumberOfDays($date_from, $date_to))) {
|
||||
$numDays = 1;
|
||||
}
|
||||
$useTax = self::useTax();
|
||||
$productsFeaturePriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices($idProducts, $date_from, $date_to, 0, 1, 0);
|
||||
foreach ($bookingData['rm_data'] as $key => $value) {
|
||||
$product_feature = Product::getFrontFeaturesStatic($this->context->language->id, $value['id_product']);
|
||||
$prod_amen = array();
|
||||
@@ -1699,14 +1708,23 @@ class HotelBookingDetail extends ObjectModel
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax());
|
||||
if ($useTax) {
|
||||
$prod_price = $productsFeaturePrice[$value['id_product']]['product_price_tax_incl'];
|
||||
$productFeaturePrice = $productsFeaturePrice[$value['id_product']]['total_price_tax_incl'] / $numDays;
|
||||
} else {
|
||||
$prod_price = $productsFeaturePrice[$value['id_product']]['product_price_tax_excl'];
|
||||
$productFeaturePrice = $productsFeaturePrice[$value['id_product']]['total_price_tax_excl'] / $numDays;
|
||||
}
|
||||
if (!empty($price) && ($price['from'] > $productFeaturePrice || $price['to'] < $productFeaturePrice)) {
|
||||
unset($bookingData['rm_data'][$key]);
|
||||
continue;
|
||||
}
|
||||
if (count($value['data']['available'])) {
|
||||
$prod_price = Product::getPriceStatic($value['id_product'], self::useTax());
|
||||
$productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 1, 0);
|
||||
if ($useTax) {
|
||||
$productPriceWithoutReduction = $productsFeaturePriceWithoutReduction[$value['id_product']]['total_price_tax_incl'] / $numDays;
|
||||
} else {
|
||||
$productPriceWithoutReduction = $productsFeaturePriceWithoutReduction[$value['id_product']]['total_price_tax_excl'] / $numDays;
|
||||
}
|
||||
$cover_image_arr = Product::getCover($value['id_product']);
|
||||
if (!empty($cover_image_arr)) {
|
||||
$cover_img = $this->context->link->getImageLink($value['link_rewrite'], $value['id_product'].'-'.$cover_image_arr['id_image'], 'home_default');
|
||||
|
||||
@@ -1415,6 +1415,63 @@ class HotelCartBookingData extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getProductsWiseFeaturePricePlansByDateRangeByPriority(
|
||||
$idProducts,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$idGroup
|
||||
) {
|
||||
$featurePricePriority = Configuration::get('HTL_FEATURE_PRICING_PRIORITY');
|
||||
if ($featurePricePriority = explode(';', $featurePricePriority)) {
|
||||
if ($featurePrices = Db::getInstance()->executeS(
|
||||
'SELECT fp.`id_feature_price`, fp.`id_product`, fp.`date_from`, fp.`date_to`, fp.`impact_way`, fp.`is_special_days_exists`,
|
||||
fp.`date_selection_type`, fp.`special_days`, fp.`impact_type`, fp.`impact_value`
|
||||
FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp'.
|
||||
(Group::isFeatureActive() ? ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg
|
||||
ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $idGroup.')' : '').'
|
||||
WHERE fp.`id_cart` = 0 AND fp.`id_product` IN('.implode(', ', $idProducts).') AND fp.`active`=1
|
||||
AND fp.`date_from` <= \''.pSQL($dateTo).'\' AND fp.`date_to` >= \''.pSQL($dateFrom).'\' '
|
||||
)) {
|
||||
$idProductsWisefeaturePrice = array();
|
||||
foreach ($featurePrices as $featurePriceKey => $featurePrice) {
|
||||
for ($currentDate = strtotime($featurePrice['date_from']); $currentDate <= strtotime($featurePrice['date_to']); $currentDate += _TIME_1_DAY_) {
|
||||
if (!isset($featurePrice['priority'])) {
|
||||
if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) {
|
||||
$featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('specific_date', $featurePricePriority);
|
||||
} else if ($featurePrice['is_special_days_exists']) {
|
||||
$featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('special_day', $featurePricePriority);
|
||||
} else if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) {
|
||||
$featurePrices[$featurePriceKey]['priority'] = $featurePrice['priority'] = array_search('date_range', $featurePricePriority);
|
||||
}
|
||||
}
|
||||
|
||||
if ((int) $featurePrice['is_special_days_exists']) {
|
||||
$specialDays = json_decode($featurePrice['special_days']);
|
||||
if (!in_array(strtolower(date('D', $currentDate)), $specialDays)) {
|
||||
continue;
|
||||
}
|
||||
} else if ($featurePrice['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC && $currentDate != strtotime($featurePrice['date_from'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate])
|
||||
&& $idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate]['priority'] > $featurePrice['priority']
|
||||
) {
|
||||
// replacing the feature prices if a feature price of more priority is available.
|
||||
$idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate] = $featurePrice;
|
||||
} else {
|
||||
$idProductsWisefeaturePrice[$featurePrice['id_product']][$currentDate] = $featurePrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $idProductsWisefeaturePrice;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns booking info of the current cart
|
||||
* @param integer $detailed : send 1 for detailedd info and 0 for normal info
|
||||
|
||||
@@ -45,9 +45,17 @@ class HotelOrderRestrictDate extends ObjectModel
|
||||
|
||||
public static function getDataByHotelId($idHotel)
|
||||
{
|
||||
return Db::getInstance()->getRow(
|
||||
'SELECT * FROM `'._DB_PREFIX_.'htl_order_restrict_date` ord WHERE ord.`id_hotel` = '.(int) $idHotel
|
||||
);
|
||||
$cache_key = 'HotelOrderRestrictDate::getDataByHotelId'.(int)$idHotel;
|
||||
if (!Cache::isStored($cache_key)) {
|
||||
$res = Db::getInstance()->getRow(
|
||||
'SELECT * FROM `'._DB_PREFIX_.'htl_order_restrict_date` ord WHERE ord.`id_hotel` = '.(int) $idHotel
|
||||
);
|
||||
Cache::store($cache_key, $res);
|
||||
} else {
|
||||
$res = Cache::retrieve($cache_key);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*Max date of ordering for order restrict*/
|
||||
|
||||
@@ -790,6 +790,151 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
return $totalPrice;
|
||||
}
|
||||
|
||||
public static function getRoomTypesTotalPrices(
|
||||
$idProducts = array(),
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$idGroup = 0,
|
||||
$withAutoRoomservices = 1,
|
||||
$useReduc = 1
|
||||
) {
|
||||
if (!$idProducts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initializations
|
||||
if (!$idGroup) {
|
||||
$idGroup = (int)Group::getCurrent()->id;
|
||||
}
|
||||
|
||||
// if dateFrom and dateTo are same then dateTo will be the next date date of dateFrom
|
||||
if (strtotime($dateFrom) == strtotime($dateTo)) {
|
||||
$dateTo = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($dateFrom)));
|
||||
}
|
||||
|
||||
|
||||
if ($withAutoRoomservices) {
|
||||
$servicesWithTax = RoomTypeServiceProduct::getAutoAddServicesByIdProducts(
|
||||
$idProducts,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
|
||||
true,
|
||||
$useReduc
|
||||
);
|
||||
$servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServicesByIdProducts(
|
||||
$idProducts,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
|
||||
false,
|
||||
$useReduc
|
||||
);
|
||||
}
|
||||
|
||||
$context = Context::getContext();
|
||||
$idCurrency = Validate::isLoadedObject($context->currency) ? (int)$context->currency->id : (int)Configuration::get('PS_CURRENCY_DEFAULT');
|
||||
$roomTypeWisePricing = array();
|
||||
foreach ($idProducts as $idProduct) {
|
||||
$productPriceTI = Product::getPriceStatic((int) $idProduct, true, false, 6, null, false, $useReduc);
|
||||
$productPriceTE = Product::getPriceStatic((int) $idProduct, false, false, 6, null, false, $useReduc);
|
||||
if ($productPriceTE) {
|
||||
$roomTypeWisePricing[$idProduct]['tax_rate'] = (($productPriceTI-$productPriceTE)/$productPriceTE)*100;
|
||||
} else {
|
||||
$roomTypeWisePricing[$idProduct]['tax_rate'] = 0;
|
||||
}
|
||||
|
||||
$roomTypeWisePricing[$idProduct]['product_price_tax_incl'] = $productPriceTI;
|
||||
$roomTypeWisePricing[$idProduct]['product_price_tax_excl'] = $productPriceTE;
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = 0;
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = 0;
|
||||
}
|
||||
|
||||
$featurePrices = HotelCartBookingData::getProductsWiseFeaturePricePlansByDateRangeByPriority(
|
||||
$idProducts,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$idGroup
|
||||
);
|
||||
|
||||
foreach ($idProducts as $idProduct) {
|
||||
for($currentDate = strtotime($dateFrom); $currentDate < strtotime($dateTo); $currentDate += _TIME_1_DAY_) {
|
||||
$featureImpactPriceTI = 0;
|
||||
$featureImpactPriceTE = 0;
|
||||
if ($useReduc && isset($featurePrices[$idProduct][$currentDate])) {
|
||||
$productPriceTI = $roomTypeWisePricing[$idProduct]['product_price_tax_incl'];
|
||||
$productPriceTE = $roomTypeWisePricing[$idProduct]['product_price_tax_excl'];
|
||||
$featurePrice = $featurePrices[$idProduct][$currentDate];
|
||||
if ($featurePrice['impact_type'] == self::IMPACT_TYPE_PERCENTAGE) {
|
||||
//percentage
|
||||
$featureImpactPriceTI = $productPriceTI * ($featurePrice['impact_value'] / 100);
|
||||
$featureImpactPriceTE = $productPriceTE * ($featurePrice['impact_value'] / 100);
|
||||
} else {
|
||||
//Fixed Price
|
||||
$taxPrice = ($featurePrice['impact_value'] * $roomTypeWisePricing[$idProduct]['tax_rate'])/100;
|
||||
$featureImpactPriceTE = Tools::convertPrice($featurePrice['impact_value'], $idCurrency);
|
||||
$featureImpactPriceTI = Tools::convertPrice($featurePrice['impact_value']+$taxPrice, $idCurrency);
|
||||
}
|
||||
|
||||
if ($featurePrice['impact_way'] == self::IMPACT_WAY_DECREASE) {
|
||||
// Decrease
|
||||
$priceWithFeatureTE = ($productPriceTE - $featureImpactPriceTE);
|
||||
$priceWithFeatureTI = ($productPriceTI - $featureImpactPriceTI);
|
||||
} elseif ($featurePrice['impact_way'] == self::IMPACT_WAY_INCREASE) {
|
||||
// Increase
|
||||
$priceWithFeatureTE = ($productPriceTE + $featureImpactPriceTE);
|
||||
$priceWithFeatureTI = ($productPriceTI + $featureImpactPriceTI);
|
||||
} else {
|
||||
// Fix
|
||||
$priceWithFeatureTE = $featureImpactPriceTE;
|
||||
$priceWithFeatureTI = $featureImpactPriceTI;
|
||||
}
|
||||
|
||||
if ($priceWithFeatureTI < 0) {
|
||||
$priceWithFeatureTI = 0;
|
||||
$priceWithFeatureTE = 0;
|
||||
}
|
||||
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += $priceWithFeatureTI;
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += $priceWithFeatureTE;
|
||||
} else {
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += $roomTypeWisePricing[$idProduct]['product_price_tax_incl'];
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += $roomTypeWisePricing[$idProduct]['product_price_tax_excl'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($withAutoRoomservices) {
|
||||
if (isset($servicesWithTax[$idProduct])) {
|
||||
foreach($servicesWithTax[$idProduct] as $service) {
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_incl'] += Tools::processPriceRounding($service['price']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($servicesWithoutTax[$idProduct])) {
|
||||
foreach($servicesWithoutTax[$idProduct] as $service) {
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_excl'] += Tools::processPriceRounding($service['price']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_excl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_excl']);
|
||||
$roomTypeWisePricing[$idProduct]['total_price_tax_incl'] = Tools::processPriceRounding($roomTypeWisePricing[$idProduct]['total_price_tax_incl']);
|
||||
}
|
||||
|
||||
Hook::exec('actionRoomTypesTotalPricesModifier',
|
||||
array(
|
||||
'total_prices' => &$roomTypeWisePricing,
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'id_currency' => $idCurrency,
|
||||
'id_group' => $idGroup,
|
||||
'use_reduc' => $useReduc,
|
||||
)
|
||||
);
|
||||
|
||||
return $roomTypeWisePricing;
|
||||
}
|
||||
|
||||
/**
|
||||
* [getRoomTypeFeaturePricePerDay returns per day feature price od the Room Type]
|
||||
* @param [int] $id_product [id of the product]
|
||||
|
||||
@@ -167,6 +167,41 @@ class RoomTypeServiceProduct extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getAutoAddServicesByIdProducts($idProducts = array(), $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $use_reduc = 1)
|
||||
{
|
||||
if ($idProducts) {
|
||||
$sql = 'SELECT p.`id_product`, `id_element` AS `id_room_type` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)
|
||||
WHERE p.`active` = 1 AND `id_element` IN( '.implode(', ', $idProducts).') AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE;
|
||||
if (!is_null($priceAdditionType)) {
|
||||
$sql .= ' AND p.`price_addition_type` = '.$priceAdditionType;
|
||||
}
|
||||
|
||||
if ($services = Db::getInstance()->executeS($sql)) {
|
||||
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
|
||||
$productWiseServices = array();
|
||||
foreach($services as $service) {
|
||||
$service['price'] = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$service['id_product'],
|
||||
(int)$service['id_room_type'],
|
||||
1,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$useTax,
|
||||
false,
|
||||
null,
|
||||
$use_reduc
|
||||
);
|
||||
$productWiseServices[$service['id_room_type']][] = $service;
|
||||
}
|
||||
|
||||
return $productWiseServices;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getServiceProductsData($idProductRoomType, $p = 1, $n = 0, $front = false, $available_for_order = 2, $auto_add_to_cart = 0, $subCategory = false, $idLang = false)
|
||||
{
|
||||
if (!$idLang) {
|
||||
|
||||
@@ -69,23 +69,30 @@ class RoomTypeServiceProductPrice extends ObjectModel
|
||||
|
||||
public static function getProductRoomTypePriceAndTax($idProduct, $idElement, $elementType)
|
||||
{
|
||||
if ($result = Db::getInstance()->getRow('
|
||||
SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp
|
||||
ON (sp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp
|
||||
ON (spp.`id_product` = sp.`id_product` AND spp.`id_element` = sp.`id_element` AND spp.`element_type` = sp.`element_type`)
|
||||
WHERE p.`id_product`='.(int)$idProduct.
|
||||
' AND sp.`id_element`='.(int)$idElement.
|
||||
' AND sp.`element_type`='.(int)$elementType)
|
||||
) {
|
||||
if ($result['auto_add_to_cart'] && $result['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM) {
|
||||
// if service is auto add to cart and added in room price, we need to find room type tax rule group
|
||||
if ($elementType == RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE) {
|
||||
$result['id_tax_rules_group'] = Product::getIdTaxRulesGroupByIdProduct((int)$idElement);
|
||||
$cache_key = 'RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax'.$idProduct.'_'.$idElement.'_'.$elementType;
|
||||
if (!Cache::isStored($cache_key)) {
|
||||
if ($result = Db::getInstance()->getRow('
|
||||
SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp
|
||||
ON (sp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp
|
||||
ON (spp.`id_product` = sp.`id_product` AND spp.`id_element` = sp.`id_element` AND spp.`element_type` = sp.`element_type`)
|
||||
WHERE p.`id_product`='.(int)$idProduct.
|
||||
' AND sp.`id_element`='.(int)$idElement.
|
||||
' AND sp.`element_type`='.(int)$elementType)
|
||||
) {
|
||||
if ($result['auto_add_to_cart'] && $result['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM) {
|
||||
// if service is auto add to cart and added in room price, we need to find room type tax rule group
|
||||
if ($elementType == RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE) {
|
||||
$result['id_tax_rules_group'] = Product::getIdTaxRulesGroupByIdProduct((int)$idElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Cache::store($cache_key, $result);
|
||||
} else {
|
||||
$result = Cache::retrieve($cache_key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -198,8 +198,24 @@ class wkhotelfilterblock extends Module
|
||||
|
||||
$prod_price = array();
|
||||
if ($room_types) {
|
||||
foreach ($room_types as $key => $value) {
|
||||
$prod_price[] = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, HotelBookingDetail::useTax());
|
||||
$idProducts = array_column($room_types, 'id_product');
|
||||
$productsFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypesTotalPrices(
|
||||
$idProducts,
|
||||
$date_from,
|
||||
$date_to
|
||||
);
|
||||
|
||||
$useTax = HotelBookingDetail::useTax();
|
||||
if (!($numDays = HotelHelper::getNumberOfDays($date_from, $date_to))) {
|
||||
$numDays = 1;
|
||||
}
|
||||
|
||||
foreach ($room_types as $value) {
|
||||
if ($useTax) {
|
||||
$prod_price[] = $productsFeaturePrice[$value['id_product']]['total_price_tax_incl'] / $numDays;
|
||||
} else {
|
||||
$prod_price[] = $productsFeaturePrice[$value['id_product']]['total_price_tax_excl'] / $numDays;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user