640 lines
30 KiB
Smarty
Raw Normal View History

2017-08-30 11:37:48 +02:00
{*
* TNT OFFICIAL MODULE FOR PRESTASHOP
*
* @author GFI Informatique <www.gfi.fr>
* @copyright 2016 GFI Informatique, 2016 TNT
* @license https://opensource.org/licenses/MIT MIT License
*}
2017-09-07 11:10:07 +02:00
2017-08-30 11:37:48 +02:00
<!-- Tnt carriers -->
{foreach $carriers.products as $tnt_index => $product}
{foreach $current_delivery_option as $idAddressSelected => $idCarrierOptionSelected}
{assign var='img_path' value='tntofficiel/views/img/carrier.jpg'}
{assign var='descript' value=""}
{assign var='label' value=$product.label}
{if $product.id|strstr:"ENTERPRISE" }
{assign var='img_path' value='tntofficiel/views/img/carrier/delivery/option-Entreprise.png'}
{* 9:00 Express (ENTERPRISE) *}
{if $product.id == "A_ENTERPRISE"}
{assign var='label' value="09:00 Express en Entreprise"}
{assign var='descript' value="Pour une livraison aux entreprises en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande, avant 9 heures."}
{* Express (ENTERPRISE) *}
{elseif $product.id == "J_ENTERPRISE"}
{assign var='label' value="En entreprise"}
{assign var='descript' value="Pour une livraison aux entreprises ou sur votre lieu de travail en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande (1).<br>
<i>(1) avant 13 heures ou en début d'après-midi en zone rurale.</i>"}
{* 12:00 Express (ENTERPRISE) *}
{elseif $product.id == "M_ENTERPRISE"}
{assign var='label' value="12:00 Express en Entreprise"}
{assign var='descript' value="Pour une livraison aux entreprises en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande, avant midi."}
{* 10:00 Express (ENTERPRISE) *}
{elseif $product.id == "T_ENTERPRISE"}
{assign var='label' value="10:00 Express en Entreprise"}
{assign var='descript' value="Pour une livraison aux entreprises en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande, avant 10 heures."}
{/if}
{elseif $product.id|strstr:"INDIVIDUAL" }
{assign var='img_path' value='tntofficiel/views/img/carrier/delivery/option-ChezVous.png'}
{* 9:00 Express (INDIVIDUAL) *}
{if $product.id == "AZ_INDIVIDUAL"}
{assign var='label' value="09:00 Express à domicile"}
{assign var='descript' value="Pour une livraison à domicile en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande, avant 9 heures."}
{* Express à domicile (INDIVIDUAL) *}
{elseif $product.id == "JZ_INDIVIDUAL"}
{assign var='label' value="À domicile"}
{assign var='descript' value="Pour une livraison à domicile en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande (1).<br>
<i>(1) avant 13 heures ou en début d'après-midi en zone rurale.</i>"}
{* 12:00 Express à domicile (INDIVIDUAL) *}
{elseif $product.id == "MZ_INDIVIDUAL"}
{assign var='label' value="12:00 Express à domicile"}
{assign var='descript' value="Pour une livraison aux entreprises en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande, avant midi."}
{* 10:00 Express à domicile (INDIVIDUAL) *}
{elseif $product.id == "TZ_INDIVIDUAL"}
{assign var='label' value="10:00 Express à domicile"}
{assign var='descript' value="Pour une livraison aux entreprises en France métropolitaine.<br>
Livraison en mains propres et contre signature dès le lendemain de l'expédition de votre commande, avant 10 heures."}
{/if}
{elseif $product.id|strstr:"DROPOFFPOINT" }
{assign var='img_path' value='tntofficiel/views/img/carrier/delivery/option-RelaisColis.png'}
{assign var='label' value="En Relais Colis®"}
{assign var='descript' value="Mise à disposition dans lun des 4200 Relais Colis® de France métropolitaine.<br>
Remise contre signature et présentation dune pièce didentité dès le lendemain de l'expédition de votre commande (1).<br>
<i>(1) avant 13 heures ou en début d'après-midi en zone rurale.</i>"}
{elseif $product.id|strstr:"DEPOT" }
{assign var='img_path' value='tntofficiel/views/img/carrier/delivery/option-Entreprise.png'}
{assign var='label' value="Dépôt restant"}
{assign var='descript' value="Pour une livraisons dans une de nos agences TNT en France métropolitaine.<br>
Mise à votre disposition sur présentation d'une pièce d'identité et contre signature dès 8 heures le lendemain de l'expédition de votre commande et ce pendant 10 Jours."}
{/if}
2017-09-07 11:10:07 +02:00
<div class="delivery_option delivery-option item">
2017-08-30 11:37:48 +02:00
<div>
<table class="resume table table-bordered">
<tr>
2017-09-07 11:10:07 +02:00
<td class="delivery-option-radio">
2017-08-30 11:37:48 +02:00
<input id="delivery_option_{$idAddress|intval}_tnt{$tnt_index|intval}" {* id="delivery_option_{$id_address|intval}_{$option@index}" *}
2017-09-07 11:10:07 +02:00
class="tnt_carrier_radio custom-input" {* class="delivery_option_radio" *}
2017-08-30 11:37:48 +02:00
type="radio"
2017-09-07 11:10:07 +02:00
name="delivery_option[{$idAddress|intval}]" {* name="delivery_option[{$id_address|intval}]" *}
2017-08-30 11:37:48 +02:00
data-key="{$product.id|escape:'htmlall':'UTF-8'}"
data-id_address="{$idAddress|intval}"
value="{$product.id|escape:'htmlall':'UTF-8'}"
{if $deliveryOption === $product.id and $idCarrierOptionSelected === "{$idTntCarrier},"}
checked="checked"
{/if}
product-type="{$product.type|escape:'htmlall':'UTF-8'|lower}"
product-label="{$product.label|escape:'htmlall':'UTF-8'}"
product-code="{$product.id|escape:'htmlall':'UTF-8'}"
/>
</td>
<td class="delivery_option_logo delivery_option_logo_tnt">
<img class="order_carrier_logo"
src="{$smarty.const._MODULE_DIR_|escape:'htmlall':'UTF-8'}{$img_path|escape:'htmlall':'UTF-8'}"
alt="{$product.label|escape:'htmlall':'UTF-8'}"
/>
</td>
<td class="delivery_option_info delivery_option_info_tnt">
<strong>{$label|escape:'htmlall':'UTF-8'}</strong>
<br>{$descript|escape:'htmlall':'UTF-8'|replace:'&lt;':'<'|replace:"&gt;":">"}
{if !empty($product.due_date)}
<br>
Date prévisionnelle de livraison :&nbsp;{$product.due_date|escape:'htmlall':'UTF-8'}
{/if}
{if $deliveryOption === $product.id and $idCarrierOptionSelected === "{$idTntCarrier},"}
{assign var='item_info' value=''}
{if {$product.type|lower} == 'dropoffpoint' and isset($deliveryPoint.xett)}
{assign var='current_method_id' value='relay_point'}
{assign var='current_method_name' value='relay-point'}
{assign var='item_info' value=$deliveryPoint}
{elseif {$product.type|lower} == 'depot' and isset($deliveryPoint.pex)}
{assign var='current_method_id' value='repository'}
{assign var='current_method_name' value='repository'}
{assign var='item_info' value=$deliveryPoint}
{/if}
{if isset($item_info) and $item_info != ''}
{include './displayCarrierList/deliveryPointSet.tpl' item=$item_info method_id=$current_method_id method_name=$current_method_name}
{/if}
{/if}
</td>
<td class="delivery_option_price">
2017-09-07 11:10:07 +02:00
<div class="delivery_option_price ">
2017-08-30 11:37:48 +02:00
{if $product.total_price_with_tax && !$product.is_free && (!isset($free_shipping) || (isset($free_shipping) && !$free_shipping))}
{if $use_taxes == 1}
{if $priceDisplay == 1}
{convertPrice price=$product.total_price_without_tax}{if $display_tax_label} HT{/if}
{else}
{convertPrice price=$product.total_price_with_tax}{if $display_tax_label} TTC{/if}
{/if}
{else}
{convertPrice price=$product.total_price_without_tax}
{/if}
{else}
gratuit
{/if}
</div>
</td>
</tr>
</table>
</div>
</div>
{/foreach}
{/foreach}
{if $cityPostcodeIsValid == false}
<a id="fancybox_city_postcode" href="#city_postcode_error" hidden="hidden"></a>
<div style="display: none;">
<div id="city_postcode_error">
<h1 class="page-subheading">{l s='Can not purchase the order' mod='tntofficiel'}</h1>
{*COMMANDE IMPOSSIBLE*}
<div class="alert-danger">
<p>{l s='Entering city in the address is unknown for the postal code %s' sprintf=$postcode mod='tntofficiel'}</p>
</div>
</div>
</div>
{/if}
<!-- spinner to be shown during ajax request -->
<div id="loading" style="display: none">
<img id="loading-image" src="{$smarty.const._MODULE_DIR_|escape:'htmlall':'UTF-8'}tntofficiel/views/img/ajax-loader.gif" alt="Loading..."/>
</div>
<a id="fancybox_extra_address_data" href="#extra_address_data" hidden="hidden"></a>
<div style="display:none">
<div id="extra_address_data">
<h1 class="page-subheading">{l s='TNT Additional Address' mod='tntofficiel'}</h1>
<div class="alert-danger extra_address_data_error">
<p class="extra_address_data_error_message"></p>
</div>
<div class="form-group">
<label for="email">{l s='Email' mod='tntofficiel'}<span class="required"></span></label>
<input class="form-control extraAddressData" type="text" id="email" name="email"
value="{$extraAddressDataValues.email|escape:'htmlall':'UTF-8'}">
</div>
<div class="form-group">
<label for="mobile_phone">{l s='Cellphone' mod='tntofficiel'}<span class="required"></span></label>
{*Téléphone portable*}
<input class="form-control extraAddressData" type="tel" id="mobile_phone" name="mobile_phone"
value="{$extraAddressDataValues.mobile_phone|escape:'htmlall':'UTF-8'}">
</div>
<div class="form-group individual-data">
<label for="building_number">{l s='Building Number' mod='tntofficiel'}</label>
{*Numéro du bâtiment*}
<input class="form-control extraAddressData" type="text" id="building_number"
name="building_number" value="{$extraAddressDataValues.building_number|escape:'htmlall':'UTF-8'}" maxlength="3">
</div>
<div class="form-group individual-data">
<label for="intercom_code">{l s='Intercom Code' mod='tntofficiel'}</label>
{*Code interphone*}
<input class="form-control extraAddressData" type="text" id="intercom_code" name="intercom_code"
value="{$extraAddressDataValues.intercom_code|escape:'htmlall':'UTF-8'}" maxlength="7">
</div>
<div class="form-group individual-data">
<label for="floor">{l s='Floor' mod='tntofficiel'}</label>
{*Etage*}
<input class="form-control extraAddressData" type="floor" id="text" name="floor"
value="{$extraAddressDataValues.floor|escape:'htmlall':'UTF-8'}" maxlength="2">
</div>
<p class="submit2">
<button type="submit" name="submitAddressExtraData" id="submitAddressExtraData"
class="btn btn-default button button-medium">
<span>
Enregistrer
<i class="icon-chevron-right right"></i>
</span>
</button>
</p>
<p class="required"><span class="required"></span>{l s='Required fields' mod='tntofficiel'}</p>
</div>
</div>
<script type="text/javascript">
{literal}
var extraAddressData = {};
var carrierInfo = {};
var $elmtPaymentLink = "";
var deliveryOptionTnt = [];
var isUniformBindFuncEnabled = $.type(window.bindUniform) === 'function';
// Enable Uniform update if bindUniform() does not exist and Uniform usable.
var isUniformUpdateEnabled = !isUniformBindFuncEnabled && !!($.type($.prototype.uniform) == 'function' && $.uniform && $.type($.uniform.update) == 'function');
{/literal}
$('input[name^=delivery_option_tnt]:checked').each(function () {
deliveryOptionTnt.push($(this).val());
});
$(document).ready(function () {
{if $cityPostcodeIsValid == false}
{literal}
$("a#fancybox_city_postcode").fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'type': 'inline',
'speedIn': 600,
'speedOut': 200,
'overlayShow': false,
'autoDimensions': true,
helpers: {
overlay: {closeClick: false}
}
});
{/literal}
$("a#fancybox_city_postcode").trigger("click");
{/if}
// Uncheck core TNT Radio.
RadioElementCheck(strjQSelectorInputRadioCoreTNT, false);
// If core TNT selected, disable the order button.
//if ($(strjQSelectorInputRadioCoreTNT).is(':checked')) {
// Add 'disabled' class from next step button.
// $("button[name=processCarrier]").addClass('disabled');
//}
// Hide the form error div.
$(".extra_address_data_error").hide();
// Fancybox configuration.
{literal}
$("a#fancybox_extra_address_data").fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'type': 'inline',
'speedIn': 600,
'speedOut': 200,
'overlayShow': false,
'autoSize': false,
'width': 480,
'autoHeight': true,
helpers: {
overlay: {closeClick: false}
}
});
{/literal}
// 5 Step process.
if (!window.TNTOfficiel.order.isOPC)
{
// If theme has bindUniform, then use it.
if(isUniformBindFuncEnabled) {
bindUniform();
}
// else if enabled, update input with uniform.
else if (isUniformUpdateEnabled) {
//$("select.form-control,input[type='radio'],input[type='checkbox']").not(".not_uniform").uniform();
$(strjQSelectorInputRadioVirtTNT).not(".not_uniform").uniform();
}
}
// Click on a real carrier (incl. TNT hidden one).
$(strjQSelectorInputRadioCoreAll).off().on('click', function () {
// If clicked input radio is not the TNT hidden one.
if ($(this).attr('data-key') != window.TNTOfficiel.carrier.id + ',') {
// Remove 'disabled' class from next step button.
//$('button[name=processCarrier]').removeClass('disabled');
// Unchek TNT.
RadioElementCheck(strjQSelectorInputRadioVirtTNT, false);
RadioElementCheck(strjQSelectorInputRadioCoreTNT, false);
}
});
// Click on a virtual TNT carrier.
$(strjQSelectorInputRadioVirtTNT).off().on('click', function () {
var $elmtInputRadioVirtTNT = $(this);
// Display pop-in for repositories list if needed.
XHRBoxDeliveryPoints($elmtInputRadioVirtTNT);
// Check hidden core TNT input radio.
RadioElementCheck(strjQSelectorInputRadioCoreTNT, true);
// Show clicked TNT input radio as checked, even if not saved. It will be saved on final AJAX request '/commande'.
// TNT mode with repo (Relais Colis ou Dépot Restant) clear previous saved TNT selection, on pop-in display, until repo choice is saved.
RadioElementCheck($elmtInputRadioVirtTNT, true);
if (isUniformUpdateEnabled) {
// TODO: remove ?
$.uniform.update($elmtInputRadioVirtTNT);
}
var onComplete = function () {
$('#loading').show();
var objJqXHR = $.ajax({
"url": window.TNTOfficiel.link.front.module.saveProductCode,
"data": {
productCode: $elmtInputRadioVirtTNT.attr('product-code')
},
"global": false
});
objJqXHR
.done(function (mxdData, strTextStatus, objJqXHR) {
// Uncheck radio required to trigger the click event.
RadioElementCheck(strjQSelectorInputRadioCoreTNT, false);
// Click hidden core TNT input radio to trigger standard Prestashop AJAX request.
// /commande?ajax=true&method=updateExtraCarrier&id_address=<ADDRESS>&id_delivery_option=<CARRIER>,&allow_refresh=1
// Also trigger global callback who hide #loading element.
$(strjQSelectorInputRadioCoreTNT).trigger('click');
// Set form action attribute for TNT (can be modified by others carriers).
$("#form").attr("action", window.TNTOfficiel.link.front.page.order);
// Check radio.
RadioElementCheck(strjQSelectorInputRadioCoreTNT, true);
//$('#loading').hide();
})
.fail(function (objJqXHR, strTextStatus, strErrorThrown) {
// console.error( objJqXHR.status + ' ' + objJqXHR.statusText );
alert('Une erreur de communication avec le serveur est survenue, le transporteur TNT est momentanément indisponible.');
location.reload();
})
.always(function () {
{*if ($('#opc_payment_methods a').length() > 0) {
$('#loading').hide();
}*}
});
};
switch ($elmtInputRadioVirtTNT.attr('product-type')) {
case 'depot':
case 'dropoffpoint':
$(document).unbind('hook_extra_carrier_shipping_method_popup:close');
$(document).on('hook_extra_carrier_shipping_method_popup:close', onComplete);
break;
default:
onComplete();
break;
}
});
// Perform an AJAX request when the extra address data form is submitted.
// Submit the address extra data form in AJAX.
$('#submitAddressExtraData').off().on('click', function () {
var stop = false;
{literal}
var regex = /^((06|07){1}(\d){8})$/;
{/literal}
$(".extra_address_data_error").hide();
// Get all the extra address data field values
$(".extraAddressData").each(function () {
if ($(this).attr("name") === "mobile_phone") {
// TODO: too restrictive check.
//$(this).val($(this).val().replace(/\s/gi,''));
//if (!regex.test($(this).val().replace(/\s/gi,''))) {
if (!regex.test($(this).val())) {
$(".extra_address_data_error_message").html("{l s='The phone number must be 10 digits' mod='tntofficiel'}");
$(".extra_address_data_error").show();
stop = true;
return false;
}
}
extraAddressData[$(this).attr("name")] = $(this).val();
});
if (stop) {
return;
}
$('#loading').show();
var objJqXHR = $.ajax({
"url": window.TNTOfficiel.link.front.module.storeDeliveryInfo,
"method": 'POST',
"data": extraAddressData,
"global": false
});
objJqXHR
.done(function (mxdData, strTextStatus, objJqXHR) {
handleSuccess(mxdData, function () {
if (window.TNTOfficiel.order.isOPC) {
/* TODO : stronger than $elmtPaymentLink system */
window.location = window.$elmtPaymentLink.attr('href');
} else {
var form = $('#form');
if (form.length) {
form.off();
form.data('valid', true);
form.submit();
}
}
});
})
.fail(function (objJqXHR, strTextStatus, strErrorThrown) {
// console.error( objJqXHR.status + ' ' + objJqXHR.statusText );
handleError(objJqXHR);
})
.always(function () {
$('#loading').hide();
});
});
});
function RadioElementCheck(mxdElmt, boolChecked) {
$(mxdElmt).prop('checked', !!boolChecked);
// If theme has bindUniform, then use it.
if(isUniformBindFuncEnabled) {
bindUniform();
}
// else if enabled, update input with uniform.
else if (isUniformUpdateEnabled) {
$.uniform.update();
}
}
/**
* Check the json response from the ajax request
* @param json
* @param onSuccess
*/
function handleSuccess(json, onSuccess) {
var result = jQuery.parseJSON(json);
//if there was an error
if (!result.result) {
//$('button[name=processCarrier]').addClass('disabled');
var errorsHtml = '';
$.each(result.form_errors, function (i, error) {
errorsHtml += error + '<br />';
});
$(".extra_address_data_error_message").html(errorsHtml);
$(".extra_address_data_error").show();
} else {
$.fancybox.close();
//$('button[name=processCarrier]').removeClass('disabled');
onSuccess();
}
}
/**
* Handle a failure of the ajax request
* @param json
*/
function handleError(json) {
$(".extra_address_data_error_message").html("{l s='An error has occured' mod='tntofficiel'}");
$(".extra_address_data_error").show();
}
/**
* Update info when a tnt carrier is selected
* @param input
*/
function XHRStoreProductPrice(input) {
carrierInfo['productCode'] = input.attr('product-code');
carrierInfo['productLabel'] = input.attr('product-label');
$('#loading').show();
var objJqXHR = $.ajax({
"url": window.TNTOfficiel.link.front.module.storeProductPrice,
"method": 'POST',
"data": carrierInfo,
"global": false
});
objJqXHR
.done(function (mxdData, strTextStatus, objJqXHR) {
})
.fail(function (objJqXHR, strTextStatus, strErrorThrown) {
// console.error( objJqXHR.status + ' ' + objJqXHR.statusText );
alert('Une erreur de communication avec le serveur est survenue, le transporteur TNT est momentanément indisponible.');
location.reload();
})
.always(function () {
$('#loading').hide();
});
}
/**
* Display the popup with the extra address data form
* @param productType
*/
function displayExtraAddressDataPopup(productType) {
// Hide the form error div
$(".extra_address_data_error").hide();
if (productType == 'dropoffpoint' || productType == 'depot' || productType == 'enterprise') {
$(".individual-data").hide();
} else {
$(".individual-data").show();
}
$("a#fancybox_extra_address_data").trigger("click");
}
/**
* Return the current shipping
*
* @returns null
* @private
*/
function _getCurrentShippingMethod() {
var $elmtRadioChecked = $(strjQSelectorInputRadioVirtTNT).filter(':checked');
if ($elmtRadioChecked.length) {
return $elmtRadioChecked.attr('product-type');
}
return null;
}
function XHRBoxDeliveryPoints(element) {
var url = null;
switch (_getCurrentShippingMethod()) {
case 'dropoffpoint':
url = window.TNTOfficiel.link.front.module.boxRelayPoints;
break;
case 'depot':
url = window.TNTOfficiel.link.front.module.boxDropOffPoints;
break;
}
if (url) {
var hasInfo = $(strjQSelectorInputRadioVirtTNT).filter(':checked').closest('table').find('.shipping-method-info').length;
if (!hasInfo) {
$(strjQSelectorInputRadioVirtTNT).closest('table').find('.shipping-method-info').remove();
}
$('#loading').show();
var objJqXHR = $.ajax({
"url": url,
"method": 'POST',
"dataType": 'html',
"global": false
});
objJqXHR
.done(function (mxdData, strTextStatus, objJqXHR) {
if (mxdData) {
if (!!$.prototype.fancybox) {
$.fancybox.open([
{
"type": 'inline',
"autoScale": true,
"autoDimensions": true,
"centerOnScroll": true,
"maxWidth": 1280,
"maxHeight": 768,
"fitToView": false,
"width": '100%',
"height": '100%',
"autoSize": false,
"closeClick": false,
"openEffect": 'none',
//"closeEffect": 'none',
"content": mxdData,
"afterShow": function () {
if (window.TNTShippingMethod) {
window.TNTShippingMethod.prepareScrollbar();
window.TNTShippingMethod.eventGoogleMaps();
}
},
"helpers": {
"overlay": {
"locked" : true,
"closeClick": false
} // prevents closing when clicking OUTSIDE fancybox
}
}
], {
"padding": 10
});
}
}
})
.fail(function (objJqXHR, strTextStatus, strErrorThrown) {
// console.error( objJqXHR.status + ' ' + objJqXHR.statusText );
alert('Une erreur de communication avec le serveur est survenue, le transporteur TNT est momentanément indisponible.');
location.reload();
})
.always(function () {
$('#loading').hide();
});
}
}
</script>