Update design of customer order detail page

This commit is contained in:
Abhishek Kumar
2024-02-26 20:01:39 +05:30
parent 9af78bcf14
commit 154e74fd5d
21 changed files with 3083 additions and 2027 deletions

View File

@@ -43,249 +43,19 @@ class OrderDetailControllerCore extends FrontController
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
}
/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
if (Tools::isSubmit('submitMessage')) {
$idOrder = (int)Tools::getValue('id_order');
$msgText = Tools::getValue('msgText');
if (!$idOrder || !Validate::isUnsignedId($idOrder)) {
$this->errors[] = Tools::displayError('The order is no longer valid.');
} elseif (empty($msgText)) {
$this->errors[] = Tools::displayError('The message cannot be blank.');
} elseif (!Validate::isMessage($msgText)) {
$this->errors[] = Tools::displayError('This message is invalid (HTML is not allowed).');
}
if (!count($this->errors)) {
$order = new Order($idOrder);
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
//check if a thread already exist
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id);
$id_product = (int)Tools::getValue('id_product');
$cm = new CustomerMessage();
if (!$id_customer_thread) {
$ct = new CustomerThread();
$ct->id_contact = 0;
$ct->id_customer = (int)$order->id_customer;
$ct->id_shop = (int)$this->context->shop->id;
if ($id_product && $order->orderContainProduct($id_product)) {
$ct->id_product = $id_product;
}
$ct->id_order = (int)$order->id;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $this->context->customer->email;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
} else {
$ct = new CustomerThread((int)$id_customer_thread);
$ct->status = 'open';
$ct->update();
}
$cm->id_customer_thread = $ct->id;
$cm->message = $msgText;
$cm->ip_address = (int)ip2long($_SERVER['REMOTE_ADDR']);
$cm->add();
if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) {
$to = strval(Configuration::get('PS_SHOP_EMAIL'));
} else {
$to = new Contact((int)Configuration::get('PS_MAIL_EMAIL_MESSAGE'));
$to = strval($to->email);
}
$toName = strval(Configuration::get('PS_SHOP_NAME'));
$customer = $this->context->customer;
$product = new Product($id_product);
$product_name = '';
if (Validate::isLoadedObject($product) && isset($product->name[(int)$this->context->language->id])) {
$product_name = $product->name[(int)$this->context->language->id];
}
if (Validate::isLoadedObject($customer)) {
Mail::Send(
$this->context->language->id,
'order_customer_comment',
Mail::l('Message from a customer'),
array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{email}' => $customer->email,
'{id_order}' => (int)$order->id,
'{order_name}' => $order->getUniqReference(),
'{message}' => Tools::nl2br($msgText),
'{product_name}' => $product_name
),
$to,
$toName,
strval(Configuration::get('PS_SHOP_EMAIL')),
$customer->firstname.' '.$customer->lastname,
null,
null,
_PS_MAIL_DIR_,
false,
null,
null,
$customer->email
);
}
if (Tools::getValue('ajax') != 'true') {
Tools::redirect('index.php?controller=order-detail&id_order='.(int)$idOrder);
}
$this->context->smarty->assign('message_confirmation', true);
} else {
$this->errors[] = Tools::displayError('Order not found');
}
}
}
}
public function displayAjax()
{
$this->display();
}
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
$this->show_breadcrump = true;
parent::initContent();
if (!($id_order = (int) Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order)) {
$this->errors[] = Tools::displayError('Order ID required');
Tools::redirect($this->context->link->getPageLink('history'));
} else {
$order = new Order($id_order);
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
// Here handle request from the ajax on order details page i.e refund, additional qty etc
$method = Tools::getValue('method');
// extra demands popup ajax
if ($method == 'getRoomTypeBookingDemands') {
$response = array('reload' => false);
if (($idProduct = Tools::getValue('id_product'))
&& ($idOrder = Tools::getValue('id_order'))
&& ($dateFrom = Tools::getValue('date_from'))
&& ($dateTo = Tools::getValue('date_to'))
) {
$objBookingDemand = new HotelBookingDemands();
$useTax = 0;
$customer = Context::getContext()->customer;
if (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC) {
$useTax = 1;
}
if ($extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands(
$idOrder,
$idProduct,
0,
$dateFrom,
$dateTo,
1,
0,
$useTax
)) {
$this->context->smarty->assign(
array(
'useTax' => $useTax,
'extraDemands' => $extraDemands,
)
);
}
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
if ($additionalServices = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$idOrder,
0,
0,
$idProduct,
$dateFrom,
$dateTo,
0,
0,
$useTax
)) {
$this->context->smarty->assign(array(
'useTax' => $useTax,
'additionalServices' => $additionalServices,
));
}
$response['extra_demands'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'_partials/order_booking_demands.tpl');
}
die(json_encode($response));
} elseif ($method == 'submitRefundRequest') { // room cancellation ajax
$hasError = 0;
if (!$refundReason = Tools::getValue('cancellation_reason')) {
$hasError = 1;
} elseif (!Validate::isCleanHtml($refundReason)) {
$hasError = 1;
}
if ($bookingRefunds = Tools::getValue('bookings_to_refund')) {
if (!count($bookingRefunds = json_decode($bookingRefunds, true))) {
$hasError = 1;
} else {
foreach ($bookingRefunds as $idHtlBooking) {
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if ($objHotelBookingDetail->id_customer != $order->id_customer
|| OrderReturn::getOrdersReturnDetail($order->id, 0, $idHtlBooking)
) {
$hasError = 1;
break;
}
}
}
} else {
$hasError = 1;
}
$res = true;
if (!$hasError) {
if ((int)$order->total_paid_real == 0){
foreach ($bookingRefunds as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$objHtlBooking->save();
}
}
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 0;
$objOrderReturn->question = $refundReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($bookingRefunds 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();
}
}
// Emails to customer, admin on refund request state change
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
die(json_encode(array('status' => 1)));
}
die(json_encode(array('status' => 0)));
}
} else {
die(json_encode(array('status' => 0)));
}
// END ajax request handle
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
$id_order_state = (int)$order->getCurrentState();
$carrier = new Carrier((int)$order->id_carrier, (int)$order->id_lang);
@@ -343,9 +113,9 @@ class OrderDetailControllerCore extends FrontController
$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'], 'small_default');
$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', 'small_default');
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default');
}
if (isset($customer->id)) {
@@ -426,9 +196,18 @@ class OrderDetailControllerCore extends FrontController
}
}
$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,
@@ -604,6 +383,9 @@ class OrderDetailControllerCore extends FrontController
$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);
$this->context->smarty->assign(
array(
'id_cms_refund_policy' => Configuration::get('WK_GLOBAL_REFUND_POLICY_CMS'),
@@ -619,6 +401,8 @@ class OrderDetailControllerCore extends FrontController
'cart_htl_data' => $cartHotelData,
'cart_service_products' => $cartServiceProducts,
'non_requested_rooms' => $nonRequestedRooms,
'obj_hotel_branch_information' => $objHotelBranchInformation,
'hotel_address_info' => $hotelAddressInfo,
)
);
// }
@@ -628,6 +412,7 @@ class OrderDetailControllerCore extends FrontController
if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) {
$refundedAmount = $objOrderReturn->getRefundedAmount($order->id);
}
$this->context->smarty->assign(
array(
'hasOrderPaid' => $order->hasBeenPaid(),
@@ -685,12 +470,292 @@ class OrderDetailControllerCore extends FrontController
$this->setTemplate(_PS_THEME_DIR_.'order-detail.tpl');
}
public function displayAjaxGetRoomTypeBookingDemands()
{
$response = array('extra_demands' => false);
if (($idProduct = Tools::getValue('id_product'))
&& ($idOrder = Tools::getValue('id_order'))
&& ($dateFrom = Tools::getValue('date_from'))
&& ($dateTo = Tools::getValue('date_to'))
) {
$objHotelBookingDemands = new HotelBookingDemands();
$useTax = 0;
if (Group::getPriceDisplayMethod($this->context->customer->id_default_group) == PS_TAX_INC) {
$useTax = 1;
}
if ($extraDemands = $objHotelBookingDemands->getRoomTypeBookingExtraDemands(
$idOrder,
$idProduct,
0,
$dateFrom,
$dateTo,
1,
0,
$useTax
)) {
$this->context->smarty->assign(array(
'useTax' => $useTax,
'extraDemands' => $extraDemands,
));
}
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
if ($additionalServices = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$idOrder,
0,
0,
$idProduct,
$dateFrom,
$dateTo,
0,
0,
$useTax
)) {
$this->context->smarty->assign(array(
'useTax' => $useTax,
'additionalServices' => $additionalServices,
));
}
$response['extra_demands'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'_partials/order_booking_demands.tpl');
}
$this->ajaxDie(json_encode($response));
}
public function displayAjaxSubmitRefundRequest()
{
$response = array('has_errors' => false);
$idOrder = Tools::getValue('id_order');
$idsHtlBooking = Tools::getValue('bookings_to_refund');
$cancellationReason = trim(Tools::getValue('cancellation_reason'));
if (!$idsHtlBooking) {
$this->errors[] = Tools::displayError('Please select at least on room for cancellation.');
}
if (!$cancellationReason) {
$this->errors[] = Tools::displayError('Please mention a reason for cancellation.');
} elseif ($cancellationReason && !Validate::isCleanHtml($cancellationReason)) {
$this->errors[] = Tools::displayError('Reason of cancellation is invalid. Please enter valid data.');
}
if (!count($this->errors)) {
$objOrder = new Order($idOrder);
if (!(Validate::isLoadedObject($objOrder) && $objOrder->id_customer == $this->context->customer->id)) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
} elseif ($idsHtlBooking) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if ($objHotelBookingDetail->id_customer != $objOrder->id_customer) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
break;
}
if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, $idHtlBooking)) {
$this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.');
break;
}
}
}
if (!count($this->errors)) {
if ((int) $objOrder->total_paid_real == 0) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$objHtlBooking->save();
}
}
$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
);
$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'));
}
}
if (count($this->errors)) {
$this->context->smarty->assign(array('errors' => $this->errors));
$response['errors_html'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'errors.tpl');
}
$response['has_errors'] = (bool) count($this->errors);
$this->ajaxDie(json_encode($response));
}
public function displayAjaxSubmitMessage()
{
$response = array('status' => false);
$idOrder = (int) Tools::getValue('id_order');
$msgText = Tools::getValue('msgText');
if (!$idOrder || !Validate::isUnsignedId($idOrder)) {
$this->errors[] = Tools::displayError('The order is no longer valid.');
} elseif (empty($msgText)) {
$this->errors[] = Tools::displayError('The message cannot be blank.');
} elseif (!Validate::isMessage($msgText)) {
$this->errors[] = Tools::displayError('This message is invalid (HTML is not allowed).');
}
if (!count($this->errors)) {
$order = new Order($idOrder);
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
//check if a thread already exist
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id);
$id_product = (int)Tools::getValue('id_product');
$cm = new CustomerMessage();
if (!$id_customer_thread) {
$ct = new CustomerThread();
$ct->id_contact = 0;
$ct->id_customer = (int)$order->id_customer;
$ct->id_shop = (int)$this->context->shop->id;
if ($id_product && $order->orderContainProduct($id_product)) {
$ct->id_product = $id_product;
}
$ct->id_order = (int)$order->id;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $this->context->customer->email;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
} else {
$ct = new CustomerThread((int)$id_customer_thread);
$ct->status = 'open';
$ct->update();
}
$cm->id_customer_thread = $ct->id;
$cm->message = $msgText;
$cm->ip_address = (int)ip2long($_SERVER['REMOTE_ADDR']);
$cm->add();
if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) {
$to = strval(Configuration::get('PS_SHOP_EMAIL'));
} else {
$to = new Contact((int)Configuration::get('PS_MAIL_EMAIL_MESSAGE'));
$to = strval($to->email);
}
$toName = strval(Configuration::get('PS_SHOP_NAME'));
$customer = $this->context->customer;
$product = new Product($id_product);
$product_name = '';
if (Validate::isLoadedObject($product) && isset($product->name[(int)$this->context->language->id])) {
$product_name = $product->name[(int)$this->context->language->id];
}
if (Validate::isLoadedObject($customer)) {
Mail::Send(
$this->context->language->id,
'order_customer_comment',
Mail::l('Message from a customer'),
array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{email}' => $customer->email,
'{id_order}' => (int)$order->id,
'{order_name}' => $order->getUniqReference(),
'{message}' => Tools::nl2br($msgText),
'{product_name}' => $product_name
),
$to,
$toName,
strval(Configuration::get('PS_SHOP_EMAIL')),
$customer->firstname.' '.$customer->lastname,
null,
null,
_PS_MAIL_DIR_,
false,
null,
null,
$customer->email
);
}
// send message html in json
$response['status'] = true;
$message = CustomerMessage::getMessagesByOrderId($order->id, false)[0];
$this->context->smarty->assign(array('message' => $message));
$response['message_html'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'_partials/booking-message.tpl');
} else {
$this->errors[] = Tools::displayError('Order not found');
}
}
if (count($this->errors)) {
$this->context->smarty->assign(array('errors' => $this->errors));
$response['errors_html'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'errors.tpl');
}
$response['has_errors'] = (bool) count($this->errors);
$this->ajaxDie(json_encode($response));
}
public function setMedia()
{
if (Tools::getValue('ajax') != 'true') {
parent::setMedia();
$this->addCSS(_THEME_CSS_DIR_.'history.css');
$this->addCSS(_THEME_CSS_DIR_.'addresses.css');
$this->addCSS(_THEME_CSS_DIR_.'order-detail.css');
$this->addJS(array(
_THEME_JS_DIR_.'order-detail.js',
_THEME_JS_DIR_.'tools.js',
));
$this->addJqueryPlugin(array('fancybox', 'scrollTo', 'footable', 'footable-sort'));
$this->addJqueryUI(array('ui.tooltip'), 'base', true);
// load Google Maps library if configured
if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder(Tools::getValue('id_order'))) {
$objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id);
if (Validate::isLoadedObject($objHotelBranchInformation)) {
if ($apiKey = Configuration::get('PS_API_KEY')) {
if (floatval($objHotelBranchInformation->latitude) != 0
&& floatval($objHotelBranchInformation->longitude) != 0
) {
Media::addJsDef(array(
'hotel_location' => array(
'latitude' => $objHotelBranchInformation->latitude,
'longitude' => $objHotelBranchInformation->longitude,
'map_input_text' => $objHotelBranchInformation->map_input_text,
),
'hotel_name' => $objHotelBranchInformation->hotel_name,
));
$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='.
$this->context->language->iso_code.'&region='.$this->context->country->iso_code
);
}
}
}
}
}
}
}
}