From 3366f35b907559cdbdf830b4d0419924b40e6de5 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 4 Aug 2023 16:46:17 +0530 Subject: [PATCH 1/2] Redirect free order to order confirmation page --- .../front/OrderConfirmationController.php | 15 ++++++++++++--- controllers/front/OrderOpcController.php | 11 ++++++++++- .../hotel-reservation-theme/js/order-opc.js | 19 +++++++++---------- .../order-confirmation.tpl | 3 +++ themes/hotel-reservation-theme/order-opc.tpl | 1 - 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index 560e8c444..ba932fc3f 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -67,9 +67,16 @@ class OrderConfirmationControllerCore extends FrontController if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) { Tools::redirect($redirectLink); } - $module = Module::getInstanceById((int)($this->id_module)); - if ($order->module != $module->name) { - Tools::redirect($redirectLink); + + if ($this->id_module == -1) { + if ($order->module != 'free_order') { + Tools::redirect($redirectLink); + } + } else { + $module = Module::getInstanceById((int)($this->id_module)); + if ($order->module != $module->name) { + Tools::redirect($redirectLink); + } } } @@ -83,6 +90,7 @@ class OrderConfirmationControllerCore extends FrontController $this->context->smarty->assign(array( 'is_guest' => $this->context->customer->is_guest, + 'is_free_order' => 1, 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(), 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn() )); @@ -405,6 +413,7 @@ class OrderConfirmationControllerCore extends FrontController $this->context->smarty->assign( array( 'refund_allowed' => (int) $order->isReturnable(), + 'is_free_order' => $this->id_module == -1 && $order->module == 'free_order', 'any_back_order' => $any_back_order, 'shw_bo_msg' => $shw_bo_msg, 'back_ord_msg' => $bo_msg, diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 17ef02dcb..38e7393fd 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -221,10 +221,19 @@ class OrderOpcControllerCore extends ParentOrderController if (($id_order = $this->_checkFreeOrder()) && $id_order) { $order = new Order((int)$id_order); $email = $this->context->customer->email; + $orderConfirmationUrl = $this->context->link->getPageLink('order-confirmation').'?id_cart='.$order->id_cart.'&id_module=-1'.'&id_order='.$id_order.'&key='.$order->secure_key; if ($this->context->customer->is_guest) { $this->context->customer->logout(); } // If guest we clear the cookie for security reason - $this->ajaxDie('freeorder:'.$order->reference.':'.$email); + + $return = array( + 'success' => true, + 'reference' => $order->reference, + 'email' => $email, + 'order_confirmation_url' => $orderConfirmationUrl, + ); + + $this->ajaxDie(json_encode($return)); } exit; break; diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index 0649a68dd..a0ce3df05 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -912,18 +912,17 @@ function confirmFreeOrder() url: orderOpcUrl + '?rand=' + new Date().getTime(), async: true, cache: false, - dataType : "html", + dataType : 'JSON', data: 'ajax=true&method=makeFreeOrder&token=' + static_token , - success: function(html) + success: function(response) { - $('#confirmOrder').prop('disabled', false); - var array_split = html.split(':'); - if (array_split[0] == 'freeorder') - { - if (isGuest) - document.location.href = guestTrackingUrl+'?id_order='+encodeURIComponent(array_split[1])+'&email='+encodeURIComponent(array_split[2]); - else - document.location.href = historyUrl; + if (response.success) { + $('#confirmOrder').prop('disabled', false); + if (isGuest) { + document.location.href = guestTrackingUrl+'?id_order='+encodeURIComponent(response.reference)+'&email='+encodeURIComponent(response.email); + } else { + document.location.href = response.order_confirmation_url; + } } }, error: function(XMLHttpRequest, textStatus, errorThrown) { diff --git a/themes/hotel-reservation-theme/order-confirmation.tpl b/themes/hotel-reservation-theme/order-confirmation.tpl index 23ac2a1fa..093669112 100644 --- a/themes/hotel-reservation-theme/order-confirmation.tpl +++ b/themes/hotel-reservation-theme/order-confirmation.tpl @@ -42,6 +42,9 @@ {l s='Follow my order'}

{else} + {if isset($is_free_order) && $is_free_order} +

{l s='Your order on %s is complete.' sprintf=$shop_name}


+ {/if}

{l s='Order Status :'} {l s='Confirmed'}

{l s='Order Reference :'} {$order->reference}

{if $any_back_order} diff --git a/themes/hotel-reservation-theme/order-opc.tpl b/themes/hotel-reservation-theme/order-opc.tpl index 8cdc91e23..72c2bec65 100644 --- a/themes/hotel-reservation-theme/order-opc.tpl +++ b/themes/hotel-reservation-theme/order-opc.tpl @@ -460,7 +460,6 @@ {addJsDef imgDir=$img_dir} {addJsDef authenticationUrl=$link->getPageLink("authentication", true)|escape:'quotes':'UTF-8'} {addJsDef orderOpcUrl=$link->getPageLink("order-opc", true)|escape:'quotes':'UTF-8'} - {addJsDef historyUrl=$link->getPageLink("history", true)|escape:'quotes':'UTF-8'} {addJsDef guestTrackingUrl=$link->getPageLink("guest-tracking", true)|escape:'quotes':'UTF-8'} {addJsDef addressUrl=$link->getPageLink("address", true, NULL, "back={$back_order_page}")|escape:'quotes':'UTF-8'} {addJsDef orderProcess='order-opc'} From 0a46c43626fcf074e4f3757ee62cdf2ea35b0a2a Mon Sep 17 00:00:00 2001 From: abhishek-webkul <84142535+abhishek-webkul@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:43:44 +0530 Subject: [PATCH 2/2] Update OrderConfirmationController.php --- controllers/front/OrderConfirmationController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index ba932fc3f..40955333f 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -90,7 +90,6 @@ class OrderConfirmationControllerCore extends FrontController $this->context->smarty->assign(array( 'is_guest' => $this->context->customer->is_guest, - 'is_free_order' => 1, 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(), 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn() ));