From a63409fa08716568c473ec845c330db1019c5269 Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Wed, 4 Feb 2026 18:40:36 +0530 Subject: [PATCH 1/4] manage custom filter for booking list --- .../WebserviceSpecificManagementBookings.php | 189 ++++++++++++++++-- 1 file changed, 177 insertions(+), 12 deletions(-) diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 10e52dab0f..8f7cb4f85f 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -158,6 +158,40 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We ) ); + public $allowedFilters = array( + 'id_hotel' => 'o.id_hotel', + 'id_customer' => 'o.id_customer', + 'id_order' => 'o.id_order', + 'id_order_status' => 'o.current_state', + 'reference' => 'o.reference', + 'check_in' => 'hbd.check_in', + 'check_out' => 'hbd.check_out', + 'date_from' => 'hbd.date_from', + 'date_to' => 'hbd.date_to', + 'room_type' => 'hbd.id_product', + 'total_price_tax_excl' => 'hbd.total_price_tax_excl', + 'total_price_tax_incl' => 'hbd.total_price_tax_incl', + 'total_paid_amount' => 'hbd.total_paid_amount', + 'is_refunded' => 'hbd.is_refunded', + 'room_num' => 'hbd.room_num', + 'hotel_name' => 'hbd.hotel_name', + 'state' => 'hbd.state', + 'country' => 'hbd.country', + 'zipcode' => 'hbd.zipcode', + 'phone' => 'hbd.phone', + 'email' => 'hbd.email', + 'check_in_time' => 'hbd.check_in_time', + 'check_out_time' => 'hbd.check_out_time', + 'id_room' => 'hbd.id_room', + 'booking_type' => 'hbd.booking_type', + 'id_cart'=>'o.id_cart', + 'id_currency'=>'o.id_currency', + 'date_add'=> 'o.date_add', + 'date_upd'=> 'o.date_upd', + ); + + public $resourceConfiguration; + /** * @param WebserviceOutputBuilderCore $obj * @return WebserviceSpecificManagementInterface @@ -301,19 +335,21 @@ public function manage() $this->renderResponse(); } else { + $this->getBookingsList(); + $this->renderResponse(); // @todo: add filters for the booking webservice // $filters = $this->manageFilters(); - $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('bookings', array()); - $bookings = Db::getInstance()->executeS('SELECT `id_order` FROM `'._DB_PREFIX_.'orders` WHERE 1'); - foreach ($bookings as $booking) { - $more_attr = array( - 'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$booking['id_order'], - 'id' => (int) $booking['id_order'] - ); - $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('booking', array('objectsNodeName' => 'bookings'), $more_attr, false); - } - $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('bookings', array()); - $this->output = $this->objOutput->getObjectRender()->overrideContent($this->output); + // $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('bookings', array()); + // $bookings = Db::getInstance()->executeS('SELECT `id_order` FROM `'._DB_PREFIX_.'orders` WHERE 1'); + // foreach ($bookings as $booking) { + // $more_attr = array( + // 'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$booking['id_order'], + // 'id' => (int) $booking['id_order'] + // ); + // $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('booking', array('objectsNodeName' => 'bookings'), $more_attr, false); + // } + // $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('bookings', array()); + // $this->output = $this->objOutput->getObjectRender()->overrideContent($this->output); } break; @@ -3539,6 +3575,136 @@ public function removeDemandsInOrderedRoom($demands) } + + private function manageBookingFilter($filters) + { + $ret = ''; + $allowedFilters = $this->allowedFilters; + foreach ($filters as $field => $raw) { + if (!array_key_exists($field, $allowedFilters)) { + $this->wsObject->setErrorDidYouMean(400, 'This filter does not exist', $field, array_keys($allowedFilters), 32); + return false; + } + preg_match('/^(.*)\[(.*)\](.*)$/', $raw, $matches); + if (count($matches) > 1) { + if ($matches[1] == '%' || $matches[3] == '%') { + $ret .= ' AND '.$allowedFilters[$field].' LIKE "'.pSQL($matches[1].$matches[2].$matches[3])."\"\n"; + } elseif ($matches[1] == '' && $matches[3] == '') { + if (strpos($matches[2], '|') > 0) { + $values = explode('|', $matches[2]); + $ret .= ' AND '.$allowedFilters[$field].' IN (' . implode(',', $values) . ')'; + } elseif (preg_match('/^([\d\.:\-\s]+),([\d\.:\-\s]+)$/', $matches[2], $matches3)) { + unset($matches3[0]); + if (count($matches3) > 0) { + sort($matches3); + $ret .= ' AND '.$allowedFilters[$field].' BETWEEN "'.pSQL($matches3[0]).'" AND "'.pSQL($matches3[1])."\"\n"; + } + } else { + $ret .= ' AND '.$allowedFilters[$field].'="'.pSQL($matches[2]).'"'."\n"; + } + } elseif ($matches[1] == '>') { + $ret .= ' AND '.$allowedFilters[$field].' > "'.pSQL($matches[2])."\"\n"; + } elseif ($matches[1] == '<') { + $ret .= ' AND '.$allowedFilters[$field].' < "'.pSQL($matches[2])."\"\n"; + } elseif ($matches[1] == '!') { + $multiple_values = explode('|', $matches[2]); + foreach ($multiple_values as $value) { + $ret .= ' AND '.$allowedFilters[$field].' != "'.pSQL($value)."\"\n"; + } + } + } else { + $ret .= ' AND '.$allowedFilters[$field].' '.(Validate::isFloat(pSQL($raw)) ? 'LIKE' : '=').' "'.pSQL($raw)."\"\n"; + } + } + + return $ret; + } + + private function manageBookingOrderBySort($sorts) + { + $sql_sort = ''; + if(isset($sorts) && $sorts){ + preg_match('#^\[(.*)\]$#Ui', $sorts, $matches); + if (count($matches) > 1) { + $sorts = explode(',', $matches[1]); + } else { + $sorts = array($sorts); + } + $sql_sort .= ' ORDER BY '; + + foreach($sorts as $key => $sort){ + $delimiterPosition = strrpos($sort, '_'); + if ($delimiterPosition !== false) { + $fieldName = substr($sort, 0, $delimiterPosition); + $direction = strtoupper(substr($sort, $delimiterPosition + 1)); + } + if ($delimiterPosition === false || !in_array($direction, array('ASC', 'DESC'))) { + $this->wsObject->setError(400, 'The "sort" value has to be formed as this example: "field_ASC" or \'[field_1_DESC,field_2_ASC,field_3_ASC,...]\' ("field" has to be an available field)', 37); + return false; + } + $sql_sort .= $fieldName.' '.$direction;// ORDER BY `field` ASC|DESC + } + } + return $sql_sort; + } + + public function getBookingsList() + { + $selectColumns = ['hbd.id']; + $fragments = $this->wsObject->urlFragments; + if (!empty($fragments['display'])) { + if ($fragments['display'] === 'full') { + $selectColumns = ['o.*', 'hbd.*']; + } elseif ($fragments['display'] !== 'full') { + $selectColumns = []; + $displayColumn = array_map('trim', explode(',', trim($fragments['display'], '[]'))); + foreach ($displayColumn as $key => $column) { + if(array_key_exists($column,$this->allowedFilters)){ + $selectColumns[] = $this->allowedFilters[$column]; + }else{ + $selectColumns[] = $column; + } + } + if (empty($selectColumns)) { + $selectColumns = ['o.id_order']; + } + } + } + + $whereSql = ''; + $limitSql = ''; + $orderSql = ''; + if (!empty($fragments['filter']) && is_array($fragments['filter'])) { + $whereSql = $this->manageBookingFilter($fragments['filter']); + } + if (!empty($fragments['sort'])) { + $orderSql = $this->manageBookingOrderBySort($fragments['sort']); + } + if (isset($fragments['limit'])) { + $limitArgs = explode(',', $fragments['limit']); + if(count($limitArgs) != 2) { + $this->wsObject->setError(400, 'The "limit" value has to be formed as this example: "5,25" or "10"', 39); + } + $limitSql = ' LIMIT ' . (int) $limitArgs[0] . ', ' . (int) $limitArgs[1]; + } + $sql = ' + SELECT ' . implode(', ', $selectColumns) . ' + FROM ' . _DB_PREFIX_ . 'orders o + INNER JOIN ' . _DB_PREFIX_ . 'htl_booking_detail hbd + ON o.id_order = hbd.id_order + WHERE 1 + ' . $whereSql . ' + ' . $orderSql . ' + ' . $limitSql; + + try { + $this->output['bookings'] = Db::getInstance()->executeS($sql); + } catch (\Throwable $th) { + $this->wsObject->setError(400, $th->getMessage(), 39); + } + } + + /** * Used to get the booking details for the GET, POST and PUT request. */ @@ -3706,7 +3872,6 @@ public function getBookingDetails($idBooking) $roomTypeInfo[$dateJoin]['rooms'][] = $roomInfo; } } - $params['associations']['room_types'] = array_values($roomTypeInfo); $this->output['booking'] = $params; } From 8628cfa7371d76e59162ce4a4f958aa6211a310c Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Thu, 5 Feb 2026 17:59:26 +0530 Subject: [PATCH 2/4] change filter columns, update filter result depending requirement --- .../WebserviceSpecificManagementBookings.php | 232 ++++++++++++++---- 1 file changed, 182 insertions(+), 50 deletions(-) diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 8f7cb4f85f..9043270860 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -159,35 +159,19 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We ); public $allowedFilters = array( - 'id_hotel' => 'o.id_hotel', - 'id_customer' => 'o.id_customer', - 'id_order' => 'o.id_order', - 'id_order_status' => 'o.current_state', - 'reference' => 'o.reference', - 'check_in' => 'hbd.check_in', - 'check_out' => 'hbd.check_out', - 'date_from' => 'hbd.date_from', - 'date_to' => 'hbd.date_to', - 'room_type' => 'hbd.id_product', - 'total_price_tax_excl' => 'hbd.total_price_tax_excl', - 'total_price_tax_incl' => 'hbd.total_price_tax_incl', - 'total_paid_amount' => 'hbd.total_paid_amount', - 'is_refunded' => 'hbd.is_refunded', - 'room_num' => 'hbd.room_num', - 'hotel_name' => 'hbd.hotel_name', - 'state' => 'hbd.state', - 'country' => 'hbd.country', - 'zipcode' => 'hbd.zipcode', - 'phone' => 'hbd.phone', - 'email' => 'hbd.email', - 'check_in_time' => 'hbd.check_in_time', - 'check_out_time' => 'hbd.check_out_time', - 'id_room' => 'hbd.id_room', - 'booking_type' => 'hbd.booking_type', - 'id_cart'=>'o.id_cart', - 'id_currency'=>'o.id_currency', - 'date_add'=> 'o.date_add', - 'date_upd'=> 'o.date_upd', + 'id_property' => 'o.id_hotel', + 'customer' => 'customer', + 'id_order' => 'o.id_order', + 'booking_status' => 'hbd.id_status', + 'order_status' => 'o.current_state', + 'source' => 'o.source', + 'booking_date' => 'o.date_add', + 'checkin_date' => 'hbd.date_from', + 'checkout_date' => 'hbd.date_to', + 'id_room_type' => 'hbd.id_product', + 'number_of_rooms' => 'hbd.num_rooms', + 'payment_type' => 'op.payment_type', + 'payment_method' => 'op.payment_method', ); public $resourceConfiguration; @@ -285,7 +269,8 @@ public function getResponseXml() 'facilities' => 'facility', 'services' => 'service', 'cart_rules' => 'cart_rule', - 'remarks' => 'remark' + 'remarks' => 'remark', + 'bookings' => 'booking' ); $this->output = $this->renderXmlOutputUsingArray($this->output, array(), $parentKeys); } @@ -3581,12 +3566,15 @@ private function manageBookingFilter($filters) $ret = ''; $allowedFilters = $this->allowedFilters; foreach ($filters as $field => $raw) { + preg_match('/^(.*)\[(.*)\](.*)$/', $raw, $matches); if (!array_key_exists($field, $allowedFilters)) { $this->wsObject->setErrorDidYouMean(400, 'This filter does not exist', $field, array_keys($allowedFilters), 32); return false; - } - preg_match('/^(.*)\[(.*)\](.*)$/', $raw, $matches); - if (count($matches) > 1) { + } else if ($field === 'customer') { + $ret .= ' AND (c.`firstname` LIKE "%' . pSQL($raw). '%" + OR c.`email` LIKE "%' . pSQL($raw). '%")' . "\n"; + continue; + } else if(count($matches) > 1) { if ($matches[1] == '%' || $matches[3] == '%') { $ret .= ' AND '.$allowedFilters[$field].' LIKE "'.pSQL($matches[1].$matches[2].$matches[3])."\"\n"; } elseif ($matches[1] == '' && $matches[3] == '') { @@ -3650,24 +3638,17 @@ private function manageBookingOrderBySort($sorts) public function getBookingsList() { - $selectColumns = ['hbd.id']; + $selectColumns = ['o.`id_order`']; $fragments = $this->wsObject->urlFragments; if (!empty($fragments['display'])) { if ($fragments['display'] === 'full') { - $selectColumns = ['o.*', 'hbd.*']; - } elseif ($fragments['display'] !== 'full') { - $selectColumns = []; - $displayColumn = array_map('trim', explode(',', trim($fragments['display'], '[]'))); - foreach ($displayColumn as $key => $column) { - if(array_key_exists($column,$this->allowedFilters)){ - $selectColumns[] = $this->allowedFilters[$column]; - }else{ - $selectColumns[] = $column; - } - } - if (empty($selectColumns)) { - $selectColumns = ['o.id_order']; - } + $selectColumns = array( + 'o.`id_order`','o.`id_currency`', 'o.`source`','o.`date_add`','o.`id_lang`','o.`current_state`','o.`total_paid_real`','o.`total_paid_tax_incl`','o.`total_paid_tax_excl`', + 'hbd.`id_product`','hbd.`date_from`','hbd.`date_to`','hbd.`total_price_tax_incl`','hbd.`total_price_tax_excl`','hbd.`id_room`','hbd.`id`','hbd.`adults`','hbd.`children`','hbd.`id_hotel`','hbd.`room_type_name`', + 'c.`firstname`','c.`lastname`','c.`email`','c.`phone`','c.`id_default_group`', + 'CONCAT(c.`firstname`, " ", c.`lastname`) AS `customer`', + 'crncy.`iso_code`' + ); } } @@ -3687,18 +3668,168 @@ public function getBookingsList() } $limitSql = ' LIMIT ' . (int) $limitArgs[0] . ', ' . (int) $limitArgs[1]; } + $id_lang = Configuration::get('PS_LANG_DEFAULT') ; + $sql = ' SELECT ' . implode(', ', $selectColumns) . ' FROM ' . _DB_PREFIX_ . 'orders o INNER JOIN ' . _DB_PREFIX_ . 'htl_booking_detail hbd ON o.id_order = hbd.id_order + INNER JOIN ' . _DB_PREFIX_ . 'customer c + ON o.id_customer = c.id_customer + INNER JOIN ' . _DB_PREFIX_ . 'currency crncy + ON o.id_currency = crncy.id_currency + LEFT JOIN ' . _DB_PREFIX_ . 'order_payment_detail opd + ON o.id_order = opd.id_order + LEFT JOIN ' . _DB_PREFIX_ . 'order_payment op + ON opd.id_order_payment = op.id_order_payment WHERE 1 ' . $whereSql . ' ' . $orderSql . ' ' . $limitSql; - try { - $this->output['bookings'] = Db::getInstance()->executeS($sql); + $results = Db::getInstance()->executeS($sql); + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); + $objOrder = new Order(); + $resultData = array(); + + foreach ($results as $result) { + $orderId = (int) $result['id_order']; + if($fragments['display'] === 'full'){ + if (!isset($resultData[$orderId])) { + $params = array(); + $params['id_order'] = $orderId; + $params['id_property'] = (int) $result['id_hotel']; + $params['currency'] = strtoupper($result['iso_code']); + $params['order_status'] = $result['current_state']; + $params['source'] = $result['source']; + $params['booking_date'] = $result['date_add']; + $params['id_language'] = (int) $result['id_lang']; + $params['associations'] = array(); + $params['associations']['customer_detail'] = array( + 'id_customer' => (int) $result['id_customer'], + 'firstname' => $result['firstname'], + 'lastname' => $result['lastname'], + 'email' => $result['email'], + 'phone' => isset($result['phone']) ? $result['phone'] : '' + ); + + $params['associations']['price_details'] = array( + 'total_paid' => Tools::ps_round($result['total_paid_real'], _PS_PRICE_COMPUTE_PRECISION_), + 'total_price_without_tax' => Tools::ps_round($result['total_paid_tax_excl'], _PS_PRICE_COMPUTE_PRECISION_), + 'total_tax' => Tools::ps_round( + $result['total_paid_tax_incl'] - $result['total_paid_tax_excl'], + _PS_PRICE_COMPUTE_PRECISION_ + ) + ); + + $params['associations']['remarks'] = array(); + if ($customerMessages = Message::getMessagesByOrderId($orderId)) { + foreach ($customerMessages as $customerMessage) { + $params['associations']['remarks'][] = $customerMessage['message']; + } + } + $params['associations']['room_types'] = array(); + $resultData[$orderId] = $params; + } + + $dateJoin = $result['id_product'] . '_' . strtotime($result['date_from']) . strtotime($result['date_to']); + + if (!isset($resultData[$orderId]['associations']['room_types'][$dateJoin])) { + $resultData[$orderId]['associations']['room_types'][$dateJoin] = array( + 'id_room_type' => (int) $result['id_product'], + 'checkin_date' => $result['date_from'], + 'checkout_date' => $result['date_to'], + 'total_tax' => ($result['total_price_tax_incl'] - $result['total_price_tax_excl']), + 'number_of_rooms' => 1, + 'name' => $result['room_type_name'], + ); + } else { + $resultData[$orderId]['associations']['room_types'][$dateJoin]['total_tax'] += + ($result['total_price_tax_incl'] - $result['total_price_tax_excl']); + $resultData[$orderId]['associations']['room_types'][$dateJoin]['number_of_rooms']++; + } + + $resultData[$orderId]['associations']['room_types'][$dateJoin]['total_tax'] = + Tools::ps_round( + $resultData[$orderId]['associations']['room_types'][$dateJoin]['total_tax'], + _PS_PRICE_COMPUTE_PRECISION_ + ); + $roomInfo = array(); + $roomInfo['id_room'] = (int) $result['id_room']; + $roomInfo['id_hotel_booking'] = (int) $result['id']; + $roomInfo['adults'] = (int) $result['adults']; + $roomInfo['child'] = (int) $result['children']; + $roomInfo['unit_price_without_tax'] = Tools::ps_round($result['total_price_tax_excl'], _PS_PRICE_COMPUTE_PRECISION_); + $roomInfo['total_tax'] = Tools::ps_round(($result['total_price_tax_incl'] - $orderData['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); + if(isset($roomInfo['services'])) { + unset($roomInfo['services']); + } + + if ($additionalServices = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $result['id_order'], + 0, + 0, + $result['id_product'], + $result['date_from'], + $result['date_to'], + $result['id_room'], + 0, + $useTax, + null + )) { + $roomInfo['services'] = array(); + foreach ($additionalServices as $additionalService) { + foreach ($additionalService['additional_services'] as $service) { + $services = array(); + $services['id_service'] = (int) $service['id_product']; + $services['name'] = $service['name']; + $services['quantity'] = (int) $service['quantity']; + $services['unit_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl'] / $services['quantity']), _PS_PRICE_COMPUTE_PRECISION_); + $services['total_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); + $services['total_tax'] = Tools::ps_round(($service['total_price_tax_incl'] - $service['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); + + $objProduct = new Product($service['id_product']); + $services['per_night'] = 0; + if ($objProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $services['per_night'] = 1; + } + + $services['price_mode'] = (int) $objProduct->price_calculation_method; + $roomInfo['services'][] = $services; + } + } + } + + $resultData[$orderId]['associations']['room_types'][$dateJoin]['rooms'][] = $roomInfo; + + }else{ + $params['id_order'] = $orderId; + $resultData[$orderId] = $params; + } + } + + foreach ($resultData as &$order) { + if(isset($order['associations']['room_types'])){ + $order['associations']['room_types'] = array_values($order['associations']['room_types']); + }else{ + $more_attr = array( + 'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$booking['id_order'], + 'id' => (int) $order['id_order'] + ); + $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('booking', array('objectsNodeName' => 'bookings'), $more_attr, false); + } + } + + if($fragments['display'] === 'full'){ + $resultData = array_values($resultData); + $this->output['bookings'] = $resultData; + } else{ + $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('bookings', array()); + $this->output = $this->objOutput->getObjectRender()->overrideContent($this->output); + } + + } catch (\Throwable $th) { $this->wsObject->setError(400, $th->getMessage(), 39); } @@ -3915,6 +4046,7 @@ public function renderFooter($footer) */ public function renderXmlOutputUsingArray($response, $keyToIgnore = array(), $parentKeys = array(), $parentKey = '', $useEmpty = false) { + // ddd($response); $output = ''; foreach ($response as $key => $res) { if (in_array($key, $keyToIgnore) && $key) { From ab4734a131a01c39693f5044161e6fd7f4329c78 Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Fri, 6 Feb 2026 11:16:23 +0530 Subject: [PATCH 3/4] Change the response based on the display argument --- .../WebserviceSpecificManagementBookings.php | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 9043270860..b49e4140c1 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -3808,27 +3808,39 @@ public function getBookingsList() $resultData[$orderId] = $params; } } + + if ($fragments['display'] === 'full') { + $responseData = []; + foreach ($resultData as $order) { + if (isset($order['associations']['room_types'])) { + $order['associations']['room_types'] = array_values( + $order['associations']['room_types'] + ); + } - foreach ($resultData as &$order) { - if(isset($order['associations']['room_types'])){ - $order['associations']['room_types'] = array_values($order['associations']['room_types']); - }else{ - $more_attr = array( - 'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$booking['id_order'], - 'id' => (int) $order['id_order'] - ); - $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('booking', array('objectsNodeName' => 'bookings'), $more_attr, false); + $responseData[] = $order; } + + $this->output['bookings'] = $responseData; + return; + } + $this->output .= $this->objOutput->getObjectRender() + ->renderNodeHeader('bookings', []); + + foreach ($resultData as $order) { + $more_attr = array( + 'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$order['id_order'], + 'id' => (int) $order['id_order'] + ); + $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('booking', array('objectsNodeName' => 'bookings'), $more_attr, false); } - if($fragments['display'] === 'full'){ - $resultData = array_values($resultData); - $this->output['bookings'] = $resultData; - } else{ - $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('bookings', array()); - $this->output = $this->objOutput->getObjectRender()->overrideContent($this->output); - } + $this->output .= $this->objOutput->getObjectRender() + ->renderNodeFooter('bookings', []); + $this->output = $this->objOutput->getObjectRender() + ->overrideContent($this->output); + } catch (\Throwable $th) { $this->wsObject->setError(400, $th->getMessage(), 39); From 9dc1c757ffb5deec53d4eacd1ed53ec66d5075e8 Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Mon, 9 Feb 2026 12:55:24 +0530 Subject: [PATCH 4/4] add cart rule in response --- .../WebserviceSpecificManagementBookings.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index b49e4140c1..e45506a4fd 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -3645,9 +3645,10 @@ public function getBookingsList() $selectColumns = array( 'o.`id_order`','o.`id_currency`', 'o.`source`','o.`date_add`','o.`id_lang`','o.`current_state`','o.`total_paid_real`','o.`total_paid_tax_incl`','o.`total_paid_tax_excl`', 'hbd.`id_product`','hbd.`date_from`','hbd.`date_to`','hbd.`total_price_tax_incl`','hbd.`total_price_tax_excl`','hbd.`id_room`','hbd.`id`','hbd.`adults`','hbd.`children`','hbd.`id_hotel`','hbd.`room_type_name`', - 'c.`firstname`','c.`lastname`','c.`email`','c.`phone`','c.`id_default_group`', + 'c.`id_customer`','c.`firstname`','c.`lastname`','c.`email`','c.`phone`','c.`id_default_group`', 'CONCAT(c.`firstname`, " ", c.`lastname`) AS `customer`', - 'crncy.`iso_code`' + 'crncy.`iso_code`', + 'ocr.`id_order_invoice`', 'ocr.`name` as cart_rule_name', 'ocr.`value` as cart_rule_value', '`ocr`.`id_cart_rule`', ); } } @@ -3683,11 +3684,14 @@ public function getBookingsList() ON o.id_order = opd.id_order LEFT JOIN ' . _DB_PREFIX_ . 'order_payment op ON opd.id_order_payment = op.id_order_payment + LEFT JOIN ' . _DB_PREFIX_ . 'order_cart_rule ocr + ON o.id_order = ocr.id_order WHERE 1 ' . $whereSql . ' ' . $orderSql . ' ' . $limitSql; try { + /// ddd($sql); $results = Db::getInstance()->executeS($sql); $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $objOrder = new Order(); @@ -3695,7 +3699,7 @@ public function getBookingsList() foreach ($results as $result) { $orderId = (int) $result['id_order']; - if($fragments['display'] === 'full'){ + if( isset($fragments['display']) && $fragments['display'] === 'full'){ if (!isset($resultData[$orderId])) { $params = array(); $params['id_order'] = $orderId; @@ -3723,6 +3727,12 @@ public function getBookingsList() ) ); + $params['associations']['cart_rules'] = array( + 'code' => $result['cart_rule_name'], + 'value' => Tools::ps_round($result['cart_rule_value'], _PS_PRICE_COMPUTE_PRECISION_), + 'id_order_invoice' => $result['id_order_invoice'], + ); + $params['associations']['remarks'] = array(); if ($customerMessages = Message::getMessagesByOrderId($orderId)) { foreach ($customerMessages as $customerMessage) { @@ -3761,10 +3771,14 @@ public function getBookingsList() $roomInfo['adults'] = (int) $result['adults']; $roomInfo['child'] = (int) $result['children']; $roomInfo['unit_price_without_tax'] = Tools::ps_round($result['total_price_tax_excl'], _PS_PRICE_COMPUTE_PRECISION_); - $roomInfo['total_tax'] = Tools::ps_round(($result['total_price_tax_incl'] - $orderData['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); + $roomInfo['total_tax'] = Tools::ps_round(($result['total_price_tax_incl'] - $result['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_); if(isset($roomInfo['services'])) { unset($roomInfo['services']); } + + if (Group::getPriceDisplayMethod($result['id_default_group']) == PS_TAX_INC) { + $useTax = 1; + } if ($additionalServices = $objServiceProductOrderDetail->getRoomTypeServiceProducts( $result['id_order'], @@ -3809,7 +3823,7 @@ public function getBookingsList() } } - if ($fragments['display'] === 'full') { + if (isset($fragments['display']) && $fragments['display'] === 'full') { $responseData = []; foreach ($resultData as $order) { if (isset($order['associations']['room_types'])) {