diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index a4660529c..ee6601751 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -135,6 +135,34 @@ class OrderOpcControllerCore extends ParentOrderController $this->ajaxDie(json_encode($return)); break; + case 'transformGuestAccount': + $passwd = Tools::getValue('passwd'); + + if (!$passwd) { + $this->errors[] = Tools::displayError('Please enter a password.'); + } + + if ($passwd && !Validate::isPasswd($passwd)) { + $this->errors[] = Tools::displayError('Please enter a valid password.'); + } + + if (!count($this->errors)) { + $customer = new Customer($this->context->customer->id); + if ($customer->transformToCustomer($this->context->language->id, $passwd)) { + $this->updateContext($customer); + } else { + $this->errors[] = Tools::displayError('An error occurred while transforming your account into a registered customer.'); + } + } + + $return = array( + 'hasError' => !empty($this->errors), + 'errors' => $this->errors, + ); + + $this->ajaxDie(json_encode($return)); + break; + case 'getAddressBlockAndCarriersAndPayments': if ($this->context->customer->isLogged() || $this->context->customer->isGuest()) { // check if customer have addresses @@ -964,4 +992,20 @@ class OrderOpcControllerCore extends ParentOrderController } die('0'); } + + public function updateContext(Customer $customer) + { + $this->context->cookie->id_customer = (int)$customer->id; + $this->context->cookie->customer_lastname = $customer->lastname; + $this->context->cookie->customer_firstname = $customer->firstname; + $this->context->cookie->passwd = $customer->passwd; + $this->context->cookie->logged = 1; + $this->context->cookie->email = $customer->email; + $this->context->cookie->is_guest = 0; + + $this->context->cart->secure_key = $customer->secure_key; + + $customer->logged = 1; + $this->context->customer = $customer; + } } diff --git a/themes/hotel-reservation-theme/css/order-opc.css b/themes/hotel-reservation-theme/css/order-opc.css index 5124ad9a2..68d7fa248 100644 --- a/themes/hotel-reservation-theme/css/order-opc.css +++ b/themes/hotel-reservation-theme/css/order-opc.css @@ -91,6 +91,20 @@ /* By Webkul */ +.strikethrough { + width: 100%; + text-align: center; + border-bottom: 1px solid #777; + line-height: 0.1em; + margin: 10px 0 25px; +} + +.strikethrough span { + background: #fff; + color: #333; + padding:0 10px; +} + #title { font-size: 13px; color: #3C3C3C; @@ -264,6 +278,9 @@ .order-detail-content .room_remove_block i { font-size: 18px; } +#order-opc #guest-info-block { + position: relative; +} #order-opc #guest-info-block div.info-head { font-size: 14px; color: #555555; @@ -312,6 +329,16 @@ font-weight: 600; } +#order-opc #login_form_content .text-secondary { + color: #333; + font-size: 14px; +} + +#order-opc #login_form_content #idAccountChoice { + color: #003AEF; + font-weight: 600; +} + #new_account_form #opc_guestCheckout { padding: 14px 25px; } @@ -552,6 +579,10 @@ padding-top: 0px; } +#order-opc #opc_account_errors { + margin-top: 10px +} + /* buttons css */ #order-opc .opc-button-small { border: none; @@ -570,7 +601,7 @@ color: #1292FF; } #order-opc .opc-button { - padding: 11px 0 0 0; + padding: 2px 0 0 0; } #order-opc .button-medium { background-color: #1292FF; @@ -641,3 +672,29 @@ content: "";} #order-opc .fancybox-skin .fancybox-close { background-image: url(../img/icon/icon-close.svg);} + +.btn-edit-guest-info { + padding: 0px 50px; + font-size: 17px; + line-height: 23px; + border-radius: 2px; + background-color: #D9D9D9; + border: 1px solid #D9D9D9; + margin-right: 10px; } + +.btn-edit-guest-info span { + display: block; + font-size: 14px; + padding: 11px; + font-weight: 600; + text-transform: uppercase; + text-align: center; } + +.transform-to-customer-block { + margin-top: 25px; } + +.transform-to-customer-block .text-secondary { + font-size: 14px; + line-height: 19px; + color: #333; + margin-bottom: 15px; } diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index 728a14494..5fa1f80be 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -63,7 +63,6 @@ $(document).ready(function() $('.is_customer_param').show(); $('#opc_account_form').slideDown('slow'); $('#is_new_customer').val('1'); - $('#opc_account_choice, #opc_invoice_address').hide(); if (typeof bindUniform !=='undefined') bindUniform(); }); @@ -72,7 +71,6 @@ $(document).ready(function() $('.is_customer_param').hide(); $('#opc_account_form').slideDown('slow'); $('#is_new_customer').val('0'); - $('#opc_account_choice, #opc_invoice_address').hide(); $('#new_account_title').html(txtInstantCheckout); $('#submitAccount').attr({id : 'submitGuestAccount', name : 'submitGuestAccount'}); if (typeof bindUniform !=='undefined') @@ -98,11 +96,19 @@ $(document).ready(function() // LOGIN FORM $(document).on('click', '#openLoginFormBlock', function(e){ e.preventDefault(); - $('#openNewAccountBlock').show(); - $('.already_registered_block').hide(); - $('#login_form_content').slideDown('slow'); - $('#new_account_form').slideUp('slow'); + $('#openNewAccountBlock').show(200); + $('.already_registered_block').hide(200); + $('#login_form_content').slideDown(200); + $('#new_account_form').slideUp(200); }); + + $(document).on('click', '#idAccountChoice', function(e) { + e.preventDefault(); + $('#login_form_content').slideUp(200); + $('#new_account_form').slideDown(200); + $('.already_registered_block').show(200); + }); + // LOGIN FORM SENDING $(document).on('click', '#SubmitLogin', function(e) { @@ -162,9 +168,10 @@ $(document).ready(function() e.preventDefault(); $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow') - var callingFile = ''; + var callingFile = ''; var advApiParam = ''; var params = ''; + var isTransforming = false; if ($(this).attr('data-adv-api')) { advApiParam = '&isAdvApi=1'; @@ -177,8 +184,12 @@ $(document).ready(function() } else { - callingFile = orderOpcUrl; - params = 'method=editCustomer&'; + if ($('#opc_account_form #passwd').val().length > 0) { + params = 'method=transformGuestAccount&'; + isTransforming = true; + } else { + params = 'method=editCustomer&'; + } } $('#opc_account_form input:visible, #opc_account_form input[type=hidden]').each(function() { @@ -199,8 +210,6 @@ $(document).ready(function() $('#opc_account_form select:visible').each(function() { params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&'; }); - params += 'customer_lastname='+encodeURIComponent($('#customer_lastname').val())+'&'; - params += 'customer_firstname='+encodeURIComponent($('#customer_firstname').val())+'&'; params += 'alias='+encodeURIComponent($('#alias').val())+'&'; params += 'other='+encodeURIComponent($('#other').val())+'&'; params += 'is_new_customer='+encodeURIComponent($('#is_new_customer').val())+'&'; @@ -214,7 +223,7 @@ $(document).ready(function() async: false, cache: false, dataType : "json", - data: 'ajax=true&'+params+'&token=' + static_token , + data: 'ajax=true&'+params+'&token=' + static_token, success: function(jsonData) { if (jsonData.hasError) @@ -241,6 +250,10 @@ $(document).ready(function() $('#opc_account_errors').slideUp('slow', function(){ $(this).html(''); }); + + if (isTransforming) { + location.reload(); + } } isGuest = parseInt($('#is_new_customer').val()) == 1 ? 0 : 1; @@ -256,32 +269,13 @@ $(document).ready(function() static_token = jsonData.token; // It's not a new customer - if ($('#opc_id_customer').val() !== '0') - if (!saveAddress('delivery')) - return false; - - // update id_customer - $('#opc_id_customer').val(jsonData.id_customer); - - if ($('#invoice_address:checked').length !== 0) - { - if (!saveAddress('invoice')) - return false; + if (PS_CUSTOMER_ADDRESS_CREATION && $('#opc_id_customer').val() !== '0') { + saveAddress('delivery', function() { + location.reload(); + }); } - // update id_customer - $('#opc_id_customer').val(jsonData.id_customer); - - // force to refresh carrier list - if (isGuest) - { - isLogged = 1; - $('#opc_account_saved').fadeIn('slow'); - $('#submitAccount').hide(); - updateAddressSelection(advApiParam); - } - else - updateNewAccountToAddressBlock(advApiParam); + location.reload(); } //$('#guest-info-block, #opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow'); }, @@ -831,7 +825,7 @@ function confirmFreeOrder() }); } -function saveAddress(type) +function saveAddress(type, callback) { if (type !== 'delivery' && type !== 'invoice') return false; @@ -868,8 +862,6 @@ function saveAddress(type) // Clean the last & params = params.substr(0, params.length-1); - var result = false; - $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, @@ -899,14 +891,16 @@ function saveAddress(type) }); }); $('#guest-info-block, #opc_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeOut('slow'); - result = false; } else { // update addresses id $('input#opc_id_address_delivery').val(jsonData.id_address_delivery); $('input#opc_id_address_invoice').val(jsonData.id_address_invoice); - result = true; + + if (typeof callback === 'function') { + callback(); + } } }, error: function(XMLHttpRequest, textStatus, errorThrown) { @@ -930,8 +924,6 @@ function saveAddress(type) $('#guest-info-block, #opc_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeOut('slow'); } }); - - return result; } function updateNewAccountToAddressBlock(is_adv_api) @@ -1200,3 +1192,9 @@ function multishippingMode(it) bindUniform(); } } + +$(document).on('click', '.btn-edit-guest-info', function(e) { + e.preventDefault(); + $('#collapse-guest-info .card-body:nth-child(1)').hide(); + $('#collapse-guest-info .card-body:nth-child(2)').toggleClass('hidden'); +}); diff --git a/themes/hotel-reservation-theme/order-opc-edit-guest-info.tpl b/themes/hotel-reservation-theme/order-opc-edit-guest-info.tpl new file mode 100644 index 000000000..ad1aacaf9 --- /dev/null +++ b/themes/hotel-reservation-theme/order-opc-edit-guest-info.tpl @@ -0,0 +1,323 @@ +{** +* 2010-2022 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through LICENSE.txt file inside our module +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to CustomizationPolicy.txt file inside our module for more information. +* +* @author Webkul IN +* @copyright 2010-2022 Webkul IN +* @license LICENSE.txt +*} + +