Fixed: issues in webservices and removed the specific managemenet qlo webservice and non required functions

This commit is contained in:
vishalsingh.qlo325
2025-06-05 11:51:38 +05:30
parent 0540eadbeb
commit 03bc902ea9
10 changed files with 45 additions and 1019 deletions

View File

@@ -171,19 +171,22 @@ class ImageCore extends ObjectModel
* @param int $id_product_attribute Product Attribute ID
* @return array Images
*/
public static function getImages($id_lang, $id_product, $id_product_attribute = null)
public static function getImages($id_lang, $id_product, $id_product_attribute = null, $bookingProduct = null)
{
$attribute_filter = ($id_product_attribute ? ' AND ai.`id_product_attribute` = '.(int)$id_product_attribute : '');
$sql = 'SELECT *
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image`)';
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image`)
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = i.`id_product`)';
if ($id_product_attribute) {
$sql .= ' LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` ai ON (i.`id_image` = ai.`id_image`)';
}
$sql .= ' WHERE i.`id_product` = '.(int)$id_product.' AND il.`id_lang` = '.(int)$id_lang.$attribute_filter.'
'.(!is_null($bookingProduct) ? ' AND p.`booking_product`='.(int) $bookingProduct : '').'
ORDER BY i.`position` ASC';
return Db::getInstance()->executeS($sql);
}
@@ -215,12 +218,14 @@ class ImageCore extends ObjectModel
*
* @return array Images
*/
public static function getAllImages()
public static function getAllImages($bookingProduct = null)
{
return Db::getInstance()->executeS('
SELECT `id_image`, `id_product`
FROM `'._DB_PREFIX_.'image`
ORDER BY `id_image` ASC');
SELECT img.`id_image`, img.`id_product` FROM `'._DB_PREFIX_.'image` img
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = img.`id_product`
WHERE 1 '.(!is_null($bookingProduct) ? ' AND p.`booking_product`='.(int) $bookingProduct : '').'
ORDER BY `id_image` ASC'
);
}
/**

View File

@@ -542,7 +542,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
return array(
array(
'adults' => isset($data['adult']) && $data['adult'] ? $data['adult'] : $roomTypeInfo['adults'],
'adults' => isset($data['adults']) ? $data['adults'] : $roomTypeInfo['adults'],
'children' => isset($data['child']) ? $data['child'] : $roomTypeInfo['children'],
'child_ages' => $child_ages
)
@@ -946,7 +946,9 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$extraVars,
null,
false,
$this->bookingCustomer->secure_key
$this->bookingCustomer->secure_key,
null,
false
)) {
$this->updateServicesAndDemandsInOrder($objPaymentModule->currentOrder);
if (!empty($this->wsRequestedRooms)) {
@@ -1081,7 +1083,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$objTaxManager = TaxManagerFactory::getManager($objAddress, $this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group']);
$objTaxCalculator = $objTaxManager->getTaxCalculator();
$priceWithTax = $objTaxCalculator->addTaxes($objHotelBookingDetail->total_price_tax_excl);
} else if (isset($this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'])) {
} else if (!empty($this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'])) {
$priceWithTax = $objHotelBookingDetail->total_price_tax_excl + $this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'];
}
@@ -1216,9 +1218,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$objOrder->total_paid_tax_incl += $priceDiffTaxIncl;
$objOrder->total_paid += $priceDiffTaxIncl;
} else if (isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'])
&& $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax']
) {
} else if (!empty($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'])) {
$oldPriceTaxIncl = $objServiceProductOrderDetail->total_price_tax_incl;
$objServiceProductOrderDetail->total_price_tax_incl = $objServiceProductOrderDetail->total_price_tax_excl + $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'];
@@ -1697,7 +1697,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$this->wsRequestedRoomTypes[$dateRoomJoinKey]['room'] = $room;
if (isset($room['id_tax_rules_group']) && Validate::isLoadedObject(new TaxRulesGroup((int) $room['id_tax_rules_group']))) {
$this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group'] = $room['id_tax_rules_group'];
} else if (isset($room['total_tax'])) {
} else if (!empty($room['total_tax'])) {
$this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'] = $room['total_tax'];
}
@@ -1946,13 +1946,13 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
if (isset($room['id_tax_rules_group']) && Validate::isLoadedObject(new TaxRulesGroup((int) $room['id_tax_rules_group']))) {
$this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group'] = $room['id_tax_rules_group'];
} else if (isset($room['total_tax'])) {
} else if (!empty($room['total_tax'])) {
$this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'] = $room['total_tax'];
}
$numDays = HotelHelper::getNumberOfDays($dateFrom, $dateTo);
if (isset($room['unit_price_without_tax'])
&& ((float) $room['unit_price_without_tax']) != ((float) $roomsByDate['order'][$roomsKey]['total_price_tax_incl']/$numDays)
&& ((float) $room['unit_price_without_tax']) != ((float) $roomsByDate['order'][$roomsKey]['total_price_tax_excl']/$numDays)
) {
$this->updateRoomPriceInOrder($room, $roomsByDate['order'][$roomsKey]);
$this->wsRequestedRoomTypes[$dateRoomJoinKey]['room'] = $room;
@@ -2314,7 +2314,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$unitPriceTaxIncl = Tools::ps_round($unitPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_);
$totalPriceTaxIncl = Tools::ps_round(($unitPriceTaxIncl * $quantity), _PS_PRICE_COMPUTE_PRECISION_);
} else if (isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'])) {
} else if (!empty($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'])) {
$totalPriceTaxIncl = $totalPriceTaxExcl + $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'];
$totalPriceTaxIncl = Tools::ps_round(($totalPriceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
@@ -2876,7 +2876,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
if (isset($room['id_tax_rules_group']) && !Validate::isLoadedObject(new TaxRulesGroup((int) $room['id_tax_rules_group']))) {
$this->error_msg = Tools::displayError('Invalid id_tax_rules_group.');
return false;
} else if (isset($room['total_tax']) && !Validate::isPrice($room['total_tax'])) {
} else if (!empty($room['total_tax']) && !Validate::isPrice($room['total_tax'])) {
$this->error_msg = Tools::displayError('Invalid total tax.');
return false;
}
@@ -3243,7 +3243,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$unitPriceTaxIncl = Tools::ps_round($unitPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_);
$totalPriceTaxIncl = Tools::ps_round(($unitPriceTaxIncl * $quantity), _PS_PRICE_COMPUTE_PRECISION_);
} else if (isset($services[$product['id_product']]['total_tax'])) {
} else if (!empty($services[$product['id_product']]['total_tax'])) {
$totalPriceTaxIncl = $totalPriceTaxExcl + $services[$product['id_product']]['total_tax'];
$totalPriceTaxIncl = Tools::ps_round(($totalPriceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);

View File

@@ -51,7 +51,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
'room_types' => array(),
'hotels' => array(),
'categories' => array(),
'extra_service' => array(),
'services' => array(),
// 'manufacturers' => array(),
// 'suppliers' => array(),
// 'stores' => array(),
@@ -288,7 +288,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$this->imageType = $this->wsObject->urlSegment[1];
// if image type requested is room_types then process products images
if ($this->imageType == 'room_types'
|| $this->imageType == 'extra_services'
|| $this->imageType == 'services'
) {
$this->imageType = 'products';
}
@@ -305,7 +305,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
case 'stores':
case 'features':
case 'hotels':
case 'extra_services':
case 'services':
case 'room_types':
switch ($this->wsObject->urlSegment[1]) {
case 'categories':
@@ -326,7 +326,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
case 'room_types':
$directory = _PS_PROD_IMG_DIR_;
break;
case 'extra_services':
case 'services':
$directory = _PS_PROD_IMG_DIR_;
break;
case 'hotels':
@@ -511,14 +511,20 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
if ($this->imageType == 'products') {
$ids = array();
$images = Image::getAllImages();
if ($this->wsObject->urlSegment[1] == 'services') {
$resourceType = 'services';
$images = Image::getAllImages(0);
} else {
$resourceType = 'room_types';
$images = Image::getAllImages(1);
}
foreach ($images as $image) {
$ids[] = $image['id_product'];
}
$ids = array_unique($ids, SORT_NUMERIC);
asort($ids);
foreach ($ids as $id) {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.'room_types'.'/'.$id), false);
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.$resourceType.'/'.$id), false);
}
} else if ($this->imageType == 'hotels') {
$ids = array();
@@ -567,10 +573,17 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
if ($this->imageType == 'products') {
// Get available image ids
$available_image_ids = array();
if ($this->wsObject->urlSegment[1] == 'services') {
$resourceType = 'services';
$bookingProduct = 0;
} else {
$bookingProduct = 1;
$resourceType = 'room_types';
}
// New Behavior
foreach (Language::getIDs() as $id_lang) {
foreach (Image::getImages($id_lang, $object_id) as $image) {
foreach (Image::getImages($id_lang, $object_id, null, $bookingProduct) as $image) {
$available_image_ids[] = $image['id_image'];
}
}
@@ -607,7 +620,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
if ($available_image_ids) {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id'=>$object_id));
foreach ($available_image_ids as $available_image_id) {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('declination', array(), array('id'=>$available_image_id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.'room_types'.'/'.$object_id.'/'.$available_image_id), false);
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('declination', array(), array('id'=>$available_image_id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.$resourceType.'/'.$object_id.'/'.$available_image_id), false);
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image', array());
} else {

View File

@@ -38,6 +38,7 @@
{$rm_v['num_rm']}
</td>
<td>
{if !isset($show_full_date)}{assign var="show_full_date" value=0}{/if}
{assign var="is_full_date" value=($show_full_date && ($rm_v['data_form']|date_format:'%D' == $rm_v['data_to']|date_format:'%D'))}
{$rm_v['data_form']|date_format:"%d-%b-%G"}{if $is_full_date} {$rm_v['data_form']|date_format:"%I:%M %p"}{/if}
</td>

View File

@@ -257,361 +257,6 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
return $specialDaysCount;
}
/**
* [getHotelRoomTypesRatesByDate returns hotel room types rates accrding to feature price plans]
* @param [int] $id_hotel [id of th hotel]
* @param integer $id_product [id of the product if supplied only rates of this room type will be returned]
* @param [date] $date_from [start date of the date range]
* @param [date] $date_to [end date of the date range]
* @return [array|false] [returns array containing rates of room type of a hotel if found else returns false]
*/
public function getHotelRoomTypesRatesAndInventoryByDate($id_hotel, $id_product, $date_from, $date_to)
{
$hotelRoomType = new HotelRoomType();
$context = Context::getContext();
$roomTypeRatesAndInventory = array();
$objBookingDetail = new HotelBookingDetail();
$incr = 0;
$date_from = date('Y-m-d', strtotime($date_from));
$date_to = date('Y-m-d', strtotime($date_to));
for($date = $date_from; $date < $date_to; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) {
$currentDate = date('Y-m-d', strtotime($date));
$nextDayDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)));
if ($id_product) {
$bookingParams = array(
'date_from' => $currentDate,
'date_to' => $nextDayDate,
'hotel_id' => $id_hotel,
'id_room_type' => $id_product,
'only_search_data' => 1,
);
$roomTypeAvailabilityInfo = $objBookingDetail->dataForFrontSearch($bookingParams);
if (isset($roomTypeAvailabilityInfo['stats']['num_avail'])) {
$totalAvailableRooms = $roomTypeAvailabilityInfo['stats']['num_avail'];
} else {
$totalAvailableRooms = 0;
}
$roomTypePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($id_product, $currentDate, $nextDayDate);
$roomTypeRatesAndInventory[$incr]['date'] = $currentDate;
$roomTypeRatesAndInventory[$incr]['room_types'][0]['id'] = $id_product;
$roomTypeRatesAndInventory[$incr]['room_types'][0]['rates'] = $roomTypePrice;
$roomTypeRatesAndInventory[$incr]['room_types'][0]['available_rooms'] = $totalAvailableRooms;
} else {
$hotelRoomTypes = $hotelRoomType->getRoomTypeByHotelId($id_hotel, $context->language->id);
if ($hotelRoomTypes) {
$roomTypeRatesAndInventory[$incr]['date'] = $currentDate;
foreach ($hotelRoomTypes as $key => $product) {
$roomTypePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$currentDate,
$nextDayDate
);
$bookingParams = array(
'date_from' => $currentDate,
'date_to' => $nextDayDate,
'hotel_id' => $id_hotel,
'id_room_type' => $product['id_product'],
'only_search_data' => 1,
);
$roomTypeAvailabilityInfo = $objBookingDetail->dataForFrontSearch($bookingParams);
if (isset($roomTypeAvailabilityInfo['stats']['num_avail'])) {
$totalAvailableRooms = $roomTypeAvailabilityInfo['stats']['num_avail'];
} else {
$totalAvailableRooms = 0;
}
$roomTypeRatesAndInventory[$incr]['room_types'][$key]['id'] = $product['id_product'];
$roomTypeRatesAndInventory[$incr]['room_types'][$key]['rates'] = $roomTypePrice;
$roomTypeRatesAndInventory[$incr]['room_types'][$key]['available_rooms'] = $totalAvailableRooms;
}
} else {
return false;
}
}
$incr++;
}
return $roomTypeRatesAndInventory;
}
/**
* [updateRoomTypesFeaturePrices update and creates feature price plans by supplied information]
* @param [array] $featurePricePlans [feature price plans sent from channel manager]
* @return [array] [success if process is finished successfully else fasiled with errors]
* @information [if any feature price plan for the same date_from and date_to(supplied in the $featurePricePlans array) it will be updated otherwise it is added. While adding date range type rate plans if any plan already exist then feature price for all specific dates in the date range will be created (or updated if specific date feature price plan exists)]
*/
public function updateRoomTypesFeaturePricesAvailability($featurePricePlans)
{
$errors = [];
if ($featurePricePlans) {
if (isset($featurePricePlans['data']) && $featurePricePlans['data']) {
foreach ($featurePricePlans['data'] as $roomTypeRatesData) {
$dateFrom = date('Y-m-d', strtotime($roomTypeRatesData['dateFrom']));
$dateTo = date('Y-m-d', strtotime('+1 day', strtotime($roomTypeRatesData['dateTo'])));
if ($roomTypeRatesData['roomType']) {
foreach ($roomTypeRatesData['roomType'] as $key => $roomTypeRates) {
$id_product = $key;
// feature price rates create and updates
if (isset($roomTypeRates['rate'])) {
$productPriceTE = Product::getPriceStatic((int) $id_product, false);
if ($productPriceTE != $roomTypeRates['rate']) {
if ($productPriceTE > $roomTypeRates['rate']) {
$priceImpactWay = 1;
$impactValue = $productPriceTE - $roomTypeRates['rate'];
} else {
$priceImpactWay = 2;
$impactValue = $roomTypeRates['rate'] - $productPriceTE;
}
$params = array();
$params['roomTypeId'] = $id_product;
$params['featurePriceName'] = 'Webservice Feature Price';
$params['dateFrom'] = $dateFrom;
$featurePriceDateTo = date('Y-m-d', (strtotime($dateTo) - _TIME_1_DAY_));
$params['dateTo'] = $featurePriceDateTo;
$params['priceImpactWay'] = $priceImpactWay;
$params['isSpecialDaysExists'] = 0;
$params['jsonSpecialDays'] = null;
$params['priceImpactType'] = 2;
$params['impactValue'] = $impactValue;
$params['enableFeaturePrice'] = 1;
$nextDate = date('Y-m-d', strtotime('+1 day', strtotime($dateFrom)));
if ($nextDate == $dateTo) {
$params['dateSelectionType'] = self::DATE_SELECTION_TYPE_SPECIFIC;
$featurePriceExists = $this->checkRoomTypeFeaturePriceExistance(
$id_product,
$dateFrom,
$featurePriceDateTo,
'specific_date'
);
if ($featurePriceExists) {
if (!$this->saveFeaturePricePlan(2, $params, $featurePriceExists['id'])) {
$errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId'];
}
} else {
if (!$this->saveFeaturePricePlan(2, $params, 0)) {
$errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId'];
}
}
} else {
$params['dateSelectionType'] = self::DATE_SELECTION_TYPE_RANGE;
if ($featurePriceExists = $this->checkRoomTypeFeaturePriceExistance(
$id_product,
$dateFrom,
$featurePriceDateTo,
'date_range'
)) {
if ($featurePriceExists['date_from'] == $dateFrom
&& $featurePriceExists['date_to'] == $featurePriceDateTo
) {
if (!$this->saveFeaturePricePlan(
1,
$params,
$featurePriceExists['id']
)) {
$errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId'];
}
} else {
for($date = $dateFrom; $date < $dateTo; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) {
// Creating feature prices day wise, for single days.
$nextDayDate = $currentDate = date('Y-m-d', $date);
$params['dateFrom'] = $currentDate;
$params['dateTo'] = $nextDayDate;
$params['dateSelectionType'] = self::DATE_SELECTION_TYPE_SPECIFIC;
$featurePriceExists = $this->checkRoomTypeFeaturePriceExistance(
$id_product,
$currentDate,
$nextDayDate,
'specific_date'
);
if ($featurePriceExists) {
if (!$this->saveFeaturePricePlan(
2,
$params,
$featurePriceExists['id']
)) {
$errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId'];
}
} else {
if (!$this->saveFeaturePricePlan(2, $params, 0)) {
$errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId'];
}
}
}
}
} else {
if (!$this->saveFeaturePricePlan(1, $params, 0)) {
$errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId'];
}
}
}
}
}
if (isset($roomTypeRates['inventory'])) {
$totalAvailableNotBooked = 0;
$totalAvailableRooms = 0;
$hotelRoomType = new HotelRoomType();
$hotelBookingDetail = new HotelBookingDetail();
$hotelRoomInformation = new HotelRoomInformation();
$roomTypeInfo = $hotelRoomType->getRoomTypeInfoByIdProduct($id_product);
$id_hotel = $roomTypeInfo['id_hotel'];
if ($id_hotel) {
$bookingParams = array(
'date_from' => $dateFrom,
'date_to' => $dateTo,
'hotel_id' => $id_hotel,
'id_room_type' => $id_product,
'only_search_data' => 1,
);
$roomTypeAvailabilityInfo = $hotelBookingDetail->dataForFrontSearch($bookingParams);
$bookedRoomsInfo = $hotelRoomInformation->getRoomTypeBookedRoomsForDateRange(
$id_hotel,
$id_product,
$dateFrom,
$dateTo
);
$countBookedRooms = count($bookedRoomsInfo);
if (isset($roomTypeAvailabilityInfo['stats']['total_rooms'])) {
$totalAvailableNotBooked = $roomTypeAvailabilityInfo['stats']['total_rooms'] - $countBookedRooms;
$totalAvailableRooms = $roomTypeAvailabilityInfo['stats']['num_avail'];
}
if ($roomTypeRates['inventory'] <= $totalAvailableNotBooked) {
if ($roomTypeRates['inventory'] < $totalAvailableRooms) {
$numDisabledRooms = $totalAvailableRooms - $roomTypeRates['inventory'];
$availableRooms = $hotelRoomInformation->getRoomTypeAvailableRoomsForDateRange(
$id_hotel,
$id_product,
$dateFrom,
$dateTo
);
if ($availableRooms) {
foreach ($availableRooms as $room) {
$objRoomDisableDates = new HotelRoomDisableDates();
$params['id_room'] = $room['id'];
$params['date_from'] = $dateFrom;
$params['date_to'] = $dateTo;
if (!($objRoomDisableDates->checkIfRoomAlreadyDisabled($params))) {
if ($numDisabledRooms > 0) {
$hotelRoomInformation = new HotelRoomInformation($room['id']);
if ($hotelRoomInformation->id_status == 3) {
$params['reason'] = $this->moduleInstance->l('Disabled from channel manager.', 'HotelRoomTypeFeaturePricing');
if (!$objRoomDisableDates->updateDisableDateRanges(
$params
)) {
$errors[] = $this->moduleInstance->l('Some error occurred while saving disable dates for '.$dateFrom.' To '.$dateTo.' for room id-'.$room['id'], 'HotelRoomTypeFeaturePricing');
}
} else {
$hotelRoomInformation->id_status = 3;
if ($hotelRoomInformation->save()) {
$objRoomDisableDates = new HotelRoomDisableDates();
$objRoomDisableDates->id_room = $room['id'];
$objRoomDisableDates->date_from = $dateFrom;
$objRoomDisableDates->date_to = $dateTo;
$objRoomDisableDates->reason = $this->moduleInstance->l('Disabled from channel manager.', 'HotelRoomTypeFeaturePricing');
$objRoomDisableDates->save();
}
}
$numDisabledRooms--;
}
}
}
}
} elseif ($roomTypeRates['inventory'] > $totalAvailableRooms) {
$roomsToEnable = $roomTypeRates['inventory'] - $totalAvailableRooms;
$disabledRooms = $hotelRoomInformation->getRoomTypeDisabledRoomsForDateRange(
$id_hotel,
$id_product,
$dateFrom,
$dateTo
);
if ($disabledRooms) {
foreach ($disabledRooms as $disableRoom) {
if ($roomsToEnable > 0) {
$hotelRoomInformation = new HotelRoomInformation($disableRoom['id']);
$objRoomDisableDates = new HotelRoomDisableDates();
$params['id_room'] = $disableRoom['id'];
$params['date_from'] = $dateFrom;
$params['date_to'] = $dateTo;
if (!$objRoomDisableDates->deleteDisabledDatesForDateRange(
$params
)) {
$errors[] = $this->moduleInstance->l('Some error occurred while saving deleting dates for '.$dateFrom.' To '.$dateTo.' for room id-'.$disableRoom['id'], 'HotelRoomTypeFeaturePricing');
}
$disabledDates = $objRoomDisableDates->getRoomDisableDates(
$disableRoom['id']
);
if (!count($disabledDates)) {
$hotelRoomInformation->id_status = 1;
$hotelRoomInformation->disabled_dates = null;
}
$hotelRoomInformation->save();
}
$roomsToEnable--;
}
}
}
}
}
} else {
$errors[] = $this->moduleInstance->l('Requested rooms inventory is not available.', 'HotelRoomTypeFeaturePricing');
}
}
} else {
$errors[] = $this->moduleInstance->l('Room Types for which Feature prices to be updated are not found.', 'HotelRoomTypeFeaturePricing');
}
}
} else {
$errors[] = $this->moduleInstance->l('Update Information not found.', 'HotelRoomTypeFeaturePricing');
}
} else {
$errors[] = $this->moduleInstance->l('Update Information not found.', 'HotelRoomTypeFeaturePricing');
}
$result = array();
if (count($errors)) {
$result['status'] = 'failed';
$result['errors'] = $errors;
} else {
$result['status'] = 'success';
}
return $result;
}
/**
* [saveFeaturePricePlan add or update feature price plan]
* @param [int] $dateSelectionType [date selection type 1 or 2 (date range or specific date)]
* @param [array] $params [Room type rate plan info]
* @param integer $id [id of the feature price plan if 0 means to add else to update the feature price plan]
* @return [bool] [returns true is successfuly added or updated else returns false]
*/
public function saveFeaturePricePlan($dateSelectionType, $params, $id = 0)
{
if ($id) {
$roomTypeFeaturePricing = new HotelRoomTypeFeaturePricing($id);
} else {
$roomTypeFeaturePricing = new HotelRoomTypeFeaturePricing();
}
$roomTypeFeaturePricing->id_product = $params['roomTypeId'];
// lang fields
$languages = Language::getLanguages(false);
foreach ($languages as $language) {
$roomTypeFeaturePricing->feature_price_name[$language['id_lang']] = $params['featurePriceName'];
}
$roomTypeFeaturePricing->date_selection_type = $params['dateSelectionType'];
$roomTypeFeaturePricing->date_from = $params['dateFrom'];
$roomTypeFeaturePricing->date_to = $params['dateTo'];
$roomTypeFeaturePricing->impact_way = $params['priceImpactWay'];
$roomTypeFeaturePricing->is_special_days_exists = $params['isSpecialDaysExists'];
$roomTypeFeaturePricing->special_days = $params['jsonSpecialDays'];
$roomTypeFeaturePricing->impact_type = $params['priceImpactType'];
$roomTypeFeaturePricing->impact_value = $params['impactValue'];
$roomTypeFeaturePricing->active = $params['enableFeaturePrice'];
return $roomTypeFeaturePricing->save();
}
/**
* [getRoomTypeTotalPrice Returns Total price of the room type according to supplied dates].
*

View File

@@ -1,304 +0,0 @@
<?php
/**
* 2010-2020 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2020 Webkul IN
* @license https://store.webkul.com/license.html
*/
class QloRoomType extends QloWebservice
{
public function getRoomType($idHotel)
{
$objHotelRoomType = new HotelRoomType();
$idLang = $this->context->language->id;
$roomTypes = $objHotelRoomType->getRoomTypeByHotelId((int)$idHotel, $idLang);
$required = ['id', 'name', 'status'];
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_types', array());
foreach ($roomTypes as $roomType) {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_type', array());
$roomType['name'] = $roomType['room_type'];
$roomType['id'] = $roomType['id_product'];
$roomType['status'] = $roomType['active'];
foreach ($roomType as $key => $value) {
if (in_array($key, $required)) {
$this->output .= $this->renderField($key, $value);
}
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('room_type', array());
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('room_types', array());
return $this->output;
}
public function getRoomRates(array $params)
{
$objRoomTypeFeaturePrice = new HotelRoomTypeFeaturePricing();
$idProd = 0;
if (isset($params['idRoomType'])) {
$idProd = $params['idRoomType'];
}
$rates = $objRoomTypeFeaturePrice->getHotelRoomTypesRatesAndInventoryByDate($params['idHotel'], $idProd, $params['dateFrom'], $params['dateTo']);
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('getRoomRatesApi', array());
foreach ($rates as $datewiseRate) {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('rate_list', array());
foreach ($datewiseRate as $attr => $value) {
// how to put line written in else before if and no need to use else condition
if ($attr == 'room_types') {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_types', array());
foreach ($value as $roomType) {
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('room_type', array());
foreach ($roomType as $roomTypeAttr => $roomTypeData) {
if ($roomTypeAttr == 'rates') {
$roomTypeData['tax_inc'] = $roomTypeData['total_price_tax_incl'];
$roomTypeData['tax_exc'] = $roomTypeData['total_price_tax_excl'];
unset($roomTypeData['total_price_tax_incl']);
unset($roomTypeData['total_price_tax_excl']);
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('rate', array());
foreach ($roomTypeData as $rateAttr => $rate) {
$this->output .= $this->renderField($rateAttr, $rate);
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('rate', array());
} else {
$this->output .= $this->renderField($roomTypeAttr, $roomTypeData);
}
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('room_type', array());
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('room_types', array());
} else {
$this->output .= $this->renderField($attr, $value);
}
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('rate_list', array());
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('getRoomRatesApi', array());
return $this->output;
}
public function updRoomRateAvail($availRateData)
{
$hotelId = $availRateData['Hotel']['id'];
$formatedData = [
'propertyId' => $hotelId,
'data' => [],
];
$rateData = $availRateData['Hotel']['rate_lists']['rate_list'];
foreach ($rateData as $dateWise) {
$formateSubData = array();
$formateSubData['dateFrom'] = $dateWise['date_range']['date_from'];
$formateSubData['dateTo'] = $dateWise['date_range']['date_to'];
if (isset($dateWise['date_range']['RoomTypeLists']['RoomType']['id'])) {
$roomTypeDetail = $dateWise['date_range']['RoomTypeLists']['RoomType'];
$formateSubData['roomType'][$roomTypeDetail['id']]['status'] = $roomTypeDetail['status'];
if (isset($roomTypeDetail['rate'])) {
$formateSubData['roomType'][$roomTypeDetail['id']]['rate'] = $roomTypeDetail['rate'];
}
if (isset($roomTypeDetail['Inventory'])) {
$formateSubData['roomType'][$roomTypeDetail['id']]['inventory'] = $roomTypeDetail['Inventory'];
}
} else {
foreach ($dateWise['date_range']['RoomTypeLists']['RoomType'] as $roomTypeDetail) {
$formateSubData['roomType'][$roomTypeDetail['id']]['status'] = $roomTypeDetail['status'];
if (isset($roomTypeDetail['rate'])) {
$formateSubData['roomType'][$roomTypeDetail['id']]['rate'] = $roomTypeDetail['rate'];
}
if (isset($roomTypeDetail['Inventory'])) {
$formateSubData['roomType'][$roomTypeDetail['id']]['inventory'] = $roomTypeDetail['Inventory'];
}
}
}
$formatedData['data'][] = $formateSubData;
}
$objRoomTypeFeaturePrice = new HotelRoomTypeFeaturePricing();
$objRoomTypeFeaturePrice->updateRoomTypesFeaturePricesAvailability($formatedData);
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('success', array());
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('success', array());
return $this->output;
}
// /**
// * Get address details by id_address
// *
// * @api /getaddress
// * @param int $idAddress
// * @return xml output
// */
// public function getaddress($idAddress)
// {
// $address = new Address($idAddress);
// if (!Validate::isLoadedObject($address)) {
// return false;
// }
// // convert object to array
// $address = json_decode(json_encode($address), true);
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('address', array());
// $address['country'] = Country::getNameById($this->id_lang, $address['id_country']);
// $address['state'] = State::getNameById($address['id_state']);
// foreach ($address as $key => $addr) {
// $this->output .= $this->renderField($key, $addr);
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('address', array());
// return $this->output;
// }
// /**
// * [getCustomerAddress description]
// *
// * @api /getcustomeraddress
// * @param int $idCustomer
// * @return xml output
// */
// public function getCustomerAddress($idCustomer)
// {
// $customer = new Customer($idCustomer);
// if (!Validate::isLoadedObject($customer)) {
// return false;
// }
// $required = ['id', 'country', 'state', 'alias', 'company', 'lastname', 'firstname',
// 'address1', 'address2', 'postcode', 'city', 'other', 'other', 'phone_mobile', 'phone', 'deleted'];
// $addresses = $customer->getAddresses($this->id_lang);
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('addresses', array());
// foreach ($addresses as $address) {
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('address', array());
// $address['id'] = $address['id_address'];
// $address['country'] = Country::getNameById($this->id_lang, $address['id_country']);
// $address['state'] = State::getNameById($address['id_state']);
// foreach ($address as $key => $value) {
// if (in_array($key, $required)) {
// $this->output .= $this->renderField($key, $value);
// }
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('address', array());
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('addresses', array());
// return $this->output;
// }
// /**
// * Check is customer have his first address or not
// *
// * @api /checkfirstaddress
// * @param int $idCustomer
// * @return xml message
// */
// public function checkFirstAddressProcess($idCustomer)
// {
// if (Address::getFirstCustomerAddressId($idCustomer)) {
// return $this->getResult($this->mkmodule->l('Address exist for this customer.', 'mkaddress'), '1');
// }
// return $this->getResult($this->mkmodule->l('No address added by this customer yet.', 'mkaddress'), '0');
// }
// /**
// * Get required field in address from configuration
// *
// * @return xml node
// */
// public function addressConfiguration()
// {
// $requiredFields = AddressFormat::getFieldsRequired();
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('required_fields', array());
// $this->output .= $this->renderField('phone_config', Configuration::get('PS_ONE_PHONE_AT_LEAST'));
// foreach ($requiredFields as $field) {
// if ($field !== 'Country:name') {
// $this->output .= $this->renderField($field, 1);
// }
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('required_fields', array());
// }
// /**
// * Get country and state list
// *
// * @api /getcountrieswithstates
// * @return [type] [description]
// */
// public function getCountriesWithStatesProcess()
// {
// $countries = Country::getCountries($this->id_lang, true);
// $this->output .= $this->addressConfiguration();
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('countries', array());
// if ($countries) {
// foreach ($countries as $country) {
// // set if default country
// if ($country['id_country'] == Configuration::get('PS_COUNTRY_DEFAULT')) {
// $country['is_default'] = 1;
// } else {
// $country['is_default'] = 0;
// }
// // check if company field exist
// if ($this->isCompanyFieldAvailable($country['id_country'])) {
// $country['is_company'] = 1;
// } else {
// $country['is_company'] = 0;
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('country', array());
// $country['country_name'] = $country['country'];
// unset($country['country']);
// foreach ($country as $k => $c) {
// if ($k == 'states') {
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader($k, array());
// foreach ($c as $s) {
// $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('state', array());
// foreach ($s as $kkk => $ss) {
// $this->output .= $this->renderField($kkk, $ss);
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('state', array());
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter($k, array());
// } else {
// $this->output .= $this->renderField($k, $c);
// }
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('country', array());
// }
// }
// $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('countries', array());
// return $this->output;
// }
// /**
// * Is 'company' field available while adding address
// *
// * @param int $idCountry
// * @return boolean
// */
// public function isCompanyFieldAvailable($idCountry)
// {
// if (in_array('company', AddressFormat::getOrderedAddressFields($idCountry, true, true))) {
// return true;
// }
// return false;
// }
}

View File

@@ -1,145 +0,0 @@
<?php
/**
* 2010-2020 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2020 Webkul IN
* @license https://store.webkul.com/license.html
*/
class QloWebservice
{
protected $objOutput;
protected $output;
protected $wsObject;
protected $mobikulGlobal; // Remove this
protected $mkGlobal;
protected $mkmodule;
protected $http;
protected $width;
public function __construct($objOutput = null, $wsObject = null, $output = null)
{
$this->objOutput = $objOutput;
$this->wsObject = $wsObject;
$this->output = $output;
// Need to remove these three settings, this should be handled by context
// $this->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
// $this->id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
// $this->currency = Currency::getCurrencyInstance((int) Configuration::get('PS_CURRENCY_DEFAULT'));
$this->setContext();
// $this->mkmodule = Module::getInstanceByName('mobikul');
// $this->mobikulGlobal = new MobikulGlobal($this->id_lang, $objOutput, $wsObject, $output); // Remove this
// $this->mkGlobal = new MobikulGlobal($this->id_lang, $objOutput, $wsObject, $output);
}
public function setContext()
{
$this->context = Context::getContext();
// // Set Customer
// if (isset($this->wsObject->urlFragments['id_customer'])) {
// $this->context->customer = new Customer($this->wsObject->urlFragments['id_customer']);
// }
// // Set language
// if (isset($this->wsObject->urlFragments['id_lang'])) {
// $language = new Language($this->wsObject->urlFragments['id_lang']);
// if (!Validate::isLoadedObject($language)) {
// $language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
// }
// } else {
// $language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
// }
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$this->context->language = $language;
// // Set Currency
// if (isset($this->wsObject->urlFragments['id_currency'])) {
// $currency = new Currency($this->wsObject->urlFragments['id_currency']);
// if (!Validate::isLoadedObject($currency)) {
// $language = new Language((int)Configuration::get('PS_CURRENCY_DEFAULT'));
// }
// } else {
// $currency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'));
// }
$currency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'));
$this->context->currency = $currency;
}
public function getResult($message, $status = null, $args = array(), $xml = false)
{
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('response', array());
if ($status !== null) {
$this->output .= $this->renderField('status', $status);
}
$this->output .= $this->renderField('message', $message);
if (is_array($args) && !empty($args)) {
foreach ($args as $key => $value) {
$this->output .= $this->renderField($key, $value);
}
}
if ($xml) {
$this->output .= $xml;
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('response', array());
return $this->output;
}
/**
* Create just like PS renderField function in WebServiceOutputXML class
* @todo :: to be mode functional with attributes and others
* @param [type] $nodeName
* @param [type] $value
* @return [type] xml node
*/
public function renderField($nodeName, $value = null)
{
$node_content = '<![CDATA['.$value.']]>';
return '<'.$nodeName.'>'.$node_content.'</'.$nodeName.'>'."\n";
}
// public function displayPrice($price, $idCurrency = false)
// {
// if ($idCurrency) {
// $this->currency = Currency::getCurrencyInstance($idCurrency);
// } elseif (isset($this->wsObject->urlFragments['id_currency'])) {
// $this->currency = Currency::getCurrencyInstance($this->wsObject->urlFragments['id_currency']);
// } else {
// $this->currency = Currency::getCurrencyInstance((int) Configuration::get('PS_CURRENCY_DEFAULT'));
// }
// $defaultCurrencyInstance = Currency::getCurrencyInstance((int) Configuration::get('PS_CURRENCY_DEFAULT'));
// if (Validate::isLoadedObject($this->currency)) {
// $price = Tools::ps_round((float) $price, (int) $this->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
// $convertedPrice = Tools::convertPrice($price, $this->currency, $defaultCurrencyInstance);
// return Tools::displayPrice($convertedPrice, $this->currency);
// } else {
// return $price;
// }
// }
// public function getProductPrice($id_product, $tax = true, $id_product_attribute = null, $decimals = 6,
// $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null)
// {
// return Product::getPriceStatic((int)$id_product, $tax, $id_product_attribute, $decimals, $divisor, $only_reduc, $usereduc, $quantity, $force_associated_tax, $id_customer);
// }
}

View File

@@ -1,185 +0,0 @@
<?php
/**
* 2010-2020 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2020 Webkul IN
* @license https://store.webkul.com/license.html
*/
class WebserviceSpecificManagementQlo implements WebserviceSpecificManagementInterface
{
protected $objOutput;
protected $output;
protected $wsObject;
public $id_lang;
public $id_customer;
public $id_currency;
public $mobikulGlobal;
public function __construct()
{
ini_set('memory_limit', '256M');
$psCurrencyDefault = (int) Configuration::get('PS_CURRENCY_DEFAULT');
$this->context = Context::getContext();
$this->id_lang = Configuration::get('PS_LANG_DEFAULT');
$this->id_currency = $psCurrencyDefault;
$this->currency = Currency::getCurrencyInstance($psCurrencyDefault);
}
public function setObjectOutput(WebserviceOutputBuilderCore $obj)
{
$this->objOutput = $obj;
return $this;
}
public function getObjectOutput()
{
return $this->objOutput;
}
public function setWsObject(WebserviceRequestCore $obj)
{
$this->wsObject = $obj;
return $this;
}
public function getWsObject()
{
return $this->wsObject;
}
// written in alphabatical order
public function manage()
{
$this->wsQloCRUD();
return $this->wsObject->getOutputEnabled();
}
protected $allowedMethods = array(
'getRoomTypes' => array(),
'getRoomRates' => array(),
'updRoomRateAvail' => array(),
);
public function getContent()
{
if ($this->output != '') {
$outputXML = $this->objOutput->getObjectRender()->overrideContent($this->output);
if (isset($this->wsObject->urlFragments['outputformat']) && $this->wsObject->urlFragments['outputformat'] == 'json') {
$outputXML = simplexml_load_string($outputXML, null, LIBXML_NOCDATA);
$json = json_encode($outputXML);
$content = preg_replace_callback("/\\\\u([a-f0-9]{4})/", function ($matches) {
return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($matches[1])));
}, $json);
header('Content-Type: application/json');
die($content);
} else {
return $outputXML;
}
}
}
protected function wsQloCRUD()
{
$objQloRoomType = new QloRoomType($this->objOutput, $this->wsObject, $this->output);
switch ($this->wsObject->method) {
case 'GET':
switch ($this->wsObject->urlSegment[1]) {
case 'getRoomTypes':
if (!isset($this->wsObject->urlFragments['id_hotel'])) {
throw new WebserviceException('You have to set \'id_hotel\' parameter to get a result', array(100, 400));
}
$this->output .= $objQloRoomType->getRoomType($this->wsObject->urlFragments['id_hotel']);
break;
case 'getRoomRates':
if (!isset($this->wsObject->urlFragments['id_hotel']) ) {
throw new WebserviceException('You have to set \'id_hotel\', \'date_from\' and \'date_to\'parameters to get a result', array(100, 400));
}
$dateFrom = isset($this->wsObject->urlFragments['date_from']) ? $this->wsObject->urlFragments['date_from'] : date('Y-m-d');
$dateTo = isset($this->wsObject->urlFragments['date_to']) ? $this->wsObject->urlFragments['date_to'] : date('Y-m-d', strtotime($dateFrom.' + 1 day'));
$kwargs = array(
'idHotel' => $this->wsObject->urlFragments['id_hotel'],
'dateFrom' => $dateFrom,
'dateTo' => $dateTo,
'idRoomType' => isset($this->wsObject->urlFragments['id_room_type']) ? $this->wsObject->urlFragments['id_room_type'] : 0,
);
$this->output .= $objQloRoomType->getRoomRates($kwargs);
break;
default:
$exception = new WebserviceException(sprintf('Method with name "%s" does not exist in Qlo Library,', $this->wsObject->urlSegment[1]), array(48, 400));
throw $exception->setDidYouMean($this->wsObject->urlSegment[1], array_keys($this->allowedMethods));
}
break;
case 'POST':
switch ($this->wsObject->urlSegment[1]) {
case 'updRoomRateAvail':
$fields = $this->getXMLFields('updRoomRateAvail');
if (!isset($fields)) {
throw new WebserviceException('Send XML formated data', array(100, 400));
}
$this->output .= $objQloRoomType->updRoomRateAvail($fields);
break;
}
break;
default :
throw new WebserviceException('This HTTP method is not allowed', array(67, 405));
}
}
public function getXMLFields($head = false)
{
$putresource = fopen('php://input', 'r');
$inputXML = '';
while ($putData = fread($putresource, 1024)) {
$inputXML .= $putData;
}
fclose($putresource);
// If xml
if (simplexml_load_string($inputXML)) {
if (isset($inputXML) && strncmp($inputXML, 'xml=', 4) == 0) {
$inputXML = Tools::substr($inputXML, 4);
}
} else {
// If input type is json
$array = json_decode($inputXML, true);
if (isset($array['json']) && $array['json'] && isset($array[$head])) {
return ($head ? $array[$head] : $array);
} else {
WebserviceRequest::getInstance()->setError(500, 'Invalid json.', 127);
return;
}
}
try {
$xml = new SimpleXMLElement($inputXML);
} catch (Exception $error) {
WebserviceRequest::getInstance()->setError(500, 'XML error : '.$error->getMessage()."\n".'XML length : '.Tools::strlen($inputXML)."\n".'Original XML : '.$inputXML, 127);
return;
}
$xmlEntities = $xml->children();
// Convert multi-dimention xml into an array
$array = json_decode(json_encode($xmlEntities), true);
return ($head ? $array[$head] : $array);
}
}

View File

@@ -41,8 +41,6 @@ require_once 'classes/HotelRoomTypeDemandPrice.php';
require_once 'classes/HotelRoomTypeDemand.php';
require_once 'classes/HotelRoomTypeRestrictionDateRange.php';
require_once 'classes/QloWebservice.php';
require_once 'classes/QloRoomType.php';
require_once 'classes/HotelRoomDisableDates.php';
require_once 'classes/HotelBranchRefundRules.php';
require_once 'classes/HotelBedType.php';

View File

@@ -54,10 +54,8 @@ class HotelReservationSystem extends Module
'room_bookings' => array('description' => 'Room bookings', 'class' => 'HotelBookingDetail'),
'booking_extra_demands' => array('description' => 'Booking extra demands', 'class' => 'HotelBookingDemands'),
'extra_demands' => array('description' => 'Extra demands', 'class' => 'HotelRoomTypeGlobalDemand'),
'extra_services' => array('description' => 'Extra services', 'class' => 'Product', 'parameters_attribute' => 'webserviceRoomTypeServicesParameters'),
'demand_advance_options' => array('description' => 'Extra demand advance options', 'class' => 'HotelRoomTypeGlobalDemandAdvanceOption'),
'hotel_ari' => array('description' => 'Search availability, rates and inventory', 'specific_management' => true),
'qlo' => array('description' => 'qlo API', 'specific_management' => true),
);
return $resources;