/** * NOTICE OF LICENSE * * This source file is subject to a commercial license from Common-Services Co., Ltd. * Use, copy, modification or distribution of this source file without written * license agreement from the SARL SMC is strictly forbidden. * In order to obtain a license, please contact us: contact@common-services.com * ........................................................................... * INFORMATION SUR LA LICENCE D'UTILISATION * * L'utilisation de ce fichier source est soumise a une licence commerciale * concedee par la societe Common-Services Co., Ltd. * Toute utilisation, reproduction, modification ou distribution du present * fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est * expressement interdite. * Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com * ........................................................................... * * @package Colissimo Flexibilite * @author Alexandre D. * @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand * @license Commercial license * Support by mail : support.soflexibilite@common-services.com */ $(document).ready(function () { window.console && console.log('Colissimo Flexibilite'); /* PrestaShop functions compatibility */ if (typeof(in_array) === 'undefined') var in_array = function (b, a) { for (var c in a) if (a[c] + "" === b + "") return !0; return !1; }; /* CACHED SELECTOR */ var selector_submit_account = $('#SubmitLogin, #submitAccount, #submitGuestAccount'); var selector_lookup = $('.lookup'); var selector_supper_selector = $('#super-selector'); if (selector_submit_account.length) { selector_submit_account.click(function () { $(document).ajaxStop(function () { $(document).unbind('ajaxStop'); setTimeout(function () { var selector_address_firstname = $('.address_firstname'); var selector_address_postcode = $('li.address_postcode'); if (selector_address_firstname.first().text()) { $('#sl-0-firstname').val(selector_address_firstname.first().text().split(' ')[0]); $('#sl-0-lastname').val(selector_address_firstname.first().text().split(' ')[1]); $('#sl-0-address1').val($('li.address_address1:first').text()); $('#sl-0-address2').val($('li.address_address2:first').text()); $('#sl-0-postcode').val(selector_address_postcode.first().text().substring(0, 5)); $('#sl-0-city').val(selector_address_postcode.first().text().substring(6)); $('#sl-0-company').val($('li.address_company:first').text()); $('#sl-0-country').val($('li[class="address_country_name"]:first').text()); $('#sl-0-phone').val($('li[class="address_phone_mobile"]:first').text()); } else { $('#sl-0-firstname').val($('#firstname').val()); $('#sl-0-lastname').val($('#lastname').val()); $('#sl-0-address1').val($('#address1').val()); $('#sl-0-address2').val(''); $('#sl-0-postcode').val($('#postcode').val()); $('#sl-0-city').val($('#city').val()); $('#sl-0-company').val($('#company').val()); $('#sl-0-country').val($('#id_country').find('option:selected').text()); $('#sl-0-phone').val($('#phone_mobile').val()); $('#sl-0-mail').val($('#email').val()); } setTimeout(function () { startSoFlexibiliteEngine(); }, 800); }, 800); }); }); } else { setTimeout(function () { startSoFlexibiliteEngine(); }, 800); } function startSoFlexibiliteEngine() { /* Check if Google Map is Loaded on the page */ try { new google.maps.DirectionsService(); } catch (e) { alert(e + '\n\nGoogle n\'est pas chargé sur la page, la livraison en Colissimo vers un bureau de poste ou relais PickUp ne sera pas possible.'); } /* if ENTER is pressed in input address search => click on search button. */ selector_lookup.keypress(function (e) { if (e.keyCode === 13) { e.preventDefault(); $('#soflex-search').click(); } }); /* If click outside of #so_box_hors, quit the overlay or click on boxlcose (x) */ $('#soflexibilite_overlay, a#boxclose').click(function () { $('#soflexibilite_overlay').fadeOut('fast', function () { $('#so_box_hors').fadeOut('slow'); setTimeout(resetOverlay, 300); }); }); /* Hooking to a target div in the theme. Center Column is present in the PS default theme. */ var target_action_div = null; if ($('#center_column').length) target_action_div = $('#center_column'); else if ($('div.column.full:first').length) target_action_div = $('div.column.full:first'); else if ($('#produits').length) target_action_div = $('#produits'); else if ($('#colFull').length) target_action_div = $('#colFull'); else if ($('#carrier_area').length) target_action_div = $('#carrier_area'); else if ($('#content').length) target_action_div = $('#content'); else if ($('#order').length) target_action_div = $('#order'); else { window.console && console.log('Missing `target_action_div`, script stop.'); return (false); } /* Carrier selector */ var carrier_selector = $('input:radio[name="id_carrier"]').length ? 'input:radio[name="id_carrier"]' : ( $('input.delivery_option_radio').length ? 'input.delivery_option_radio' : 'input:radio[name^="delivery_option["]'); /* PS16 - Select carrier when click on carrier image */ if (parseInt($.fn.jquery.split('.').join('')) > 172) target_action_div.delegate('.delivery_option_logo', 'click', function () { $(this).parent().find(carrier_selector).attr('checked', true).click().parent().addClass('checked'); SoFlexibilite.updateCarrierSelectionAndGift(); }); var dom_id = $('input#soflexibilite_dom_id').val(); var dos_id = $('input#soflexibilite_dos_id').val(); var rdv_id = $('input#soflexibilite_rdv_id').val(); var bpr_id = $('input#soflexibilite_bpr_id').val(); var a2p_id = $('input#soflexibilite_a2p_id').val(); var cit_id = $('input#soflexibilite_cit_id').val(); /* Check if at least one So Colissimo Liberte carrier is available */ var pass = false; $(carrier_selector).each(function () { switch ($(this).val().split(',').join('')) { // Case : standard case dom_id : case dos_id : case rdv_id : case bpr_id : case a2p_id : case cit_id : // Case : envoi differe case dom_id + dom_id: case dos_id + dos_id: case rdv_id + rdv_id: case bpr_id + bpr_id: case a2p_id + a2p_id: case cit_id + cit_id: pass = true; break; } // Case : 2 products with 2 different carriers if ($(this).val().search(dom_id) > -1 || $(this).val().search(dos_id) > -1 || $(this).val().search(rdv_id) > -1 || $(this).val().search(bpr_id) > -1 || $(this).val().search(a2p_id) > -1 || $(this).val().search(cit_id) > -1) pass = true; }); if (!pass) { window.console && console.log('No So Colissimo Flexibilite carriers, script stop.'); return false; } /* Retrieving carriers ID */ var sf_carriers_id = []; $('[id^="soflexibilite_"][id$="_id"]').not('#soflexibilite_address_id, #soflexibilite_cart_id').each(function () { sf_carriers_id.push($(this).val()); }); // If no SF Carrier => STOP if (!sf_carriers_id.length) return false; /* Check if processCarrier or opc_payment_methods is present in theme in order to check parameters before payment. */ // if (!$('#opc_payment_methods, input[name="processCarrier"], button[name="processCarrier"], button[name="confirmDeliveryOption"]').length) { // alert($('#error-target-payment').val()); // return; // } /* Variables */ var ps17x = parseInt($('#ps17x').val()); var ps16x = parseInt($('#ps16x').val()); var ps15x = parseInt($('#ps15x').val()); var ps14x = parseInt($('#ps14x').val()); var currency_sign = typeof currencySign !== 'undefined' ? currencySign : ( typeof currency !== 'undefined' ? currency.sign : prestashop.currency.sign ); var sf_customer_address = $('#sl-0-address1').val() + ', ' + $('#sl-0-postcode').val() + ' ' + $('#sl-0-city').val() + ', ' + $('#sl-0-country-name').val(); sf_customer_address = sf_customer_address.split(/France|FRANCE|france/).length > 1 ? sf_customer_address.split(/France|FRANCE|france/)[0] + 'France' : sf_customer_address; selector_lookup.val(sf_customer_address); var soflex_available_countries = $('#soflexibilite_available_countries').val().split('|'); var soflex_image_url = $('#soflex_image_url').val(); var sf_delivery_mode_is_selected = false; var sf_customer_lat = null; var sf_customer_lng = null; var sf_customer_mail = $('#sl-0-mail').val(); var sf_customer_phone = $('#sl-0-phone').val(); var sf_country_selected = ''; var sf_latlng = null; var sf_map_zoom = 14; var sf_map_options = null; var sf_map = null; var sf_customer_house = null; var sf_markers = []; var sf_info_windows = []; var sf_bounds = null; var sf_direction_service = new google.maps.DirectionsService(); var sf_directions_display = new google.maps.DirectionsRenderer({suppressMarkers: true}); var sf_panorama = null; var search_address_parameters = []; var sf_icon_home = new google.maps.MarkerImage( soflex_image_url + 'home.png', null, null, null, new google.maps.Size(32, 32) ); var sf_icon_relay = new google.maps.MarkerImage( soflex_image_url + 'picto.png', null, null, null, new google.maps.Size(32, 32) ); var sf_center_control_div = null; var sf_center_control = null; var sf_relay_control_div = null; var sf_relay_control = null; var sf_id_cart = $('#soflexibilite_cart_id').val(); $('#so_box_hors').find('a.boxclose').css('backgroundImage', 'url(' + soflex_image_url + 'close.png)'); selector_supper_selector.css('backgroundImage', 'url(' + soflex_image_url + 'picto.png)').css('background-repeat', 'no-repeat').css('background-position', '2% center'); $(carrier_selector).attr('checked', false); /* Overlay */ target_action_div.delegate(carrier_selector, 'click', function () { sf_delivery_mode_is_selected = false; var selected_carrier = $(this).val().split(',')[0]; if (!in_array(selected_carrier, sf_carriers_id)) { $('#soflexibilite_description_address').remove(); return (true); } if (in_array(selected_carrier, [bpr_id, a2p_id])) { $('[id^="PR"]').hide(); if (selected_carrier == bpr_id) { $('[id^="PR"].BPR, [id^="PR"].BDP, [id^="PR"].CDI, [id^="PR"].ACP').show(); selector_supper_selector.find('option[value="choixPoste"]').attr('selected', true); refreshSelect(selector_supper_selector); } else if (selected_carrier == a2p_id) { $('[id^="PR"].A2P, [id^="PR"].CMT, [id^="PR"].PCS').show(); selector_supper_selector.find('option[value="choixCom"]').attr('selected', true); refreshSelect(selector_supper_selector); } $('#soflexibilite_overlay').fadeIn('fast', function () { $('#so_box_hors').fadeIn(1000); if (typeof (sf_map) !== 'undefined' && sf_map !== null) { google.maps.event.trigger(sf_map, 'resize'); sf_map.fitBounds(sf_bounds); } }); } else showDeliverySumUpHome(); }); // Address change target_action_div.delegate('#id_address_delivery', 'change', function () { $('.delivery_option').remove(); $('#opc-refresh-carrier').clone().attr('id', 'opc-refresh-carrier-copy').insertAfter('.delivery_options').show(); target_action_div.ajaxComplete(function () { $(carrier_selector).attr('checked', false).parent().removeClass('checked'); $('#soflexibilite_description_address').remove(); }); target_action_div.ajaxStop(function () { target_action_div.unbind('ajaxComplete'); target_action_div.unbind('ajaxStop'); $(carrier_selector).attr('checked', false).parent().removeClass('checked'); setTimeout(function () { resetDeliveryInfoFromAddressBloc(); setTooltips(); $('#soflex-search').click(); }, 500); }); }); /* Google Map */ try { var geocoder = new google.maps.Geocoder(); } catch (e) { window.console && console.log('Erreur GeoCODER', e); alert($('#geocoder_failed').val()); } function geocodeLocation() { geocoder.geocode({'address': sf_customer_address, 'region': 'FR'}, function (results, status) { if (window.console) { console.log('Address : ' + sf_customer_address || 'N/A'); if (results[0]) console.log('Google Map Api value : ' + results[0].geometry.location_type); } if (status === google.maps.GeocoderStatus.OK) { sf_customer_lat = parseFloat(results[0].geometry.location.lat()); sf_customer_lng = parseFloat(results[0].geometry.location.lng()); } else if (window.console) window.console && console.log('google.maps.GeocoderStatus != OK', status, results); $.ajax({ type: 'POST', url: $('#soflexibilite_point_list_url').val(), dataType: 'json', data: { adresseRecherche: $('#sl-0-address1').val(), address: $('#sl-0-address1').val(), postcode: $('#sl-0-postcode').val(), city: $('#sl-0-city').val(), country: $('#sl-0-country').val() }, success: function (data) { window.console && console.log(data); if (data.status === true) { sf_bounds = new google.maps.LatLngBounds(); sf_latlng = new google.maps.LatLng(sf_customer_lat, sf_customer_lng); sf_map_options = { zoom: sf_map_zoom, center: sf_latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, styles: (typeof(sf_map_style) === 'object') ? sf_map_style : null }; sf_map = new google.maps.Map(document.getElementById('gmap'), sf_map_options); sf_center_control_div = document.createElement('div'); sf_center_control = new setControlCenter(sf_center_control_div); sf_center_control_div.index = 1; sf_map.controls[google.maps.ControlPosition.TOP_RIGHT].push(sf_center_control_div); if ($('#soflexibilite_only_map').val() == '0') { sf_relay_control_div = document.createElement('div'); sf_relay_control = new setControlRelay(sf_relay_control_div); sf_relay_control_div.index = 1; sf_map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(sf_relay_control_div); } sf_customer_house = new google.maps.Marker({ map: sf_map, position: new google.maps.LatLng(sf_customer_lat, sf_customer_lng), icon: sf_icon_home }); sf_bounds.extend(sf_customer_house.position); fillPR(data.points, data.horaires, data.fermetures); } }, error: function (er) { if (window.console) console.log('Erreur geocoder.geocode()', er); } }); }); } geocodeLocation(); selector_supper_selector.change(function () { var type_de_point = selector_supper_selector.find('option:selected').val(); $('#information-pr').hide(); $('#points').show(); sf_directions_display.setMap(null); $('div[id^="PR"]').hide(); if (type_de_point == 'choixPoste') $('div[id^="PR"].BPR, div[id^="PR"].CDI, div[id^="PR"].ACP, div[id^="PR"].BDP').show(); else $('div[id^="PR"].A2P, div[id^="PR"].CMT, div[id^="PR"].PCS').show(); $('#so_constraint').is(':checked') && setConstraint(); }); $('#gmap').delegate('.infoButton', 'click', function () { var rel_point = $(this).parent().find('.so-infoWindow').attr('rel'); var prez = '' + $('[id="PR' + rel_point + '"]').find('.libelle').html() + '
' + $('[id="PR' + rel_point + '"]').find('.address1').html() + '
' + $('[id="PR' + rel_point + '"]').find('.code_postal').html() + ' ' + $('[id="PR' + rel_point + '"]').find('.commune').html(); $('#information-pr').attr('rel', rel_point); $('#points').hide(); $('#information-pr').find('.prez').html(prez); $('#horaire').html('').append($('[id="PR' + rel_point + '"]').find('.horairesPR').html()); $('#fermeture').html('').append($('[id="PR' + rel_point + '"]').find('.fermeturesPR').html()); $('#information-pr').show(); checkStreetViewAvailability( parseFloat($('[id="PR' + rel_point + '"] .pr-lat').val().split(',').join('.')), parseFloat($('[id="PR' + rel_point + '"] .pr-lng').val().split(',').join('.')) ); }); $('#gmap').delegate('.sf_select', 'click', function () { var id_point = $(this).parent().find('.so-infoWindow').attr('rel'); id_point = $('[id="PR' + id_point + '"] .pr-id').val(); selectPoint(id_point); showDeliverySumUpRelay(id_point); }); function resetDeliveryInfoFromAddressBloc() { $(carrier_selector).attr('checked', false).parent().removeClass('checked'); if ($('.address_firstname:first').text()) { $('#sl-0-firstname').val($('.address_firstname:first').text().split(' ')[0]); $('#sl-0-lastname').val($('.address_firstname:first').text().split(' ')[1]); $('#sl-0-address1').val($('li.address_address1:first').text()); $('#sl-0-address2').val($('li.address_address2:first').text()); $('#sl-0-postcode').val($('li.address_postcode:first').text().substring(0, 5)); $('#sl-0-city').val($('li.address_postcode:first').text().substring(6)); $('#sl-0-company').val($('li.address_company:first').text()); $('#sl-0-country-name').val($('li[class="address_country_name"]:first').text()); $('#sl-0-phone').val($('li[class="address_phone_mobile"]:first').text()); sf_customer_phone = $('li[class="address_phone_mobile"]:first').text(); sf_customer_address = $('li.address_address1:first').text() + ' ' + $('li.address_postcode:first').text(); } else { $('#sl-0-firstname').val($('#firstname').val()); $('#sl-0-lastname').val($('#lastname').val()); $('#sl-0-address1').val($('#address1').val()); $('#sl-0-address2').val(''); $('#sl-0-postcode').val($('#postcode').val()); $('#sl-0-city').val($('#city').val()); $('#sl-0-company').val($('#company').val()); $('#sl-0-country-name').val($('#id_country option:selected').text()); $('#sl-0-phone').val($('#phone_mobile').val()); $('#sl-0-mail').val($('#email').val()); sf_customer_phone = $('#phone_mobile').val(); sf_customer_mail = $('#email').val(); sf_customer_address = $('#address1').val() + ', ' + $('#postcode').val() + ' ' + $('#city').val(); } selector_lookup.val(sf_customer_address); } function setTooltips() { $('a[id^="tooltip"]').remove(); if (parseInt($.fn.jquery.split('.').join('')) < 172) return false; $(carrier_selector).each(function () { var id_carrier = $(this).val().split(',')[0]; var delivery_mode = null; if (!in_array(id_carrier, sf_carriers_id)) return true; switch (id_carrier) { case dom_id: delivery_mode = 'Dom'; break; case dos_id: delivery_mode = 'Dos'; break; case bpr_id: delivery_mode = 'Bpr'; break; case a2p_id: delivery_mode = 'A2p'; break; } $('.for' + delivery_mode).clone().appendTo($(this).closest('tr').find('.delivery_option_logo').next()).attr('id', 'tooltip' + delivery_mode).show().qtip({ content: { text: $('.for' + delivery_mode + ' span.sf_fr').html().trim() }, position: { my: 'bottom center', at: 'top center' }, style: { classes: 'qtip-light qtip-shadow', width: 500 }, hide: { fixed: true, delay: 300 } }).parent().find('strong').html( $('#tooltip' + delivery_mode).parent().find('strong').text().split(' - ').join(' - ') + '' ).css('color', '#FB4F14'); // Instead of .parent().find('strong')... // // var txt1 = $('#tooltip' + delivery_mode).parent().html().trim().split('Faites')[0]; // var txt2 = $('#tooltip' + delivery_mode).parent().html().trim().split('Faites')[1]; // // $('#tooltip' + delivery_mode).parent().html('' + txt1 + '' + ' Faites' + txt2); if ($('#tooltip' + delivery_mode).prev().text() === '') $('#tooltip' + delivery_mode).prev().remove(); }); } function setControlCenter(controlDiv) { // Set CSS for the control center border. var controlCenterMap = document.createElement('div'); controlCenterMap.style.backgroundColor = '#fff'; controlCenterMap.style.border = '2px solid #fff'; controlCenterMap.style.borderRadius = '3px'; controlCenterMap.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)'; controlCenterMap.style.cursor = 'pointer'; controlCenterMap.style.margin = '10px'; controlCenterMap.style.textAlign = 'center'; controlCenterMap.title = 'Recentrer la carte et les points de retrait'; controlDiv.appendChild(controlCenterMap); // Set CSS for the control center interior. var controlCenterText = document.createElement('div'); controlCenterText.style.color = 'rgb(0, 0, 0)'; controlCenterText.style.fontFamily = 'Roboto, Arial, sans-serif'; controlCenterText.style.fontSize = '11px'; controlCenterText.style.padding = '8px'; controlCenterText.innerHTML = 'Centrer la carte'; controlCenterMap.appendChild(controlCenterText); // Setup the click event listeners controlCenterMap.addEventListener('click', function () { sf_map.fitBounds(sf_bounds); }); } function setControlRelay(controlDiv) { // Set CSS for the control relay border. var controlRelay = document.createElement('div'); controlRelay.style.backgroundColor = '#fff'; controlRelay.style.border = '2px solid #fff'; controlRelay.style.borderRadius = '3px'; controlRelay.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)'; controlRelay.style.margin = '10px'; controlRelay.style.textAlign = 'center'; controlRelay.title = 'Cacher les points de retrait qui ne font pas partie du mode de livraison sélectionné'; controlRelay.id = 'so_control_relay'; controlDiv.appendChild(controlRelay); // Set CSS for the control relay interior. var controlRelayText = document.createElement('div'); controlRelayText.style.color = 'rgb(0, 0, 0)'; controlRelayText.style.fontFamily = 'Roboto, Arial, sans-serif'; controlRelayText.style.fontSize = '11px'; controlRelayText.style.padding = '8px'; controlRelayText.innerHTML = ' Filtrer les points de retrait'; controlRelay.appendChild(controlRelayText); // Setup the click event listeners controlRelay.addEventListener('click', function () { setConstraint(); }); } function fillPR(points, horaires, fermetures) { deleteMarkers(); $('div[id^=PR]').remove(); $('#so-no-points').hide(); var type_de_point = selector_supper_selector.find('option:selected').val(); $.each(points, function (p, point) { var point_div = $('#model-points').clone().appendTo('div#points').attr('id', 'PR' + p).attr('class', point.typeDePoint); var distance = null; var position = new google.maps.LatLng(point.coordGeolocalisationLatitude, point.coordGeolocalisationLongitude); if (point.distanceEnMetre < 1000) distance = '(env ' + point.distanceEnMetre + 'm)'; else distance = '(env ' + (point.distanceEnMetre / 1000).toFixed(2) + 'Km)'; // Fill divs point_div.children('span.libelle').html(point.nom); point_div.children('span.so_distance').html(distance); point_div.children('span.address1').html(point.adresse1); point_div.children('span.code_postal').html(point.codePostal); point_div.children('span.commune').html(point.localite); point_div.children('span.point-choose').find('img').attr('class', 'choosethePR PR' + p).click(function () { selectPoint(point.identifiant); showDeliverySumUpRelay(point.identifiant); }); if (point.accesPersonneMobiliteReduite) point_div.find('img.handicap').attr('src', soflex_image_url + 'picto-handicap.png'); var so_info = '
' + point.nom + '
' + '
' + point.adresse1 + '
'; if (fermetures[p] === 'disabled') so_info += '
' + point.codePostal + ' ' + point.localite + '
En Congés
'; else so_info += '
' + point.codePostal + ' ' + point.localite + '
'; point_div.find('div.prez').html(so_info); point_div.find('div.horairesPR').html(horaires[p]); if (fermetures[p] === 'disabled') { point_div.children('span.picto').html(''); point_div.css('opacity', '0.5').css('background', 'gainsboro').find('div.fermeturesPR').html(fermetures[p]); point_div.find('.point-choose').hide(); } else { point_div.children('span.picto').html(''); point_div.find('div.fermeturesPR').html(fermetures[p]); } point_div.children('input.pr-lat').attr('value', point.coordGeolocalisationLatitude); point_div.children('input.pr-lng').attr('value', point.coordGeolocalisationLongitude); point_div.children('input.pr-id').attr('value', point.identifiant); point_div.children('input.pr-indice').attr('value', point.indiceDeLocalisation); point_div.children('input.pr-country').attr('value', point.codePays); point_div.children('input.pr-country-name').attr('value', point.libellePays); point_div.children('input.pr-reseau').attr('value', point.reseau); point_div.hide(); // Markers sf_markers[p] = new google.maps.Marker({ map: sf_map, position: position, icon: sf_icon_relay }); sf_bounds.extend(sf_markers[p].position); google.maps.event.addListener(sf_markers[p], 'click', function () { closeSFInfoWindows(); sf_info_windows[p].open(sf_map, sf_markers[p]); if ($('#information-pr').is(':visible')) { $('.infoButton').click(); sf_directions_display.setMap(null); } }); // Info windows var kind = point.typeDePoint; var item = 'wc-' + kind + '-' + p; var content_string = '
' + $('div[id="PR' + p + '"]').find('div.prez').html() + '
'; if (point_div.find('.fermeturesPR').text() !== 'disabled') content_string += ($('#soflexibilite_only_map').val() !== '0' ? $('div[id="PR' + p + '"]').find('div.horairesPR').html().replace('
', '') + 'Fermeture : ' + $('div[id="PR' + p + '"]').find('div.fermeturesPR').text() + '
' : '') + ''; sf_info_windows[p] = new google.maps.InfoWindow({ content: content_string, maxWidth: 430 }); // Close when clic on map google.maps.event.addListener(sf_map, 'click', function () { sf_info_windows[p].close(); }); // Clic on the list then point on map $('div[id^="PR' + p + '"]').click(function () { closeSFInfoWindows(); sf_info_windows[p].open(sf_map, sf_markers[p]); // If clic on PR and screen mobile if (window.innerWidth <= 700) { selectPoint(point.identifiant); showDeliverySumUpRelay(point.identifiant); } }); }); if (type_de_point == 'choixPoste') $('div[id^="PR"].BPR, div[id^="PR"].CDI, div[id^="PR"].ACP, div[id^="PR"].BDP').show(); else $('div[id^="PR"].A2P, div[id^="PR"].CMT, div[id^="PR"].PCS').show(); if ($('#points div[id^="PR"]').length === 0) $('#so-no-points').show(); else $('#so-no-points').hide(); } function closeSFInfoWindows() { for (var x in sf_info_windows) if (typeof (sf_info_windows[x]) === 'object') sf_info_windows[x].close(); } function deleteMarkers() { for (var x in sf_markers) if (typeof (sf_markers[x]) === 'object') sf_markers[x].setMap(null); sf_markers = []; } function selectPoint(id) { if (window.console) console.log('selectPoint : ' + id); var idPoint = $('.pr-id[value="' + id + '"]').parent().attr('id'); var selector_prid = $('#' + idPoint); $.ajax({ type: 'POST', url: $('#saveDelivery_url').val(), dataType: 'json', data: { id: id, phone: $('#custPhone').val(), type: selector_prid.attr('class'), libelle: selector_prid.find('.libelle').text(), indice: selector_prid.find('.pr-indice').text(), adresse1: selector_prid.find('.address1').text(), code_postal: selector_prid.find('.code_postal').text(), commune: selector_prid.find('.commune').text(), country: selector_prid.find('.pr-country').val(), reseau: selector_prid.find('.pr-reseau').val(), id_cart: sf_id_cart }, success: function (data) { if (window.console) { console.log(data, 'SelectPoint Succeed'); } if (data.status) { $('#soflexibilite_carrier_hors_dom_chose').val('1'); sf_country_selected = selector_prid.find('.pr-country').val(); } else { alert('Une erreur est survenue lors de l\'enregistrement du point de retrait, contactez le webmaster de la boutique.'); } }, error: function (er) { alert('Une erreur est survenue lors de l\'enregistrement du point de retrait, contacter le webmaster de la boutique.'); if (window.console) { console.log('une erreur sur selectpoint ! ' + er.debug, er); } } }); } function showDeliverySumUpRelay(id_point) { if (window.console) console.log('ShowDetails()'); sf_delivery_mode_is_selected = true; $('#soflexibilite_description_address').remove(); SoFlexibilite.hideAllForOverlay(); var fullid = '#' + $('.pr-id[value="' + id_point + '"]').parent().attr('id'); $('#soflexibilite_overlay').fadeOut('slow').hide(); $('#so_box_hors').fadeOut('slow'); $('#adresseFinal').html(SoFlexibilite.buildFinalAddress({ company: $('#sl-0-company').val(), libelle: $(fullid).find('.libelle').html(), firstname: $('#sl-0-firstname').val(), lastname: $('#sl-0-lastname').val(), address1: $(fullid).find('.address1').html(), address2: $(fullid).find('.pr-indice').val(), postcode: $(fullid).find('.code_postal').html(), city: $(fullid).find('.commune').html(), country: $(fullid).find('.pr-country-name').val() })); $('#custMail').val(sf_customer_mail); $('#custPhone').val(sf_customer_phone); SoFlexibilite.selectRightCarrier($(fullid).attr('class')); var insert_after = $('.order-options').length ? '.order-options' : ( $('#extra_carrier').length ? '#extra_carrier' : '.hook_extracarrier' ); var saved_sumup = $('#soflexibilite_carrierList_template').clone().insertAfter($(insert_after)).attr('id', 'soflexibilite_description_address').show(); $(saved_sumup).find('#custPhone').attr('id', 'sf_phone'); $('#soflexibilite_speech').show(); $('#so-h3-recap-horsdom').show(); $('#so-h3-recap-dom').hide(); var offset_selector = ps17x ? '#picFinalColissimo' : '#so-h3-recap-horsdom'; $('html, body').animate({ scrollTop: $(offset_selector).offset().top - 200 }); if ($('#order-opc').length) { target_action_div.ajaxComplete(function () { $('#soflexibilite_description_address').remove(); $(saved_sumup).insertAfter($(insert_after)); }); target_action_div.ajaxStop(function () { target_action_div.unbind('ajaxStop'); target_action_div.unbind('ajaxComplete'); }); } if (ps17x) { $.ajax({ type: 'POST', url: $('#delivery-method').data('url-update'), data: $('#delivery-method').serialize(), success: function(resp) { typeof(resp) !== 'undefined' && typeof(resp.preview) !== 'undefined' && $('#checkout-cart-summary').replaceWith(resp.preview); } }) } resetOverlay(); } function showDeliverySumUpHome() { sf_delivery_mode_is_selected = true; $('#soflexibilite_description_address').remove(); $('#adresseFinal').html(SoFlexibilite.buildFinalAddress({ company: $('#sl-0-company').val(), libelle: null, firstname: $('#sl-0-firstname').val(), lastname: $('#sl-0-lastname').val(), address1: $('#sl-0-address1').val(), address2: $('#sl-0-address2').val(), postcode: $('#sl-0-postcode').val(), city: $('#sl-0-city').val(), country: $('#sl-0-country-name').val() })); sf_customer_mail = $('#sl-0-mail').val(); $('#custMail').val(sf_customer_mail); $('#custPhone').val(sf_customer_phone); var insert_after = $('.order-options').length ? '.order-options' : ( $('#extra_carrier').length ? '#extra_carrier' : '.hook_extracarrier' ); var saved_sumup = $('#soflexibilite_carrierList_template').clone().insertAfter($(insert_after)).attr('id', 'soflexibilite_description_address').show(); $(saved_sumup).find('#custPhone').attr('id', 'sf_phone'); $('#soflexibilite_speech').show(); $('#so-h3-recap-horsdom').hide(); $('#so-h3-recap-dom').show(); var offset_selector = ps17x ? '#picFinalColissimo' : '#soflexibilite_carrierList'; $('html, body').animate({ scrollTop: $(offset_selector).offset().top - 200 }); if ($('#order-opc').length) { target_action_div.ajaxComplete(function () { $('#soflexibilite_description_address').remove(); $(saved_sumup).insertAfter($(insert_after)); }); target_action_div.ajaxStop(function () { target_action_div.unbind('ajaxStop'); target_action_div.unbind('ajaxComplete'); }); } } function resetOverlay() { var pos = $('#PR0').position(); if (typeof (pos) !== 'undefined' && typeof (pos) !== null && typeof (pos.top) !== 'undefined' && pos.top !== null) $('#points').animate({scrollTop: pos.top}, 0); $('div#header').css('z-index', 10); $('#points').show(); $('#information-pr').hide(); $('#picStreetView').hide(); $('#header').css('z-index', 10); if (typeof (panorama) !== 'undefined' && panorama !== null) panorama.setVisible(null); if (typeof (infoWindow) !== 'undefined' && infoWindow !== null) for (var x in infoWindow) if (typeof (infoWindow[x]) === 'object') infoWindow[x].close(); } function codeLatLng(lat, lng, callback) { var latlng = new google.maps.LatLng(lat, lng); geocoder.geocode({'latLng': latlng, 'region': 'fr'}, function (res, stat) { if (stat === google.maps.GeocoderStatus.OK) { if (res[0]) { var elt = res[0].address_components; var i = null; for (i in elt) { if (elt[i].types[0] === 'postal_code' || elt[i].types[0] === 'postal_code_prefix') search_address_parameters['postcode'] = elt[i].long_name; else if (elt[i].types[0] === 'locality') search_address_parameters['city'] = elt[i].long_name; else if (elt[i].types[0] === 'route' || elt[i].types[0] === 'premise') search_address_parameters['address'] = elt[i].long_name; else if (elt[i].types[0] === 'country') { search_address_parameters['country'] = elt[i].short_name; search_address_parameters['country-name'] = elt[i].long_name; } } 'function' === typeof(callback) && callback(); } } else { window.console && console.log(res, stat); alert("Erreur de geolocalisation: " + stat); } }); } function fillMRPickupPoints(pickup_points) { var week_days = [ 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche' ]; $('div.sf_pickup').remove(); $.each(pickup_points, function (id_p, point) { var model_div = $('.sf_pickup_model').clone().appendTo('#sf_delivery_point').attr('class', 'sf_pickup').attr('rel', point.Num).show(); model_div.find('.lgadr1').text(point.LgAdr1); model_div.find('.distance').text(point.Distance >= 1000 ? (point.Distance / 1000) + 'Km' : point.Distance + 'm'); model_div.find('.lgadr3').text(point.LgAdr3); model_div.find('.lgadr4').text(point.LgAdr4); model_div.find('.CP').text(point.CP); model_div.find('.ville').text(point.Ville); model_div.find('.pays').text(point.Pays); model_div.find('.latitude').val(point.Latitude); model_div.find('.longitude').val(point.Longitude); // hours $.each(week_days, function (id_d, day) { model_div.find('table tbody').html( model_div.find('table tbody').html() + '' + '' + day + '' + '' + (point.Horaires[day][0] || '') + '' + '' + (point.Horaires[day][1] || '') + '' + '' ); }); sf_bounds.extend(new google.maps.LatLng(point.Latitude.split(',').join('.'), point.Longitude.split(',').join('.'))); }); } function setLocationGeoCode(lat, lng) { google.maps.event.trigger(sf_map, 'resize'); sf_map.fitBounds(sf_bounds); } function setConstraint() { var selected_mode = selector_supper_selector.find('option:selected').val(); if ($('#so_constraint').is(':checked')) { for (var x in sf_markers) if (typeof (sf_markers[x]) === 'object') sf_markers[x].setMap(sf_map); if (selected_mode == 'choixPoste') { for (var x in sf_markers) if (typeof (sf_markers[x]) === 'object' && $('[id="PR' + x + '"]').is('.A2P, .CMT, .PCS')) sf_markers[x].setMap(null); } else { for (var x in sf_markers) if (typeof (sf_markers[x]) === 'object' && $('[id="PR' + x + '"]').is('.BPR, .BDP, .ACP, .CDI')) sf_markers[x].setMap(null); } } else { for (var x in sf_markers) if (typeof (sf_markers[x]) === 'object') sf_markers[x].setMap(sf_map); } closeSFInfoWindows(); } $('#so_constraint').change(function () { setConstraint(); }); /* Check everything is well done before submitting everything. */ $(target_action_div).delegate('#opc_payment_methods, [name="processCarrier"]', 'mousedown click submit', function (ev) { var pass = false; if (!$(carrier_selector + ':checked').length && !$('.delivery_option span.checked').length) { ev.preventDefault(); alert('Merci de sélectionner un transporteur.'); return (false); } // On verifie quel transporteur est selectionne var result = $('input[id^="delivery_option_"]:checked').val().match('^([0-9]*)')[1]; // Ce n'est pas So Colissimo qui est selectionne on intervient pas if (!in_array(result, sf_carriers_id)) return (true); // So Colissimo est selectionne, on verifie si un point de retrait ou domicile/rdv est selectionne if (!sf_delivery_mode_is_selected) { ev.preventDefault(); alert($('#must-select').val()); return (false); } // Check contact infos var phone_mobile_fr = /^0[67](\d{2}){4}$/i; var phone_mobile_be = /^\+324\d{8,10}$/i; var phone_mobile_nl = /^(\+|00)31\d{9,10}$/i; var phone_mobile_lu = /^(\+|00)352\d{8,10}$/i; var phone_mobile_es = /^(\+|00)41\d{9,10}$/i; var phone_mobile_de = /^(\+|00)49\d{9,12}$/i; var phone_mobile_uk = /^(\+|00)44\d{9,10}$/i; var phone_format = ''; switch (sf_country_selected.toUpperCase()) { case 'FR': phone_format = '0661010203'; break; case 'BE': phone_format = '+324...'; break; case 'NL': phone_format = '+31...'; break; case 'LU': phone_format = '+352...'; break; case 'ES': phone_format = '+41...'; break; case 'DE': phone_format = '+49...'; break; case 'UK': phone_format = '+44...'; break; } var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/i; if (!email.test($('#custMail').val())) { ev.preventDefault(); alert('Renseignez votre email !'); return (false); } if (!$('#custPhone').val().length) { $('#sf_phone').change(); $('#custPhone').val($('#sf_phone').val()); } if (!$('#custPhone').val().length) { ev.preventDefault(); alert($('#error-mobile-mandatory').val() + '\n\nFormat : 0661010203'); return (false); } // if (sf_country_selected.toUpperCase() == 'FR' && !phone_mobile_fr.test($('#custPhone').val()) || // sf_country_selected.toUpperCase() == 'BE' && !phone_mobile_be.test($('#custPhone').val()) || // sf_country_selected.toUpperCase() == 'NL' && !phone_mobile_nl.test($('#custPhone').val()) || // sf_country_selected.toUpperCase() == 'LU' && !phone_mobile_lu.test($('#custPhone').val()) || // sf_country_selected.toUpperCase() == 'ES' && !phone_mobile_es.test($('#custPhone').val()) || // sf_country_selected.toUpperCase() == 'DE' && !phone_mobile_de.test($('#custPhone').val()) || // sf_country_selected.toUpperCase() == 'UK' && !phone_mobile_uk.test($('#custPhone').val())) { // // ev.preventDefault(); // alert($('#error-mobile-invalid').val() + '\n\nFormat : ' + phone_format); // return (false); // } return (true); }); $('#soflex-search').click(function () { $('#search-btn, #search-btn-pending, #soflex-search img').toggle(); var adresse_de_recherche = selector_lookup.val().toUpperCase(); adresse_de_recherche = adresse_de_recherche.split('FRANCE').length > 1 ? adresse_de_recherche.split('FRANCE')[0] + 'FRANCE' : adresse_de_recherche; var current_carrier = $(carrier_selector + ':checked').val() ? parseInt($(carrier_selector + ':checked').val().split(',')[0]) : 0; var warning_message = $('#soflexibilite_carrier_fee_changes_1').val() + '\n' + $('#soflexibilite_carrier_fee_changes_2').val() + '\n' + $('#soflexibilite_carrier_fee_changes_3').val(); window.console && window.console.log('Adresse de recherche : ' + adresse_de_recherche); geocoder.geocode({'address': adresse_de_recherche, 'region': 'fr'}, function (results, status) { if (status === google.maps.GeocoderStatus.OK) { sf_customer_lat = parseFloat(results[0].geometry.location.lat()); sf_customer_lng = parseFloat(results[0].geometry.location.lng()); codeLatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng(), function () { if (!in_array(search_address_parameters['country'], soflex_available_countries)) { $('#search-btn, #search-btn-pending, #soflex-search img').toggle() && alert($('#soflexibilite_country_disalbed').val()); return false; } else if (search_address_parameters['country'] !== $('#sl-0-country').val()) { warning_message = warning_message .replace('##relay_country##', search_address_parameters['country-name']) .replace('##current_country##', $('#sl-0-country-name').val()) .replace('##relay_price##', parseFloat( sf_carrier_fee_countries[current_carrier][search_address_parameters['country']] ).toFixed(2) + currency_sign || '??'); if (!confirm(warning_message)) { $('#search-btn, #search-btn-pending, #soflex-search img').toggle(); return false; } } $.ajax({ type: 'POST', url: $('#soflexibilite_point_list_url').val(), dataType: 'json', data: { adresseRecherche: adresse_de_recherche, address: search_address_parameters['address'], postcode: search_address_parameters['postcode'], city: search_address_parameters['city'], country: search_address_parameters['country'] }, success: function (data) { window.console && console.log(data); if (typeof (data) === 'undefined' || data === null || typeof (data.points) === 'undefined' || data.points === null || data.points.length === 0) $('#gmap').text('Une erreur est survenue.'); $('#search-btn, #search-btn-pending, #soflex-search img').toggle(); $('#points').scrollTop(0).show(); $('#picStreetView').hide(); $('#information-pr').hide(); $('#gmap *').length <= 5 && (sf_map = new google.maps.Map(document.getElementById('gmap'), sf_map_options)); if (data.status === true) { sf_bounds = new google.maps.LatLngBounds(); sf_bounds.extend(new google.maps.LatLng(sf_customer_lat, sf_customer_lng)); sf_customer_house && sf_customer_house.setMap(null); sf_customer_house = new google.maps.Marker({ map: sf_map, position: new google.maps.LatLng(sf_customer_lat, sf_customer_lng), icon: sf_icon_home }); if (!in_array(search_address_parameters['country'], ['FR', 'BE'])) { selector_supper_selector.find('option[value="choixCom"]').attr('selected', true); } else { selector_supper_selector.find('option[value="choixPoste"]').attr('selected', true); } fillPR(data.points, data.horaires, data.fermetures); setLocationGeoCode(sf_customer_lat, sf_customer_lng); setConstraint(); } else if (data.error) { $('div[id^=PR]').remove(); $('#gmap').html('
' + data.error + '
'); } }, error: function (e) { window.console && console.log('error recherche adresse', e); $('#search-btn, #search-btn-pending, #soflex-search img').toggle(); } }); }); } else { $('#search-btn, #search-btn-pending, #soflex-search img').toggle(); $('#gmap').html('

L\'adresse recherchée est incorrecte.

'); window.console && console.log('google.maps.GeocoderStatus != OK', results, status); } }); }); target_action_div.delegate('#sf_phone', 'keydown, blur', function () { if ($(this).val().length >= 6) { $.ajax({ type: 'POST', url: $('#saveInfoCommande_url').val(), dataType: 'json', data: { email: $('#custMail').val(), phone: $('#sf_phone').val(), infoDelivery: $('#infoCommande').val(), cart: sf_id_cart }, success: function (data) { if (data.status === true) { window.console && console.log('Informations saved !'); sf_customer_mail = $('#custMail').val(); sf_customer_phone = $('#sf_phone').val(); $('#custPhone').val($('#sf_phone').val()); } else window.console && console.log('Error', data); }, error: function (er) { window.console && console.log('Une erreur sur save information !', er); } }); } }); target_action_div.delegate('#sf_phone, #custMail, #infoCommande', 'change', function () { $.ajax({ type: 'POST', url: $('#saveInfoCommande_url').val(), dataType: 'json', data: { email: $('#custMail').val(), phone: $('#sf_phone').val(), infoDelivery: $('#infoCommande').val(), cart: sf_id_cart }, success: function (data) { if (data.status === true) { window.console && console.log('Informations saved !'); sf_customer_mail = $('#custMail').val(); sf_customer_phone = $('#sf_phone').val(); $('#custPhone').val($('#sf_phone').val()); } else window.console && console.log('Error', data); }, error: function (er) { window.console && console.log('Une erreur sur save information !', er); } }); }); $('#otherPR, #so-info-close').click(function () { $('#picStreetView').hide(); $('#points').show(); $('#information-pr').hide(); $('#driving').attr('checked', true); sf_directions_display.setMap(null); if (sf_panorama) sf_panorama.setVisible(false); }); $('#infoChoosePR').click(function () { var id_point = $('#information-pr').attr('rel'); id_point = $('[id="PR' + id_point + '"] .pr-id').val(); selectPoint(id_point); showDeliverySumUpRelay(id_point); }); $('#picDriving').click(function () { var id_point = $('#information-pr').attr('rel'); var request = { origin: sf_customer_house.position, destination: new google.maps.LatLng( $('#PR' + id_point + ' .pr-lat').val(), $('#PR' + id_point + ' .pr-lng').val() ), travelMode: google.maps.TravelMode.DRIVING }; closeSFInfoWindows(); sf_panorama && sf_panorama.setVisible(false); sf_directions_display.setMap(null); sf_direction_service.route(request, function (res, stat) { if (stat === google.maps.DirectionsStatus.OK) sf_directions_display.setDirections(res); }); sf_directions_display.setMap(sf_map); }); $('#picWalking').click(function () { var id_point = $('#information-pr').attr('rel'); var request = { origin: sf_customer_house.position, destination: new google.maps.LatLng( $('#PR' + id_point + ' .pr-lat').val(), $('#PR' + id_point + ' .pr-lng').val() ), travelMode: google.maps.TravelMode.WALKING }; closeSFInfoWindows(); sf_panorama && sf_panorama.setVisible(false); sf_directions_display.setMap(null); sf_direction_service.route(request, function (res, stat) { if (stat === google.maps.DirectionsStatus.OK) sf_directions_display.setDirections(res); }); sf_directions_display.setMap(sf_map); }); $('#picStreetView').click(function () { var id_point = $('#information-pr').attr('rel'); sf_panorama = sf_map.getStreetView(); sf_panorama.setPosition(new google.maps.LatLng( $('#PR' + id_point + ' .pr-lat').val(), $('#PR' + id_point + ' .pr-lng').val() )); sf_panorama.setVisible(true); }); function checkStreetViewAvailability(lat, lng) { $('#picStreetView').hide(); var streetViewLatLng = new google.maps.LatLng(lat, lng); geocoder.geocode({'latLng': streetViewLatLng, 'region': 'fr'}, function (results, status) { if (status === google.maps.GeocoderStatus.OK) { if (results[0].geometry.location_type === 'ROOFTOP') $('#picStreetView').show(); else $('#picStreetView').hide(); } else $('#picStreetView').hide(); }); } /* Set tooltips */ setTooltips(); if (in_array($(carrier_selector).val().split(',')[0], sf_carriers_id)) $(carrier_selector).attr('checked', false).parent().removeClass('checked'); // Theme setting if ($('#soflexibilite_only_map').val() !== '0') { $('#so_box_hors > p, #super-selector, #so_box_hors > div.float-left.keep-left, .infoButton').hide(); $('#gmap').css('width', '100%').css('height', '86%'); } // Address autocomplete try { var circle = new google.maps.Circle({ center: { lat: 48.8566, lng: 2.3522 }, radius: 1240000 }); var autocomplete = new google.maps.places.Autocomplete( $('#sf_lookup')[0], { bounds: circle.getBounds(), types: ['geocode'] } ); } catch (excp) { console.log && console.log('Google Maps Autocomplete unavaible : ', excp); } } });