Merge branch 'develop' into gli-1798

This commit is contained in:
Shreesh Arora
2024-07-02 16:55:28 +05:30
130 changed files with 9762 additions and 8840 deletions

View File

@@ -411,7 +411,7 @@ class AdminCartRulesControllerCore extends AdminController
$ruleGroupId,
$ruleId,
Tools::getValue('product_rule_'.$ruleGroupId.'_'.$ruleId.'_type'),
Tools::getValue('product_rule_select_'.$ruleGroupId.'_'.$ruleId)
Tools::getValue('product_rule_select_'.$ruleGroupId.'_'.$ruleId, array())
);
}
}
@@ -486,6 +486,7 @@ class AdminCartRulesControllerCore extends AdminController
ON (p.`id_product` = hrt.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl
ON (hrt.`id_hotel` = hbl.`id` AND hbl.`id_lang` = '.(int)Context::getContext()->language->id.Shop::addSqlRestrictionOnLang('pl').')
WHERE p.`booking_product` = 1
ORDER BY name');
foreach ($results as $row) {
if($row['hotel_name']) {

View File

@@ -50,9 +50,9 @@ class AdminCustomerPreferencesControllerCore extends AdminController
$this->fields_options = array(
'general' => array(
'title' => $this->l('General'),
'icon' => 'icon-cogs',
'fields' => array(
'title' => $this->l('General'),
'icon' => 'icon-cogs',
'fields' => array(
'PS_REGISTRATION_PROCESS_TYPE' => array(
'title' => $this->l('Registration process type'),
'hint' => $this->l('The "Only account creation" registration option allows the customer to register faster, and create his/her address later.'),
@@ -121,6 +121,15 @@ class AdminCustomerPreferencesControllerCore extends AdminController
'cast' => 'intval',
'type' => 'bool'
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
'customer_kpi' => array(
'title' => $this->l('Customer KPI configuration'),
'icon' => 'icon-cogs',
'fields' => array(
'PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS' => array(
'title' => $this->l('Number of orders to use to calculate frequent customers'),
'hint' => $this->l('Set the number of orders to use to calculate frequent customers.'),
@@ -157,8 +166,10 @@ class AdminCustomerPreferencesControllerCore extends AdminController
'class' => 'fixed-width-xl',
),
),
'submit' => array('title' => $this->l('Save')),
),
'submit' => array(
'title' => $this->l('Save'),
),
)
);
}

View File

@@ -509,7 +509,7 @@ class AdminCustomersControllerCore extends AdminController
);
// if we add a customer via fancybox (ajax), it's a customer and he doesn't need to be added to the visitor and guest groups
if (Tools::isSubmit('addcustomer') && Tools::isSubmit('submitFormAjax')) {
if (Tools::isSubmit('submitFormAjax')) {
$visitor_group = Configuration::get('PS_UNIDENTIFIED_GROUP');
$guest_group = Configuration::get('PS_GUEST_GROUP');
foreach ($groups as $key => $g) {

View File

@@ -77,7 +77,7 @@ class AdminGendersControllerCore extends AdminController
'list' => array(
0 => $this->l('Male'),
1 => $this->l('Female'),
2 => $this->l('Neutral')
2 => $this->l('Other')
),
'filter_key' => 'a!type',
'callback' => 'displayGenderType',
@@ -145,7 +145,7 @@ class AdminGendersControllerCore extends AdminController
array(
'id' => 'type_neutral',
'value' => 2,
'label' => $this->l('Neutral')
'label' => $this->l('Other')
)
)
),

View File

@@ -54,7 +54,16 @@ class AdminMaintenanceControllerCore extends AdminController
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'class' => "hello"
'form_group_class' => (Tools::getValue('PS_SHOP_ENABLE', Configuration::get('PS_SHOP_ENABLE'))) ? 'collapse' : '',
),
'PS_ALLOW_EMP_MAX_ATTEMPTS' => array(
'title' => $this->l('Maximum Login Attempts'),
'validation' => 'isUnsignedInt',
'cast' => 'intval',
'type' => 'text',
'class' => 'fixed-width-xl',
'desc' => sprintf($this->l('Set the number of maximum login attempts allowed in %d minutes. Set to 0 to disable this feature.'), MaintenanceAccess::LOGIN_ATTEMPTS_WINDOW),
'form_group_class' => ((Tools::getValue('PS_SHOP_ENABLE', Configuration::get('PS_SHOP_ENABLE'))) || !(Tools::getValue('PS_ALLOW_EMP', Configuration::get('PS_ALLOW_EMP')))) ? ' collapse' : '',
),
'PS_MAINTENANCE_IP' => array(
'title' => $this->l('Maintenance IP'),
@@ -69,9 +78,44 @@ class AdminMaintenanceControllerCore extends AdminController
);
}
public function postProcess()
{
if (Tools::isSubmit('submitOptionsconfiguration')) {
$shopEnable = Tools::getValue('PS_SHOP_ENABLE');
$allowEmp = Tools::getValue('PS_ALLOW_EMP');
$allowEmpMaxAttempts = trim(Tools::getValue('PS_ALLOW_EMP_MAX_ATTEMPTS'));
$maintenanceIp = trim(Tools::getValue('PS_MAINTENANCE_IP'));
// validations
if (!$shopEnable && $allowEmp) {
if ($allowEmpMaxAttempts == '') {
$this->errors[] = $this->l('Maximum Login Attempts is a required field.');
} elseif (!Validate::isUnsignedInt($allowEmpMaxAttempts)) {
$this->errors[] = $this->l('Maximum Login Attempts is invalid. Please enter a value greater than or equal to 0.');
}
}
// update values
if (!count($this->errors)) {
Configuration::updateValue('PS_SHOP_ENABLE', $shopEnable);
Configuration::updateValue('PS_MAINTENANCE_IP', $maintenanceIp);
if (!$shopEnable) {
Configuration::updateValue('PS_ALLOW_EMP', $allowEmp);
if ($allowEmp) {
Configuration::updateValue('PS_ALLOW_EMP_MAX_ATTEMPTS', $allowEmpMaxAttempts);
}
}
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&conf=6');
}
}
}
public function setMedia()
{
parent::setMedia();
$this->addJS(_PS_JS_DIR_.'maintenance.js');
$this->addJS(_PS_JS_DIR_.'/admin/maintenance.js');
}
}

View File

@@ -186,19 +186,17 @@ class AdminNormalProductsControllerCore extends AdminController
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP? (int)$this->context->shop->id : 'a.id_shop_default';
$this->_join .= ' JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = '.$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (a.`id_product` = hrt.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hb ON (hrt.`id_hotel` = hb.`id`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (hb.`id` = hbl.`id` AND b.`id_lang` = hbl.`id_lang`)
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`)
LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1)
LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` rsp ON (rsp.`id_product` = a.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = hb.`id`)';
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (rsp.`id_element` = hrt.`id_product` AND rsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.')
'.HotelBranchInformation::addHotelRestriction(false, 'hrt');
$this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, IF(a.`price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_PER_DAY.', "'.$this->l('Per Day').'", "'.$this->l('Per Booking').'") as price_calculation_method_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, ';
$this->_select .= ' COUNT(rsp.`id_product`) as products_associated, hrt.`adults`, hrt.`children`, hb.`id` as id_hotel, aa.`city`, hbl.`hotel_name`, ';
$this->_select .= ' COUNT(hrt.`id_product`) as products_associated, ';
$this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, ';
$this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`';
@@ -280,7 +278,7 @@ class AdminNormalProductsControllerCore extends AdminController
$idServiceCategory = Configuration::get('PS_SERVICE_CATEGORY');
$this->objLocationsCategory = new Category($idServiceCategory, $this->context->language->id);
$nestedCategories = Category::getNestedCategories($idServiceCategory);
if ($nestedCategories) {
if (isset($nestedCategories[$idServiceCategory]['children']) && $nestedCategories[$idServiceCategory]['children']) {
foreach ($nestedCategories[$idServiceCategory]['children'] as $childCategory) {
$this->buildCategoryOptions($childCategory);
}

View File

@@ -376,11 +376,11 @@ class AdminOrdersControllerCore extends AdminController
$cart_order_exists = $cart->orderExists();
if (!$cart_order_exists) {
$this->context->cart = $cart;
$this->context->currency = new Currency((int)$cart->id_currency);
// validate cart for removing invalid data from cart before new order creation
$this->errors = array_merge($this->errors, HotelCartBookingData::validateCartBookings());
$this->context->currency = new Currency((int)$cart->id_currency);
$cart_detail_data = array();
$cart_detail_data_obj = new HotelCartBookingData();
$objHotelServiceProductCartDetail = new HotelServiceProductCartDetail();
@@ -494,11 +494,14 @@ class AdminOrdersControllerCore extends AdminController
);
if (((int) $order->isReturnable()) && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG)) {
$orderTotalPaid = $order->getTotalPaid();
$orderDiscounts = $order->getCartRules();
$hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false;
$this->toolbar_btn['cancel'] = array(
'short' => ((float) $order->getTotalPaid()) ? $this->l('Refund') : $this->l('Cancel'),
'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'),
'href' => '#refundForm',
'id' => 'desc-order-standard_refund',
'desc' => ((float) $order->getTotalPaid()) ? $this->l('Initiate refund') : $this->l('Cancel bookings'),
'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'),
'class' => 'icon-exchange',
'target' => true,
);
@@ -772,7 +775,7 @@ class AdminOrdersControllerCore extends AdminController
array(
'order' => $objOrder,
'currency' => new Currency($objOrder->id_currency),
'current_index' => self::$currentIndex,
'reallocate_form_action' => $this->context->link->getAdminLink('AdminOrders').'&vieworder&id_order='.$objOrder->id,
)
);
$modal = array(
@@ -938,7 +941,7 @@ class AdminOrdersControllerCore extends AdminController
// get booking information by order
$objBookingDetail = new HotelBookingDetail();
$objOrderReturn = new OrderReturn();
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1);
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1, 0, 1);
if ($bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($objOrder->id)) {
foreach($bookingOrderInfo as $key => $booking) {
if ((in_array($booking['id'], $refundReqBookings)) || $booking['is_refunded']) {
@@ -946,6 +949,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
}
$this->context->smarty->assign(
array(
'order' => $objOrder,
@@ -958,15 +962,18 @@ class AdminOrdersControllerCore extends AdminController
'modal_class' => 'modal-md order_detail_modal',
'modal_title' => '<i class="icon icon-exchange"></i> &nbsp'.$this->l('Cancel Bookings'),
'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_cancel_room_bookings.tpl'),
'modal_actions' => array(
);
if ($bookingOrderInfo) {
$modal['modal_actions'] = array(
array(
'type' => 'button',
'value' => 'submitCancelBooking',
'class' => 'submitCancelBooking btn-primary pull-right',
'label' => '<i class="icon-exchange"></i> '.$this->l('Cancel Bookings'),
),
),
);
)
);
}
$this->context->smarty->assign($modal);
$response['hasError'] = 0;
@@ -985,6 +992,8 @@ class AdminOrdersControllerCore extends AdminController
if ($this->tabAccess['edit'] == 1 && $this->display == 'view') {
$this->addJS(_PS_JS_DIR_.'admin/orders.js');
// add js for reallocation process
$this->addJS(_PS_JS_DIR_.'admin/reallocation.js');
// $this->addJS(_PS_JS_DIR_.'admin/orders-product-event.js');
// $this->addJS(_PS_JS_DIR_.'admin/orders-room-event.js');
$this->addJS(_PS_JS_DIR_.'tools.js');
@@ -1375,19 +1384,22 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to delete this.');
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
}
/* booking refunds from order */
elseif (Tools::isSubmit('initiateRefund') && isset($order)) {
if ($this->tabAccess['delete'] === '1') {
if ($this->tabAccess['edit'] === '1') {
$bookings = Tools::getValue('id_htl_booking');
if ($bookings && count($bookings)) {
foreach ($bookings as $idHtlBooking) {
if (OrderReturn::getOrdersReturnDetail($order->id, 0, $idHtlBooking)) {
$this->errors[] = Tools::displayError('Wrong bookings found for booking cancelation.');
break;
if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($order->id, 0, $idHtlBooking)) {
$bookingRefundDetail = reset($bookingRefundDetail);
if (!$bookingRefundDetail['refunded']) {
$this->errors[] = Tools::displayError('Wrong bookings found for booking cancelation.');
break;
}
}
}
} else {
@@ -1399,51 +1411,66 @@ class AdminOrdersControllerCore extends AdminController
}
if (!count($this->errors)) {
// if amount paid is > 0 then create refund request else cancel the booking directly
if ($order->getTotalPaid() > 0) {
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = Configuration::get('PS_ORS_PENDING');
$objOrderReturn->by_admin = 1;
$objOrderReturn->question = $refundReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($bookings as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->save();
// create refund request
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 1;
$objOrderReturn->question = $refundReason;
$objOrderReturn->refunded_amount = 0;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($bookings as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->refunded_amount = 0;
if (!$order->getCartRules() && $order->getTotalPaid() <= 0) {
$objOrderReturnDetail->id_customization = 1;
}
$objOrderReturnDetail->save();
}
} else {
// cancel the booking directly
}
// Change order refund state
// Emails to customer, superadmin and employees on refund request state change
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
// process direct cancellations
if (!$order->getCartRules() && $order->getTotalPaid() <= 0) {
// Process refund in booking tables
foreach ($bookings as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
if (!$objHtlBooking->processRefundInBookingTables()) {
$this->errors[] = Tools::displayError('An error occurred while cancelling the booking.');
} else {
// set the message for the cancellation
$message = $this->l('Room').': '.$objHtlBooking->room_num.', '.$objHtlBooking->room_type_name.' '.$this->l('has been cancelled by the hotel.');
$message .= PHP_EOL.$this->l('Reasonn').': '.$refundReason;
$objHtlBooking->setBookingCancellationMessage($message, 1);
}
}
// if all bookings are getting cancelled then cancel the order also
if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
// As object order is already changed in processRefundInBookingTables
$order = new Order($order->id);
// complete the booking refund directly in the refund request
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED'));
// if all bookings are getting cancelled/Refunded then Cancel/Refund the order also
$idOrderState = 0;
if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
$idOrderState = Configuration::get('PS_OS_REFUND');
} elseif ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
$idOrderState = Configuration::get('PS_OS_CANCELED');
}
if ($idOrderState) {
$objOrderHistory = new OrderHistory();
$objOrderHistory->id_order = (int)$order->id;
$idOrderState = Configuration::get('PS_OS_CANCELED');
$useExistingPayment = false;
if (!$order->hasInvoice()) {
$useExistingPayment = true;
@@ -1460,7 +1487,7 @@ class AdminOrdersControllerCore extends AdminController
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=3&token='.$this->token);
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to delete this.');
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
} elseif (Tools::isSubmit('messageReaded')) {
Message::markAsReaded(Tools::getValue('messageReaded'), $this->context->employee->id);
@@ -1555,6 +1582,7 @@ class AdminOrdersControllerCore extends AdminController
$objCart = new Cart($id_cart);
if (Validate::isLoadedObject($objCart)) {
$this->context->cart = $objCart;
$this->context->currency = new Currency((int)$objCart->id_currency);
$this->errors = HotelCartBookingData::validateCartBookings();
$orderTotal = $objCart->getOrderTotal(true, Cart::BOTH);
@@ -2225,24 +2253,56 @@ class AdminOrdersControllerCore extends AdminController
$helper = new HelperKpi();
$helper->id = 'box-order-date';
$helper->icon = 'icon-calendar';
$helper->color = 'color3';
$helper->color = 'color1';
$helper->title = $this->l('Order Date');
$helper->tooltip = $this->l('The date when the order was placed.');
$helper->value = Tools::displayDate($objOrder->date_add);
$kpis[] = $helper;
$helper = new HelperKpi();
$helper->id = 'box-order-total';
$helper->icon = 'icon-money';
$helper->color = 'color4';
$helper->title = $this->l('Total');
$helper->color = 'color3';
$helper->title = $this->l('Bookings Total');
$helper->tooltip = $this->l('Total booking amount of this order.');
$helper->value = Tools::displayPrice($objOrder->total_paid_tax_incl, new Currency($objOrder->id_currency));
$kpis[] = $helper;
$helper = new HelperKpi();
$helper->id = 'box-total-paid';
$helper->icon = 'icon-money';
$helper->color = 'color4';
$helper->title = $this->l('Total Paid');
$helper->tooltip = $this->l('Total paid is the amount which customer has already paid for this order.');
$helper->value = Tools::displayPrice($objOrder->total_paid_real, new Currency($objOrder->id_currency));
$kpis[] = $helper;
$helper = new HelperKpi();
$helper->id = 'box-total-due';
$helper->icon = 'icon-money';
$helper->color = 'color2';
$helper->title = $this->l('Total Due');
$helper->tooltip = $this->l('Total due is the amount which customer has to pay for this order.');
$helper->value = Tools::displayPrice(($objOrder->total_paid_tax_incl - $objOrder->total_paid_real), new Currency($objOrder->id_currency));
$kpis[] = $helper;
$orderHistory = array_reverse($objOrder->getHistory($this->context->language->id));
$helper = new HelperKpi();
$helper->id = 'box-order-source';
$helper->icon = 'icon-globe';
$helper->color = 'color1';
$helper->title = $this->l('Order Source');
$helper->tooltip = $this->l('Order source shows from which source the order was placed.');
$helper->subtitle = $orderHistory[0]['id_employee'] ? $this->l('Back office') : $this->l('Front office');
$helper->value = $objOrder->source;
$kpis[] = $helper;
$helper = new HelperKpi();
$helper->id = 'box-messages';
$helper->icon = 'icon-comments';
$helper->color = 'color2';
$helper->title = $this->l('Messages');
$helper->tooltip = $this->l('Messages is the number of customer messages for this order.');
$helper->href = $this->context->link->getAdminLink('AdminCustomerThreads').'&id_order='.$objOrder->id;
$helper->value = count(CustomerThread::getCustomerMessages($objOrder->id_customer, null, $objOrder->id));
$kpis[] = $helper;
@@ -2254,13 +2314,43 @@ class AdminOrdersControllerCore extends AdminController
$helper->icon = 'icon-home';
$helper->color = 'color1';
$helper->title = $this->l('Total Rooms');
$helper->tooltip = $this->l('Total rooms is the number of rooms booked in this order.');
$helper->href = '#start_products';
$helper->value = $numRooms;
$kpis[] = $helper;
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
'kpis' => &$kpis,
));
$helper = new HelperKpi();
$helper->id = 'box-payment-type';
$helper->icon = 'icon-home';
$helper->color = 'color3';
$helper->title = $this->l('Payment Type');
$helper->tooltip = $this->l('The payment type refers to the type of payment that customer selected while placing this order.');
$helper->value = $objOrder->is_advance_payment ? $this->l('Partial Payment') : $this->l('Full Payment');
$kpis[] = $helper;
if ($objOrder->is_advance_payment) {
$helper = new HelperKpi();
$helper->id = 'box-partial-payment-amount';
$helper->icon = 'icon-money';
$helper->color = 'color4';
$helper->title = $this->l('Partial Payment Amount');
$helper->tooltip = $this->l('Partial payment amount refers to the amount that customer has to pay as advance payment, if payment type selected as partial payment while placing this order.');
$helper->value = Tools::displayPrice($objOrder->advance_paid_amount, new Currency($objOrder->id_currency));
$kpis[] = $helper;
}
$objOrderReturn = new OrderReturn();
if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1)) {
$refundedAmount = $objOrderReturn->getRefundedAmount($objOrder->id);
$helper = new HelperKpi();
$helper->id = 'box-payment-type';
$helper->icon = 'icon-money';
$helper->color = 'color3';
$helper->title = $this->l('Refunded Amount');
$helper->tooltip = $this->l('Refunded amount refers to the amount that has been refunded for this order.');
$helper->value = Tools::displayPrice($refundedAmount, new Currency($objOrder->id_currency));
$kpis[] = $helper;
}
} else {
$time = time();
$kpis = array();
@@ -2375,6 +2465,10 @@ class AdminOrdersControllerCore extends AdminController
$kpis[] = $helper;
}
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
'kpis' => &$kpis,
));
$helper = new HelperKpiRow();
$helper->kpis = $kpis;
return $helper->generate();
@@ -2546,7 +2640,7 @@ class AdminOrdersControllerCore extends AdminController
$totalConvenienceFeeTI = 0;
$totalDemandsPriceTE = 0;
$totalDemandsPriceTI = 0;
$totalRefundedRooms = 0;
if ($order_detail_data = $objBookingDetail->getOrderFormatedBookinInfoByIdOrder($order->id)) {
$objBookingDemand = new HotelBookingDemands();
$objHotelRoomType = new HotelRoomType();
@@ -2707,6 +2801,15 @@ class AdminOrdersControllerCore extends AdminController
$order_detail_data[$key]['amt_with_qty_tax_incl'] = $value['total_price_tax_incl'];
$order_detail_data[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']);
$order_detail_data[$key]['total_room_tax'] = $order_detail_data[$key]['total_room_price_ti'] - $order_detail_data[$key]['total_room_price_te'];
if (isset($value['refund_info'])
&& $value['refund_info']['refunded']
&& $value['refund_info']['id_customization']
&& $value['is_refunded']
&& !$value['is_cancelled']
) {
$totalRefundedRooms += 1;
}
}
} else {
$order_detail_data = array();
@@ -2714,19 +2817,25 @@ class AdminOrdersControllerCore extends AdminController
$objOrderReturn = new OrderReturn();
$refundedAmount = 0;
if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) {
if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1, 0, 1)) {
$refundedAmount = $objOrderReturn->getRefundedAmount($order->id);
}
// get booking information by order
$bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($order->id);
foreach ($bookingOrderInfo as &$bookingOrderRoomInfo) {
// Get last refund request for booking
if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($bookingOrderRoomInfo['id_order'], 0, $bookingOrderRoomInfo['id'])) {
$bookingRefundDetail = reset($bookingRefundDetail);
if (!$bookingRefundDetail['id_customization']) {
$bookingOrderRoomInfo['is_refunded'] = 0;
}
}
$bookingOrderRoomInfo['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($bookingOrderRoomInfo['id']);
}
$objHotelBookingDetail = new HotelBookingDetail();
$htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id);
$isCancelledRoom = in_array(1, array_column($htlBookingDetail, 'is_cancelled'));
// hotel booking statuses
$htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus();
@@ -2745,15 +2854,13 @@ class AdminOrdersControllerCore extends AdminController
$orderOverBookings = $objHotelBookingDetail->getOverbookedRooms($order->id, 0, '', '', 0, 0, 1);
$this->tpl_view_vars = array(
// refund info
'totalRefundedRooms' => $totalRefundedRooms,
'orderOverBookings' => $orderOverBookings,
'refund_allowed' => (int) $order->isReturnable(),
'applicable_refund_policies' => $applicableRefundPolicies,
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'refundReqBookings' => $refundReqBookings,
'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG),
'allBookingsRefunded' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG),
'allBookingsCancelled' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG),
'refundedAmount' => $refundedAmount,
'totalDemandsPriceTI' => $totalDemandsPriceTI,
'totalDemandsPriceTE' => $totalDemandsPriceTE,
@@ -2840,7 +2947,6 @@ class AdminOrdersControllerCore extends AdminController
'products' => $products,
'customer' => $customer)
),
'isCancelledRoom' => $isCancelledRoom,
'orderDocuments' => $order->getDocuments(),
'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED,
'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN,
@@ -3027,44 +3133,52 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessUpdateGuestDetails()
{
$response = array(
'success' => false
'hasError' => false,
'errors' => array(),
);
if (Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) {
if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) {
$id_gender = Tools::getValue('id_gender');
$firstname = Tools::getValue('firstname');
$lastname = Tools::getValue('lastname');
$email = Tools::getValue('email');
$phone = Tools::getValue('phone');
$objCustomerGuestDetail->id_gender = $id_gender;
$objCustomerGuestDetail->firstname = $firstname;
$objCustomerGuestDetail->lastname = $lastname;
$objCustomerGuestDetail->email = $email;
$objCustomerGuestDetail->phone = $phone;
if ($objCustomerGuestDetail->validateGuestInfo()) {
$objCustomerGuestDetail = new OrderCustomerGuestDetail();
$response['errors'] = $objCustomerGuestDetail->validateController();
if (!$response['errors']) {
if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) {
$id_gender = Tools::getValue('id_gender');
$firstname = Tools::getValue('firstname');
$lastname = Tools::getValue('lastname');
$email = Tools::getValue('email');
$phone = Tools::getValue('phone');
$objCustomerGuestDetail->id_gender = $id_gender;
$objCustomerGuestDetail->firstname = $firstname;
$objCustomerGuestDetail->lastname = $lastname;
$objCustomerGuestDetail->email = $email;
$objCustomerGuestDetail->phone = $phone;
if ($objCustomerGuestDetail->save()) {
$response['success'] = true;
$gender = new Gender($objCustomerGuestDetail->id_gender, $this->context->language->id);
$response['data']['gender_name'] = $gender->name;
$response['data']['guest_name'] = $objCustomerGuestDetail->firstname.' '.$objCustomerGuestDetail->lastname ;
$response['data']['guest_email'] = $objCustomerGuestDetail->email;
$response['data']['guest_phone'] = $objCustomerGuestDetail->phone;
$response['msg'] = $this->l('Guest details are updated.');
} else {
$response['errors'][] = $this->l('Unable to save guest details.');
}
} else {
$response['errors'][] = $this->l('Invalid guest details, please check and try again.');
$response['errors'][] = $this->l('Guest details not found.');
}
} else {
$response['errors'][] = $this->l('Guest details not found.');
}
} else {
$response['errors'][] = $this->l('Guest details not found.');
}
}
if ($response['errors']) {
$response['hasError'] = true;
$this->context->smarty->assign('errors', $response['errors']);
$response['errorsHtml'] = $this->context->smarty->fetch('alerts.tpl');
}
$this->ajaxDie(json_encode($response));
}
@@ -3953,7 +4067,7 @@ class AdminOrdersControllerCore extends AdminController
if ($createFeaturePrice) {
$featurePriceParams['id_room'] = $room_info['id_room'];
$featurePriceParams = array_merge($featurePriceParams, array('date_from' => $date_from, 'date_to' => $date_to));
$this->createFeaturePrice($featurePriceParams);
HotelRoomTypeFeaturePricing::createAutoFeaturePrice($featurePriceParams);
}
} else {
break;
@@ -4407,32 +4521,6 @@ class AdminOrdersControllerCore extends AdminController
)));
}
protected function createFeaturePrice($params)
{
$feature_price_name = array();
foreach (Language::getIDs(true) as $id_lang) {
$feature_price_name[$id_lang] = 'Auto-generated';
}
$hrt_feature_price = new HotelRoomTypeFeaturePricing();
$hrt_feature_price->id_product = (int) $params['id_product'];
$hrt_feature_price->id_cart = (int) $params['id_cart'];
$hrt_feature_price->id_guest = (int) $params['id_guest'];
$hrt_feature_price->id_room = (int) $params['id_room'];
$hrt_feature_price->feature_price_name = $feature_price_name;
$hrt_feature_price->date_selection_type = HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE;
$hrt_feature_price->date_from = date('Y-m-d', strtotime($params['date_from']));
$hrt_feature_price->date_to = date('Y-m-d', strtotime($params['date_to']));
$hrt_feature_price->is_special_days_exists = 0;
$hrt_feature_price->special_days = json_encode(false);
$hrt_feature_price->impact_way = HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE;
$hrt_feature_price->impact_type = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE;
$hrt_feature_price->impact_value = $params['price'];
$hrt_feature_price->active = 1;
$hrt_feature_price->groupBox = array_column(Group::getGroups($this->context->language->id), 'id_group');
$hrt_feature_price->add();
}
public function ajaxProcessEditRoomOnOrder()
{
// Return value
@@ -4494,7 +4582,7 @@ class AdminOrdersControllerCore extends AdminController
if (Validate::isLoadedObject($objProduct = new Product($roomInfo['id_product']))) {
// If room type is NOT DELETED then use current room type price calculation
$params = array_merge($params, array('date_from' => $new_date_from, 'date_to' => $new_date_to));
$this->createFeaturePrice($params);
HotelRoomTypeFeaturePricing::createAutoFeaturePrice($params);
$roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$roomInfo['id_product'],
@@ -5247,7 +5335,7 @@ class AdminOrdersControllerCore extends AdminController
$res &= $order->update();
// Reinject quantity in stock
$this->reinjectQuantity($order_detail, $order_detail->product_quantity, $delete);
$order_detail->reinjectQuantity($order_detail, $order_detail->product_quantity, $delete);
// Update weight SUM
$order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
@@ -5337,7 +5425,7 @@ class AdminOrdersControllerCore extends AdminController
$res &= $order->update();
// Reinject quantity in stock
$this->reinjectQuantity($order_detail, $order_detail->product_quantity, true);
$order_detail->reinjectQuantity($order_detail, $order_detail->product_quantity, true);
// Update weight SUM
$order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier());
@@ -5737,101 +5825,6 @@ class AdminOrdersControllerCore extends AdminController
);
}
/**
* @param OrderDetail $order_detail
* @param int $qty_cancel_product
* @param bool $delete
*/
protected function reinjectQuantity($order_detail, $qty_cancel_product, $delete = false)
{
// Reinject product
$reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected;
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
// @since 1.5.0 : Advanced Stock Management
$product_to_inject = new Product($order_detail->product_id, false, (int)$this->context->language->id, (int)$order_detail->id_shop);
$product = new Product($order_detail->product_id, false, (int)$this->context->language->id, (int)$order_detail->id_shop);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) {
$manager = StockManagerFactory::getManager();
$movements = StockMvt::getNegativeStockMvts(
$order_detail->id_order,
$order_detail->product_id,
$order_detail->product_attribute_id,
$quantity_to_reinject
);
$left_to_reinject = $quantity_to_reinject;
foreach ($movements as $movement) {
if ($left_to_reinject > $movement['physical_quantity']) {
$quantity_to_reinject = $movement['physical_quantity'];
}
$left_to_reinject -= $quantity_to_reinject;
if (Pack::isPack((int)$product->id)) {
// Gets items
if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || ($product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0)) {
$products_pack = Pack::getItems((int)$product->id, (int)Configuration::get('PS_LANG_DEFAULT'));
// Foreach item
foreach ($products_pack as $product_pack) {
if ($product_pack->advanced_stock_management == 1) {
$manager->addProduct(
$product_pack->id,
$product_pack->id_pack_product_attribute,
new Warehouse($movement['id_warehouse']),
$product_pack->pack_quantity * $quantity_to_reinject,
null,
$movement['price_te'],
true
);
}
}
}
if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 ||
($product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) {
$manager->addProduct(
$order_detail->product_id,
$order_detail->product_attribute_id,
new Warehouse($movement['id_warehouse']),
$quantity_to_reinject,
null,
$movement['price_te'],
true
);
}
} else {
$manager->addProduct(
$order_detail->product_id,
$order_detail->product_attribute_id,
new Warehouse($movement['id_warehouse']),
$quantity_to_reinject,
null,
$movement['price_te'],
true
);
}
}
$id_product = $order_detail->product_id;
if ($delete) {
$order_detail->delete();
}
StockAvailable::synchronize($id_product);
} elseif ($order_detail->id_warehouse == 0) {
StockAvailable::updateQuantity(
$order_detail->product_id,
$order_detail->product_attribute_id,
$quantity_to_reinject,
$order_detail->id_shop
);
if ($delete) {
$order_detail->delete();
}
} else {
$this->errors[] = Tools::displayError('This product cannot be re-stocked.');
}
}
/**
* @param OrderInvoice $order_invoice
* @param float $value_tax_incl
@@ -6900,14 +6893,23 @@ class AdminOrdersControllerCore extends AdminController
// if room is changing in the reallocation
if ($objHotelBooking->id_product != $idNewRoomType) {
$result['has_room_type_change'] = 1;
// set context currency So that we can get prices in the order currency
$objOrder = new Order($objHotelBooking->id_order);
$this->context->currency = new Currency($objOrder->id_currency);
$newRoomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idNewRoomType,
$objHotelBooking->date_from,
$objHotelBooking->date_to
$objHotelBooking->date_to,
0,
0,
0,
0,
0,
0
);
if ($objHotelBooking->total_price_tax_excl != $newRoomTotalPrice['total_price_tax_excl']) {
$result['has_price_changes'] = 1;
$result['price_diff'] = $newRoomTotalPrice['total_price_tax_excl'] - $objHotelBooking->total_price_tax_excl;
$result['price_diff'] = Tools::ps_round(($newRoomTotalPrice['total_price_tax_excl'] - $objHotelBooking->total_price_tax_excl), 6);
}
}
} else {

View File

@@ -245,9 +245,10 @@ class AdminProductsControllerCore extends AdminController
);
} else {
$hotels = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1);
$hotelsArray = array();
foreach ($hotels as $hotel) {
$addressInfo = HotelBranchInformation::getAddress($hotel['id_hotel']);
$this->hotelsArray[$hotel['id_hotel']] = $hotel['hotel_name'].', '.$addressInfo['city'];
$hotelsArray[$hotel['id_hotel']] = $hotel['hotel_name'].', '.$addressInfo['city'];
}
$this->fields_list['hotel_name'] = array(
@@ -256,7 +257,7 @@ class AdminProductsControllerCore extends AdminController
'multiple' => true,
'operator' => 'or',
'filter_key' => 'hrt!id_hotel',
'list' => $this->hotelsArray,
'list' => $hotelsArray,
'optional' => true,
'class' => 'chosen',
'visible_default' => true,
@@ -399,7 +400,7 @@ class AdminProductsControllerCore extends AdminController
$idLocationsCategory = Configuration::get('PS_LOCATIONS_CATEGORY');
$this->objLocationsCategory = new Category($idLocationsCategory, $this->context->language->id);
$nestedCategories = Category::getNestedCategories($idLocationsCategory);
if ($nestedCategories) {
if (isset($nestedCategories[$idLocationsCategory]['children']) && $nestedCategories[$idLocationsCategory]['children']) {
foreach ($nestedCategories[$idLocationsCategory]['children'] as $childCategory) {
$this->buildCategoryOptions($childCategory);
}
@@ -3272,22 +3273,26 @@ class AdminProductsControllerCore extends AdminController
$this->errors[] = Tools::displayError('Invalid base children');
} else if (Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
if ($baseChildren > Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
$this->errors[] = sprintf(Tools::displayError('Base children cannot be greater than max childern allowed on your website (Max: %s)'), Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'));
$this->errors[] = sprintf(Tools::displayError('Base children cannot be greater than max childern allowed in the room of this room type (Max: %s)'), Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'));
}
}
if (!$maxAdults || !Validate::isUnsignedInt($maxAdults)) {
$this->errors[] = Tools::displayError('Invalid maximum number of adults');
} elseif ($maxAdults < $baseAdults) {
$this->errors[] = Tools::displayError('Maximum number of adults cannot be less than base adults');
} elseif ($maxAdults > $maxGuests) {
$this->errors[] = Tools::displayError('Maximum number of adults cannot be more than maximum number of guests');
}
if ($maxChildren == '' || !Validate::isUnsignedInt($maxChildren)) {
$this->errors[] = Tools::displayError('Invalid maximum number of children');
} else if (Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
if ($maxChildren > Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
$this->errors[] = sprintf(Tools::displayError('Maximum number of children cannot be greater than max childern allowed on your website (Max: %s)'), Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'));
}
} elseif ($maxChildren < $baseChildren) {
$this->errors[] = Tools::displayError('Maximum number of children cannot be less than base children');
} elseif ($maxChildren >= $maxGuests) {
$this->errors[] = Tools::displayError('Maximum number of children cannot be more or equal than maximum number of guests.(1 adult is mandatory in a room)');
} else if (Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
if ($maxChildren > Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
$this->errors[] = sprintf(Tools::displayError('Maximum number of children cannot be greater than max childern allowed in the room of this room type (Max: %s)'), Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'));
}
}
if (!$maxGuests || !Validate::isUnsignedInt($maxGuests)) {
$this->errors[] = Tools::displayError('Invalid maximum number of guests');
@@ -3670,6 +3675,7 @@ class AdminProductsControllerCore extends AdminController
public function processAdditionalFacilities()
{
if ($idProduct = Tools::getValue('id_product')) {
$errors = array();
$objRoomTypeDemand = new HotelRoomTypeDemand();
$objRoomTypeDemandPrice = new HotelRoomTypeDemandPrice();
// first delete all the previously saved prices and demands of this room type
@@ -3697,7 +3703,7 @@ class AdminProductsControllerCore extends AdminController
$objRoomTypeDemandPrice->save();
}
} else {
$this->errors[] = Tools::displayError('Invalid demand price of facility.').
$errors[] = Tools::displayError('Invalid demand price of facility.').
' : '.$objGlobalDemand->name[$this->context->language->id];
}
if ($advOptions = $objAdvOption->getGlobalDemandAdvanceOptions($idGlobalDemand)) {
@@ -3714,15 +3720,16 @@ class AdminProductsControllerCore extends AdminController
$objRoomTypeDemandPrice->save();
}
} else {
$this->errors[] = Tools::displayError('Invalid price of advanced option: ').$objAdvOption->name[$this->context->language->id];
$errors[] = Tools::displayError('Invalid price of advanced option: ').$objAdvOption->name[$this->context->language->id];
}
}
}
}
}
}
if (count($this->errors)) {
$this->warnings[] = Tools::displayError('Invalid price values are not saved. Please correct them and save again.');
if (count($errors)) {
$this->warnings[] = Tools::displayError('Invalid price values for additional facilities were not saved. Please correct them and try again.');
$this->errors = array_merge($this->errors, $errors);
}
$objCartBookingData = new HotelCartBookingData();

View File

@@ -677,6 +677,8 @@ class AdminThemesControllerCore extends AdminController
if (!count($this->errors)) {
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes').'&conf=6');
} else {
$this->redirect_after = '';
}
}
@@ -1981,7 +1983,7 @@ class AdminThemesControllerCore extends AdminController
}
}
if ($xml_version_too_old && !$this->_checkConfigForFeatures(array_keys(AdminThemes::$check_features))) {
$this->errors[] .= Tools::displayError('The config.xml file has not been created for this version of PrestaShop.');
$this->errors[] = Tools::displayError('The config.xml file has not been created for this version of QloApps.');
$return = false;
}

View File

@@ -115,99 +115,112 @@ class ContactControllerCore extends FrontController
WHERE cc.id_customer_thread = '.(int)$id_customer_thread.' AND cc.id_shop = '.(int)$this->context->shop->id.'
ORDER BY cm.date_add DESC');
if ($old_message == $message) {
$this->context->smarty->assign('alreadySent', 1);
$this->errors[] = Tools::displayError('Your message has already been sent.');
$_POST = array();
$contact->email = '';
$contact->customer_service = 0;
}
if ($contact->customer_service) {
if ((int)$id_customer_thread) {
$ct = new CustomerThread($id_customer_thread);
$ct->status = 'open';
$ct->id_lang = (int)$this->context->language->id;
$ct->id_contact = (int)$id_contact;
$ct->id_order = (int)$id_order;
if ($id_product = (int)Tools::getValue('id_product')) {
$ct->id_product = $id_product;
} else {
if ($contact->customer_service) {
if ((int)$id_customer_thread) {
$ct = new CustomerThread($id_customer_thread);
$ct->status = 'open';
$ct->id_lang = (int)$this->context->language->id;
$ct->id_contact = (int)$id_contact;
$ct->id_order = (int)$id_order;
if ($id_product = (int)Tools::getValue('id_product')) {
$ct->id_product = $id_product;
}
$ct->update();
} else {
$ct = new CustomerThread();
if (isset($customer->id)) {
$ct->id_customer = (int)$customer->id;
}
$ct->id_shop = (int)$this->context->shop->id;
$ct->id_order = (int)$id_order;
if ($id_product = (int)Tools::getValue('id_product')) {
$ct->id_product = $id_product;
}
$ct->id_contact = (int)$id_contact;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $from;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
}
$ct->update();
} else {
$ct = new CustomerThread();
if (isset($customer->id)) {
$ct->id_customer = (int)$customer->id;
}
$ct->id_shop = (int)$this->context->shop->id;
$ct->id_order = (int)$id_order;
if ($id_product = (int)Tools::getValue('id_product')) {
$ct->id_product = $id_product;
}
$ct->id_contact = (int)$id_contact;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $from;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
}
if ($ct->id) {
$cm = new CustomerMessage();
$cm->id_customer_thread = $ct->id;
$cm->message = $message;
if (isset($file_attachment['rename']) && !empty($file_attachment['rename']) && rename($file_attachment['tmp_name'], _PS_UPLOAD_DIR_.basename($file_attachment['rename']))) {
$cm->file_name = $file_attachment['rename'];
@chmod(_PS_UPLOAD_DIR_.basename($file_attachment['rename']), 0664);
}
$cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
if (!$cm->add()) {
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
}
} else {
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
}
}
if (!count($this->errors)) {
$var_list = array(
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
);
if (isset($file_attachment['name'])) {
$var_list['{attached_file}'] = $file_attachment['name'];
}
$id_product = (int)Tools::getValue('id_product');
if (isset($ct) && Validate::isLoadedObject($ct) && $ct->id_order) {
$order = new Order((int)$ct->id_order);
$var_list['{order_name}'] = $order->getUniqReference();
$var_list['{id_order}'] = (int)$order->id;
}
if ($id_product) {
$product = new Product((int)$id_product);
if (Validate::isLoadedObject($product) && isset($product->name[Context::getContext()->language->id])) {
$var_list['{product_name}'] = $product->name[Context::getContext()->language->id];
}
}
if (!empty($contact->email)) {
if (!Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form').' [no_sync]',
$var_list, $contact->email, $contact->name, null, null,
$file_attachment, null, _PS_MAIL_DIR_, false, null, null, $from)) {
if ($ct->id) {
$cm = new CustomerMessage();
$cm->id_customer_thread = $ct->id;
$cm->message = $message;
if (isset($file_attachment['rename']) && !empty($file_attachment['rename']) && rename($file_attachment['tmp_name'], _PS_UPLOAD_DIR_.basename($file_attachment['rename']))) {
$cm->file_name = $file_attachment['rename'];
@chmod(_PS_UPLOAD_DIR_.basename($file_attachment['rename']), 0664);
}
$cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
if (!$cm->add()) {
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
}
} else {
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
}
}
}
if (count($this->errors) > 1) {
array_unique($this->errors);
} elseif (!count($this->errors)) {
$this->context->smarty->assign('confirmation', 1);
if (!count($this->errors)) {
$var_list = array(
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
);
if (isset($file_attachment['name'])) {
$var_list['{attached_file}'] = $file_attachment['name'];
}
$id_product = (int)Tools::getValue('id_product');
if (isset($ct) && Validate::isLoadedObject($ct) && $ct->id_order) {
$order = new Order((int)$ct->id_order);
$var_list['{order_name}'] = $order->getUniqReference();
$var_list['{id_order}'] = (int)$order->id;
}
if ($id_product) {
$product = new Product((int)$id_product);
if (Validate::isLoadedObject($product) && isset($product->name[Context::getContext()->language->id])) {
$var_list['{product_name}'] = $product->name[Context::getContext()->language->id];
}
}
if (!empty($contact->email)) {
Mail::Send(
$this->context->language->id,
'contact',
Mail::l('Message from contact form').' [no_sync]',
$var_list,
$contact->email,
$contact->name,
null,
null,
$file_attachment,
null,
_PS_MAIL_DIR_,
false,
null,
null,
$from
);
}
}
if (count($this->errors) > 1) {
array_unique($this->errors);
} elseif (!count($this->errors)) {
Tools::redirect($this->context->link->getPageLink('contact', null, null, array('confirm' => 1)));
}
}
}
}
@@ -312,6 +325,7 @@ class ContactControllerCore extends FrontController
}
}
//End
$this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');
}

View File

@@ -249,6 +249,7 @@ class GuestTrackingControllerCore extends FrontController
$total_demands_price_ti = 0;
$total_convenience_fee_te = 0;
$total_convenience_fee_ti = 0;
foreach ($orderProducts as $type_key => $type_value) {
if (in_array($type_value['product_id'], $processedProducts)) {
continue;
@@ -306,13 +307,6 @@ class GuestTrackingControllerCore extends FrontController
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
if ($data_v['is_refunded']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1;
}
} else {
$num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
$cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
@@ -332,15 +326,6 @@ class GuestTrackingControllerCore extends FrontController
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0;
if ($data_v['is_refunded']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1;
}
}
$cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded'];

View File

@@ -83,339 +83,349 @@ class OrderDetailControllerCore extends FrontController
}
//by webkul to show order details properly on order history page
// if (Module::isInstalled('hotelreservationsystem')) {
// include_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
// $objHtlBranchInfo = new HotelBranchInformation();
$objBookingDetail = new HotelBookingDetail();
$objRoomType = new HotelRoomType();
$objBookingDemand = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$anyBackOrder = 0;
$processedProducts = array();
$cartHotelData = array();
$cartServiceProducts = array();
$total_demands_price_te = 0;
$total_demands_price_ti = 0;
$total_convenience_fee_te = 0;
$total_convenience_fee_ti = 0;
if (!empty($products)) {
foreach ($products as $type_key => $type_value) {
if (in_array($type_value['product_id'], $processedProducts)) {
continue;
}
if ($type_value['is_booking_product']) {
$processedProducts[] = $type_value['product_id'];
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default');
} else {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default');
}
if (isset($customer->id)) {
$obj_cart = new Cart($order->id_cart);
$order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $obj_cart->id_guest, $type_value['product_id'], $customer->id);
} else {
$order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $customer->id_guest, $type_value['product_id']);
}
$cartHotelData[$type_key]['id_product'] = $type_value['product_id'];
$cartHotelData[$type_key]['cover_img'] = $cover_img;
$objBookingDemand = new HotelBookingDemands();
foreach ($order_bk_data as $data_k => $data_v) {
$date_join = strtotime($data_v['date_from']).strtotime($data_v['date_to']);
$cartHotelData[$type_key]['adults'] = $data_v['adults'];
$cartHotelData[$type_key]['children'] = $data_v['children'];
/*Product price when order was created*/
$order_details_obj = new OrderDetail($data_v['id_order_detail']);
$cartHotelData[$type_key]['name'] = $order_details_obj->product_name;
$cartHotelData[$type_key]['paid_unit_price_tax_excl'] = ($order_details_obj->total_price_tax_excl)/$order_details_obj->product_quantity;
$cartHotelData[$type_key]['paid_unit_price_tax_incl'] = ($order_details_obj->total_price_tax_incl)/$order_details_obj->product_quantity;
if (isset($cartHotelData[$type_key]['date_diff'][$date_join])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
$num_days = $cartHotelData[$type_key]['date_diff'][$date_join]['num_days'];
$var_quant = (int) $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'];
$cartHotelData[$type_key]['date_diff'][$date_join]['adults'] += $data_v['adults'];
$cartHotelData[$type_key]['date_diff'][$date_join]['children'] += $data_v['children'];
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] += $data_v['total_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] += $data_v['total_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order'];
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
if ($data_v['is_refunded']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1;
}
} else {
$num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
$cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
$cartHotelData[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
$cartHotelData[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
$cartHotelData[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['adults'] = $data_v['adults'];
$cartHotelData[$type_key]['date_diff'][$date_join]['children'] = $data_v['children'];
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] = $data_v['total_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] = $data_v['total_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order'];
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0;
if ($data_v['is_refunded']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1;
}
}
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_htl_booking'] = $data_v['id'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_room'] = $data_v['id_room'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['adults'] = $data_v['adults'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['children'] = $data_v['children'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['child_ages'] = $data_v['child_ages'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_refunded'] = $data_v['is_refunded'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_cancelled'] = $data_v['is_cancelled'];
$cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded'];
$cartHotelData[$type_key]['date_diff'][$date_join]['ids_htl_booking_detail'][] = $data_v['id'];
$cartHotelData[$type_key]['date_diff'][$date_join]['ids_rooms'][] = $data_v['id_room'];
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands'] = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
$type_value['product_id'],
0,
$data_v['date_from'],
$data_v['date_to']
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] += $extraDemandPriceTI = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
$type_value['product_id'],
$data_v['id_room'],
$data_v['date_from'],
$data_v['date_to'],
0,
1,
1
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] += $extraDemandPriceTE = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
$type_value['product_id'],
$data_v['id_room'],
$data_v['date_from'],
$data_v['date_to'],
0,
1,
0
);
$total_demands_price_ti += $extraDemandPriceTI;
$total_demands_price_te += $extraDemandPriceTE;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_excl'] = $order_details_obj->unit_price_tax_excl;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_incl'] = $order_details_obj->unit_price_tax_incl;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_excl'] = $order_details_obj->unit_price_tax_excl + $order_details_obj->reduction_amount_tax_excl;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] = $order_details_obj->unit_price_tax_incl + $order_details_obj->reduction_amount_tax_incl;
$feature_price_diff = (float)($cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']);
$cartHotelData[$type_key]['date_diff'][$date_join]['feature_price_diff'] = $feature_price_diff;
$cartHotelData[$type_key]['hotel_name'] = $data_v['hotel_name'];
// add additional services products in hotel detail.
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to']
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] += $additionalServicesPriceTI = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
1
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] += $additionalServicesPriceTE = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
0
);
// get auto added price to be displayed with room price
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
1,
1,
Product::PRICE_ADDITION_TYPE_WITH_ROOM
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
0,
1,
Product::PRICE_ADDITION_TYPE_WITH_ROOM
);
}
// calculate averages now
foreach ($cartHotelData[$type_key]['date_diff'] as $key => &$value) {
$value['avg_paid_unit_price_tax_excl'] = Tools::ps_round($value['avg_paid_unit_price_tax_excl'] / $value['num_rm'], 6);
$value['avg_paid_unit_price_tax_incl'] = Tools::ps_round($value['avg_paid_unit_price_tax_incl'] / $value['num_rm'], 6);
$value['avg_price_diff_tax_excl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_excl'] - $value['product_price_tax_excl'], 6));
$value['avg_price_diff_tax_incl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_incl'] - $value['product_price_tax_incl'], 6));
}
} else if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITH_ROOMTYPE) {
if ($type_value['product_auto_add'] && $type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT) {
$total_convenience_fee_ti += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
$type_value['product_id'],
0,
0,
0,
0,
0,
1,
1,
1
);
$total_convenience_fee_te += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
$type_value['product_id'],
0,
0,
0,
0,
0,
1,
0,
1
);
}
} else {
// get all products that are independent.
if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default');
} else {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default');
}
$cartServiceProducts[] = $type_value;
}
}
}
$redirectTermsLink = $this->context->link->getCMSLink(new CMS(3, $this->context->language->id), null, $this->context->language->id);
}
$objHotelBookingDetail = new HotelBookingDetail();
$htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id);
$idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id);
$objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id);
$hotelAddressInfo = HotelBranchInformation::getAddress($idHotel);
$objHotelBranchRefundRules = new HotelBranchRefundRules();
$hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1);
$this->context->smarty->assign(
array(
'id_cms_refund_policy' => Configuration::get('WK_GLOBAL_REFUND_POLICY_CMS'),
'THEME_DIR' => _THEME_DIR_,
'total_convenience_fee_ti' => $total_convenience_fee_ti,
'total_convenience_fee_te' => $total_convenience_fee_te,
'total_demands_price_ti' => $total_demands_price_ti,
'total_demands_price_te' => $total_demands_price_te,
'any_back_order' => $anyBackOrder,
'shw_bo_msg' => Configuration::get('WK_SHOW_MSG_ON_BO'),
'back_ord_msg' => Configuration::get('WK_BO_MESSAGE'),
'order_has_invoice' => $order->hasInvoice(),
'cart_htl_data' => $cartHotelData,
'cart_service_products' => $cartServiceProducts,
'obj_hotel_branch_information' => $objHotelBranchInformation,
'hotel_address_info' => $hotelAddressInfo,
'hotel_refund_rules' => $hotelRefundRules,
)
);
// }
//To show order details properly on order history page
$objBookingDetail = new HotelBookingDetail();
$objRoomType = new HotelRoomType();
$objBookingDemand = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$anyBackOrder = 0;
$processedProducts = array();
$cartHotelData = array();
$cartServiceProducts = array();
$total_demands_price_te = 0;
$total_demands_price_ti = 0;
$total_convenience_fee_te = 0;
$total_convenience_fee_ti = 0;
$roomTypes = array();
$objOrderReturn = new OrderReturn();
$refundedAmount = 0;
if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) {
$refundedAmount = $objOrderReturn->getRefundedAmount($order->id);
}
if (!empty($products)) {
foreach ($products as $type_key => $type_value) {
if (in_array($type_value['product_id'], $processedProducts)) {
continue;
}
if ($type_value['is_booking_product']) {
$processedProducts[] = $type_value['product_id'];
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default');
} else {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default');
}
if (isset($customer->id)) {
$obj_cart = new Cart($order->id_cart);
$order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $obj_cart->id_guest, $type_value['product_id'], $customer->id);
} else {
$order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $customer->id_guest, $type_value['product_id']);
}
$cartHotelData[$type_key]['id_product'] = $type_value['product_id'];
$cartHotelData[$type_key]['cover_img'] = $cover_img;
$objBookingDemand = new HotelBookingDemands();
foreach ($order_bk_data as $data_k => $data_v) {
$date_join = strtotime($data_v['date_from']).strtotime($data_v['date_to']);
$cartHotelData[$type_key]['adults'] = $data_v['adults'];
$cartHotelData[$type_key]['children'] = $data_v['children'];
/*Product price when order was created*/
$order_details_obj = new OrderDetail($data_v['id_order_detail']);
$cartHotelData[$type_key]['name'] = $order_details_obj->product_name;
$cartHotelData[$type_key]['paid_unit_price_tax_excl'] = ($order_details_obj->total_price_tax_excl)/$order_details_obj->product_quantity;
$cartHotelData[$type_key]['paid_unit_price_tax_incl'] = ($order_details_obj->total_price_tax_incl)/$order_details_obj->product_quantity;
// Get last refund request for booking
if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($data_v['id_order'], 0, $data_v['id'])) {
$bookingRefundDetail = reset($bookingRefundDetail);
}
if (isset($cartHotelData[$type_key]['date_diff'][$date_join])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
$num_days = $cartHotelData[$type_key]['date_diff'][$date_join]['num_days'];
$var_quant = (int) $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'];
$cartHotelData[$type_key]['date_diff'][$date_join]['adults'] += $data_v['adults'];
$cartHotelData[$type_key]['date_diff'][$date_join]['children'] += $data_v['children'];
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] += $data_v['total_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] += $data_v['total_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order'];
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) {
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
} elseif ($bookingRefundDetail && $bookingRefundDetail['refunded'] && $bookingRefundDetail['id_customization']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
}
} else {
$num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
$cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
$cartHotelData[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
$cartHotelData[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
$cartHotelData[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['adults'] = $data_v['adults'];
$cartHotelData[$type_key]['date_diff'][$date_join]['children'] = $data_v['children'];
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days;
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] = $data_v['total_price_tax_incl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] = $data_v['total_price_tax_excl'];
$cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order'];
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0;
if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) {
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
} elseif ($bookingRefundDetail && $bookingRefundDetail['refunded'] && $bookingRefundDetail['id_customization']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
}
}
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_htl_booking'] = $data_v['id'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_room'] = $data_v['id_room'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['adults'] = $data_v['adults'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['children'] = $data_v['children'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['child_ages'] = $data_v['child_ages'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_refunded'] = $data_v['is_refunded'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_cancelled'] = $data_v['is_cancelled'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_status'] = $data_v['id_status'];
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['refund_denied'] = 0;
if ($bookingRefundDetail && $bookingRefundDetail['refunded'] && !$bookingRefundDetail['id_customization']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['refund_denied'] = 1;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded'];
$cartHotelData[$type_key]['date_diff'][$date_join]['ids_htl_booking_detail'][] = $data_v['id'];
$cartHotelData[$type_key]['date_diff'][$date_join]['ids_rooms'][] = $data_v['id_room'];
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands'] = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
$type_value['product_id'],
0,
$data_v['date_from'],
$data_v['date_to']
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] += $extraDemandPriceTI = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
$type_value['product_id'],
$data_v['id_room'],
$data_v['date_from'],
$data_v['date_to'],
0,
1,
1
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] += $extraDemandPriceTE = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
$type_value['product_id'],
$data_v['id_room'],
$data_v['date_from'],
$data_v['date_to'],
0,
1,
0
);
$total_demands_price_ti += $extraDemandPriceTI;
$total_demands_price_te += $extraDemandPriceTE;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_excl'] = $order_details_obj->unit_price_tax_excl;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_incl'] = $order_details_obj->unit_price_tax_incl;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_excl'] = $order_details_obj->unit_price_tax_excl + $order_details_obj->reduction_amount_tax_excl;
$cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] = $order_details_obj->unit_price_tax_incl + $order_details_obj->reduction_amount_tax_incl;
$feature_price_diff = (float)($cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']);
$cartHotelData[$type_key]['date_diff'][$date_join]['feature_price_diff'] = $feature_price_diff;
$cartHotelData[$type_key]['hotel_name'] = $data_v['hotel_name'];
// add additional services products in hotel detail.
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to']
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] += $additionalServicesPriceTI = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
1
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] += $additionalServicesPriceTE = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
0
);
// get auto added price to be displayed with room price
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
1,
1,
Product::PRICE_ADDITION_TYPE_WITH_ROOM
);
if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'])) {
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] = 0;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
0,
0,
$type_value['product_id'],
$data_v['date_from'],
$data_v['date_to'],
$data_v['id_room'],
1,
0,
1,
Product::PRICE_ADDITION_TYPE_WITH_ROOM
);
}
// calculate averages now
foreach ($cartHotelData[$type_key]['date_diff'] as $key => &$value) {
$value['avg_paid_unit_price_tax_excl'] = Tools::ps_round($value['avg_paid_unit_price_tax_excl'] / $value['num_rm'], 6);
$value['avg_paid_unit_price_tax_incl'] = Tools::ps_round($value['avg_paid_unit_price_tax_incl'] / $value['num_rm'], 6);
$value['avg_price_diff_tax_excl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_excl'] - $value['product_price_tax_excl'], 6));
$value['avg_price_diff_tax_incl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_incl'] - $value['product_price_tax_incl'], 6));
}
} else if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITH_ROOMTYPE) {
if ($type_value['product_auto_add'] && $type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT) {
$total_convenience_fee_ti += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
$type_value['product_id'],
0,
0,
0,
0,
0,
1,
1,
1
);
$total_convenience_fee_te += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$id_order,
$type_value['product_id'],
0,
0,
0,
0,
0,
1,
0,
1
);
}
} else {
// get all products that are independent.
if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default');
} else {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default');
}
$cartServiceProducts[] = $type_value;
}
}
$roomTypes[$type_value['id_product']] = $type_value;
}
$redirectTermsLink = $this->context->link->getCMSLink(new CMS(3, $this->context->language->id), null, $this->context->language->id);
}
$objHotelBookingDetail = new HotelBookingDetail();
$htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id);
$idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id);
$objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id);
$hotelAddressInfo = HotelBranchInformation::getAddress($idHotel);
$objHotelBranchRefundRules = new HotelBranchRefundRules();
$hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1);
$this->context->smarty->assign(
array(
'id_cms_refund_policy' => Configuration::get('WK_GLOBAL_REFUND_POLICY_CMS'),
'THEME_DIR' => _THEME_DIR_,
'total_convenience_fee_ti' => $total_convenience_fee_ti,
'total_convenience_fee_te' => $total_convenience_fee_te,
'total_demands_price_ti' => $total_demands_price_ti,
'total_demands_price_te' => $total_demands_price_te,
'any_back_order' => $anyBackOrder,
'shw_bo_msg' => Configuration::get('WK_SHOW_MSG_ON_BO'),
'back_ord_msg' => Configuration::get('WK_BO_MESSAGE'),
'order_has_invoice' => $order->hasInvoice(),
'cart_htl_data' => $cartHotelData,
'cart_service_products' => $cartServiceProducts,
'obj_hotel_branch_information' => $objHotelBranchInformation,
'hotel_address_info' => $hotelAddressInfo,
'hotel_refund_rules' => $hotelRefundRules,
)
);
$this->context->smarty->assign(
array(
'hasOrderPaid' => $order->hasBeenPaid(),
@@ -423,7 +433,7 @@ class OrderDetailControllerCore extends FrontController
'refund_allowed' => (int) $order->isReturnable(),
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'refundReqBookings' => $refundReqBookings,
'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG),
'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(0, 1),
'refundedAmount' => $refundedAmount,
'shop_name' => strval(Configuration::get('PS_SHOP_NAME')),
'order' => $order,
@@ -437,6 +447,7 @@ class OrderDetailControllerCore extends FrontController
'order_history' => $order->getHistory($this->context->language->id, false, true),
'overbooking_order_states' => OrderState::getOverBookingStates(),
'products' => $products,
'roomTypes' => $roomTypes,
'discounts' => $order->getCartRules(),
'carrier' => $carrier,
'address_invoice' => $addressInvoice,
@@ -455,6 +466,9 @@ class OrderDetailControllerCore extends FrontController
'use_tax' => Configuration::get('PS_TAX'),
'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC),
'reorderingAllowed' => !(bool) Configuration::get('PS_DISALLOW_HISTORY_REORDERING'),
'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED,
'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN,
'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT,
)
);
@@ -561,6 +575,12 @@ class OrderDetailControllerCore extends FrontController
break;
}
// the room has already been checked in/checked out, room will not be able to be cancelled by the customer
if ($objHotelBookingDetail->id_status != HotelBookingDetail::STATUS_ALLOTED) {
$this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out.');
break;
}
if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, $idHtlBooking)) {
$this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.');
break;
@@ -569,66 +589,61 @@ class OrderDetailControllerCore extends FrontController
}
if (!count($this->errors)) {
if ((int) $objOrder->total_paid_real == 0) {
// create refund request
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $objOrder->id_customer;
$objOrderReturn->id_order = $objOrder->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 0;
$objOrderReturn->question = $cancellationReason;
$objOrderReturn->refunded_amount = 0;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$objHtlBooking->save();
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->refunded_amount = 0;
if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) {
$objOrderReturnDetail->id_customization = 1;
}
$objOrderReturnDetail->save();
}
}
// if amount paid is > 0 then create refund request else cancel the booking directly
if ($objOrder->getTotalPaid() > 0) {
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $objOrder->id_customer;
$objOrderReturn->id_order = $objOrder->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 0;
$objOrderReturn->question = $cancellationReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
$numDays = $objHotelBookingDetail->getNumberOfDays(
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to
);
// Emails to customer, superadmin and employees on refund request state change
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHotelBookingDetail->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->save();
}
}
// Emails to customer, superadmin and employees on refund request state change
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
} else {
// cancel the booking directly
if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) {
// Process refund in booking tables
foreach ($idsHtlBooking as $idHtlBooking) {
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if (!$objHotelBookingDetail->processRefundInBookingTables()) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
} else {
// set the message for the cancellation
$message = Tools::displayError(sprintf(
"1 room from %s has been cancelled by hotel.\nReason: %s",
$objHotelBookingDetail->room_type_name,
$cancellationReason
));
$objHotelBookingDetail->setBookingCancellationMessage($message);
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
if (!$objHtlBooking->processRefundInBookingTables()) {
$this->errors[] = Tools::displayError('An error occurred while cancelling the booking.');
}
}
// complete the booking refund directly in the refund request
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED'));
// if all bookings are getting cancelled then cancel the order also
if ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
// if all bookings are getting cancelled/Refunded then Cancel/Refund the order also
$idOrderState = 0;
if ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
$idOrderState = Configuration::get('PS_OS_REFUND');
} elseif ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
$idOrderState = Configuration::get('PS_OS_CANCELED');
}
if ($idOrderState) {
$objOrderHistory = new OrderHistory();
$objOrderHistory->id_order = (int)$objOrder->id;
$idOrderState = Configuration::get('PS_OS_CANCELED');
$useExistingPayment = false;
if (!$objOrder->hasInvoice()) {
$useExistingPayment = true;
@@ -805,4 +820,4 @@ class OrderDetailControllerCore extends FrontController
}
}
}
}
}

