/** * We offer the best and most useful modules PrestaShop and modifications for your online store. * * We are experts and professionals in PrestaShop * * @author PresTeamShop.com * @copyright 2011-2020 PresTeamShop * @license see file: LICENSE.txt * @category PrestaShop * @category Module */ $(function(){ if(!AppOPC.initialized) { AppOPC.init(); } OPC_External_Validation.init(); OPC_Compatibilities.init(); function toggleIcon(e) { $(e.target) .parent() .prev('.card-header') .find(".more-less") .toggleClass('fa-pts-angle-down fa-pts-angle-up'); } $('#panel_addresses_customer').on('hidden.bs.collapse', toggleIcon); $('#panel_addresses_customer').on('shown.bs.collapse', toggleIcon); //$('#checkbox_create_account_guest').trigger('click'); }); var AppOPC = { $opc: false, $opc_step_one: false, $opc_step_two: false, $opc_step_three: false, $opc_step_review: false, initialized: false, load_offer: true, is_valid_opc: false, is_valid_form_login: false, is_valid_form_customer: false, is_valid_form_address_delivery: false, is_valid_form_address_invoice: false, jqOPC: typeof $jqOPC === typeof undefined ? $ : $jqOPC, m4gpdr: false, init: function(){ $(document).on('click', 'button#btn-copy_invoice_address_to_delivery', AppOPC.copyInvoiceAddressToDelivery); prestashop.on('updatedDeliveryForm', function(event) { $('.delivery-option.selected .carrier-extra-content').show() }); AppOPC.initialized = true; AppOPC.$opc = $('#onepagecheckoutps'); AppOPC.$opc_step_one = $('#onepagecheckoutps div#onepagecheckoutps_step_one'); AppOPC.$opc_step_two = $('#onepagecheckoutps div#onepagecheckoutps_step_two'); AppOPC.$opc_step_three = $('#onepagecheckoutps div#onepagecheckoutps_step_three'); AppOPC.$opc_step_review = $('#onepagecheckoutps div#onepagecheckoutps_step_review'); if (typeof OnePageCheckoutPS !== typeof undefined) { if (typeof jeoquery !== typeof undefined) { jeoquery.defaultCountryCode = OnePageCheckoutPS.iso_code_country_delivery_default; jeoquery.defaultLanguage = prestashop.language.iso_code; jeoquery.defaultData.lang = prestashop.language.iso_code; } //Se anade funcionalidad para eliminar espacios vacios de principio y fin de la cadena AppOPC.$opc_step_one.find('input:text, input[type="email"]').on('blur', function(e) { var value = $(e.currentTarget).val(); var new_value = value.trim(); $(e.currentTarget).val(new_value); }); //launch validate fields if (typeof $.formUtils !== typeof undefined && typeof $.validate !== typeof undefined){ $.formUtils.loadModules('prestashop.js, security.js, brazil.js', OnePageCheckoutPS.ONEPAGECHECKOUTPS_DIR + 'views/js/lib/form-validator/'); $.validate({ form: 'div#onepagecheckoutps #form_login, div#onepagecheckoutps #form_customer, div#onepagecheckoutps #form_address_delivery, div#onepagecheckoutps #form_address_invoice', validateHiddenInputs: true, language : messageValidate, onError: function ($form) { if ($form.attr('id') == 'form_login') { AppOPC.is_valid_form_login = false; } else if ($form.attr('id') == 'form_customer') { AppOPC.is_valid_form_customer = false; } else if ($form.attr('id') == 'form_address_delivery') { AppOPC.is_valid_form_address_delivery = false; } else if ($form.attr('id') == 'form_address_invoice') { AppOPC.is_valid_form_address_invoice = false; } }, onSuccess: function ($form) { if ($form.attr('id') == 'form_login') { AppOPC.is_valid_form_login = true; } else if ($form.attr('id') == 'form_customer') { AppOPC.is_valid_form_customer = true; } else if ($form.attr('id') == 'form_address_delivery') { AppOPC.is_valid_form_address_delivery = true; } else if ($form.attr('id') == 'form_address_invoice') { AppOPC.is_valid_form_address_invoice = true; } return false; } }); } $(OnePageCheckoutPS.CONFIGS.OPC_ID_CONTENT_PAGE) .css({ margin: 0 }) .addClass('opc_center_column') .removeClass('col-sm-push-3'); Address.launch(); Fronted.launch(); if (!register_customer) { $(OnePageCheckoutPS.CONFIGS.OPC_ID_CONTENT_PAGE).css({width: '100%'}); Carrier.launch(); PaymentOPC.launch(); Review.launch(); } if (typeof $.fn.datepicker !== typeof undefined) { AppOPC.$opc_step_one.find('input[data-validation*="isBirthDate"], input[data-validation*="isDate"]').datepicker({ dateFormat: OnePageCheckoutPS.date_format_language, changeMonth: true, changeYear: true, showButtonPanel: true, yearRange: '-100:+0', isRTL: parseInt(prestashop.language.is_rtl) }); } } }, copyInvoiceAddressToDelivery: function() { var $invoice_fields = $('#panel_address_invoice #form_address_invoice').find('.invoice'); var $form_delivery = $('#panel_address_delivery #form_address_delivery'); $.each($invoice_fields, function(i, elem) { var field_name = $(elem).data('field-name'); var value = $(elem).val(); if (field_name != 'id' && $form_delivery.find('[data-field-name="'+field_name+'"]').length > 0) { $form_delivery.find('[data-field-name="'+field_name+'"]').val(value); } }); } } var Fronted = { launch: function(){ $('div#onepagecheckoutps #opc_show_login').click(function(){ Fronted.showModal({type:'normal', title:$('#opc_login').attr('title'), title_icon:'fa-pts-user', content:$('#opc_login')}); }); AppOPC.$opc.find('#opc_login').on('click', '#btn_login', Fronted.loginCustomer); AppOPC.$opc.on('click', '#btn_continue_shopping', function(){ var link = $('div#onepagecheckoutps #btn_continue_shopping').data('link'); if (typeof link === typeof undefined) { link = prestashop.urls.pages.index; } window.location.href = link; }); AppOPC.$opc.on('click', '#btn-logout', function(e){ $.totalStorageOPC.deleteItem('create_invoice_address_'+OnePageCheckoutPS.id_shop); window.location.href = $(e.currentTarget).data('link'); }); AppOPC.$opc.find('#opc_login #txt_login_password').keypress(function(e){ var code = (e.keyCode ? e.keyCode : e.which); if (code == 13) Fronted.loginCustomer(); }); //evita el guest checkout cuando solo quiere registrarse o iniciar sesion "rc=1". if (AppOPC.$opc_step_review.length <= 0) { var $create_account_guest = AppOPC.$opc_step_one.find('#field_customer_checkbox_create_account_guest'); if ($create_account_guest.length > 0) { $create_account_guest.hide(); if (!$create_account_guest.find('#checkbox_create_account_guest').is(':checked')) { $create_account_guest.find('#checkbox_create_account_guest').trigger('click'); } } } //evita copiar, pegar y cortar en los campos de confirmacion. /*AppOPC.$opc_step_one.find('#customer_conf_email, #customer_conf_passwd').bind("cut copy paste", function(e) { e.preventDefault(); });*/ }, openCMS: function(params){ var param = $.extend({}, { id_cms: '' }, params); var data = { url_call: prestashop.urls.pages.order + '?rand=' + new Date().getTime(), is_ajax: true, dataType: 'html', action: 'loadCMS', id_cms: param.id_cms }; var _json = { data: data, beforeSend: function() { Fronted.loadingBig(true); }, success: function(html) { if (!$.isEmpty(html)){ Fronted.showModal({name: 'cms_modal', content: html}); } }, complete: function(){ Fronted.loadingBig(false); } }; $.makeRequest(_json); }, loading: function(show, selector){ if (show) { Fronted.loadingBig(true); } }, loadingBig: function(show){ if (show && !AppOPC.$opc.find('> .row').hasClass('.opc_overlay')) { AppOPC.$opc.find('> .row').addClass('opc_overlay'); if ($(window).width() >= 1024) { AppOPC.$opc.find('.loading_big').show(); } else { $('div#opc_loading').remove(); $('body').append('
'+OnePageCheckoutPS.Msg.processing_purchase+'
'); } } else { AppOPC.$opc.find('> .row').removeClass('opc_overlay'); if ($(window).width() >= 1024) { AppOPC.$opc.find('.loading_big').hide(); } else { $('div#opc_loading').remove(); } } }, showModal: function(params){ var param = $.extend({}, { name: 'opc_modal', type: 'normal', title: '', title_icon: '', message: '', content: '', close: true, button_ok: false, button_close: false, size: '', callback: '', callback_ok: '', callback_close: '' }, params); $('#'+param.name).remove(); //var windows_width = $(window).width(); var parent_content = ''; if (typeof param.content === 'object'){ parent_content = param.content.parent(); } var $modal = $('
').attr({id:param.name, 'class':'modal fade', role:'dialog'}); var $modal_dialog = $('
').attr({'class':'modal-dialog ' + param.size}); var $modal_header = $('
').attr({'class':'modal-header'}); var $modal_content = $('
').attr({'class':'modal-content'}); var $modal_body = $('
').attr({'class':'modal-body'}); var $modal_footer = $('
').attr({'class':'modal-footer'}); var $modal_button_close = $('