View File

@@ -591,7 +591,6 @@ class OrderOpcControllerCore extends ParentOrderController
if (!empty($cartProducts)) {
if ($cartBookingInfo = HotelCartBookingData::getHotelCartBookingData()) {
// ddd($cartBookingInfo);
$this->context->smarty->assign('cart_htl_data', $cartBookingInfo);
}
$objHotelServiceProductCartDetail = new HotelServiceProductCartDetail();
@@ -1078,21 +1077,52 @@ class OrderOpcControllerCore extends ParentOrderController
$customerGuestDetailLastname = Tools::getValue('customer_guest_detail_lastname');
$customerGuestDetailEmail = Tools::getValue('customer_guest_detail_email');
$customerGuestDetailPhone = Tools::getValue('customer_guest_detail_phone');
$className = 'CartCustomerGuestDetail';
$rules = call_user_func(array($className, 'getValidationRules'), $className);
if (trim($customerGuestDetailGender) && Validate::isUnsignedInt($customerGuestDetailGender)) {
$objCustomerGuestDetail->id_gender = $customerGuestDetailGender;
} else {
$result['errors']['customer_guest_detail_gender'] = Tools::displayError('Invalid gender');
}
if (trim($customerGuestDetailFirstname) && Validate::isName($customerGuestDetailFirstname)) {
if (trim($customerGuestDetailFirstname)
&& Validate::isName($customerGuestDetailFirstname)
&& (!isset($rules['size']['firstname'])
|| (isset($rules['size']['firstname']) && (Tools::strlen(trim($customerGuestDetailFirstname)) <= $rules['size']['firstname']))
)
) {
$objCustomerGuestDetail->firstname = $customerGuestDetailFirstname;
}
if (trim($customerGuestDetailLastname) && Validate::isName($customerGuestDetailLastname)) {
if (trim($customerGuestDetailLastname)
&& Validate::isName($customerGuestDetailLastname)
&& (!isset($rules['size']['lastname'])
|| (isset($rules['size']['lastname']) && (Tools::strlen(trim($customerGuestDetailLastname)) <= $rules['size']['lastname']))
)
) {
$objCustomerGuestDetail->lastname = $customerGuestDetailLastname;
}
if (trim($customerGuestDetailEmail) && Validate::isEmail($customerGuestDetailEmail)) {
if (trim($customerGuestDetailEmail)
&& Validate::isEmail($customerGuestDetailEmail)
&& (!isset($rules['size']['email'])
|| (isset($rules['size']['email']) && (Tools::strlen(trim($customerGuestDetailEmail)) <= $rules['size']['email']))
)
) {
$objCustomerGuestDetail->email = $customerGuestDetailEmail;
}
if (trim($customerGuestDetailPhone) && Validate::isPhoneNumber($customerGuestDetailPhone)) {
if (trim($customerGuestDetailPhone)
&& Validate::isPhoneNumber($customerGuestDetailPhone)
&& (!isset($rules['size']['phone'])
|| (isset($rules['size']['phone']) && (Tools::strlen(trim($customerGuestDetailPhone)) <= $rules['size']['phone']))
)
) {
$objCustomerGuestDetail->phone = $customerGuestDetailPhone;
}
$objCustomerGuestDetail->id_cart = $this->context->cart->id;
$objCustomerGuestDetail->save();
} else {
@@ -1102,6 +1132,7 @@ class OrderOpcControllerCore extends ParentOrderController
}
}
}
$this->context->cart->save();
}
}

View File

@@ -50,22 +50,23 @@ class OrderReturnControllerCore extends FrontController
$objOrder = new Order($objOrderReturn->id_order);
$orderCurrency = new Currency($objOrder->id_currency);
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrderReturn->id_order, $objOrderReturn->id, 0, 1);
$isCanceled = false;
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrderReturn->id_order, $objOrderReturn->id);
$isCanceledBookings = false;
if (count(array_unique(array_column($refundReqBookings, 'is_cancelled'))) === 1
&& array_unique(array_column($refundReqBookings, 'is_cancelled'))[0] != 0
) {
$isCanceled = true;
$isCanceledBookings = true;
}
$voucher = '';
if (Validate::isLoadedObject($objCartRule = new CartRule($objOrderReturn->id_return_type))) {
$voucher = $objCartRule->name[$this->context->language->id];
}
$this->context->smarty->assign(
array (
'orderReturnInfo' => (array)$objOrderReturn,
'refundReqBookings' => $refundReqBookings,
'isCanceled' => $isCanceled,
'isCanceledBookings' => $isCanceledBookings,
'orderInfo' => (array) $objOrder,
'orderCurrency' => (array) $orderCurrency,
'currentStateInfo' => (array) new OrderReturnState($objOrderReturn->state,