Hola, estoy programando un módulo que integra un transportista un poco especial.
El caso es que necesito que si se ha seleccionado ese transportista, los métodos de pago "diferidos", es decir, pago con cheque, transferencia, etc.. queden desactivados.
En un principio lo he integrado por con un javascript, pero no consigo que se cargue en el hook de payment.
Alguna idea?
Pego el código por si puede servir de ayuda.
$id_carrier = $this->installExternalCarrier($carrierConfig);
Configuration::updateValue('TENLOAHORA_CARRIER_ID', (int)$id_carrier);
Configuration::updateValue('TENLOAHORA_GATEWAY_URL', 'urlServidor');
if (!parent::install() OR
!$this->runSql($sql) OR
!$this->registerHook('backBeforePayment') OR
!$this->registerHook('extraCarrier') OR
!$this->registerHook('orderConfirmation') OR
!$this->registerHook('payment') OR
!$this->registerHook('updateCarrier'))
return false;
return true;
Aquí cargo el tpl en el que cargo el js:
public function hookPayment($params){
global $smarty;
$ps_module_dir = str_replace($_SERVER['DOCUMENT_ROOT'], "", _PS_MODULE_DIR_);
$smarty->assign(array(
'tenloahora_carrier_id' => Configuration::get('TENLOAHORA_CARRIER_ID'),
'tenloahora_id_address' => $params['cart']->id_address_delivery,
'ps_module_dir' => $ps_module_dir,
));
return $this->display(__FILE__, 'views/frontend/payment.tpl');
Y este es el tpl que se carga:
{assign var="tenloahora_selected" value="{$tenloahora_carrier_id},"}
{assign var="id_delivery_option" value="{Tools::getValue('id_delivery_option')}"}
{if TRUE}
<div class="tenloahora_check_payment">
<p class="payment_module">
<h2>HOLAAAAA</h2>
</p>
{literal}
<script id="tenloahora_check_payment" versionjs="4">
(function () {
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function () {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
if (typeof jqTA === 'undefined') {
loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js", function () {
//jQuery loaded
console.log('jquery loaded');
loadScript("modules/apprenticeshipping/views/frontend/js/tenloahora.js", function () {
//TenloAhora.js loaded from same server
console.log('TenloAhora.js loaded, enjoy :D');
tenloahora.desactivarPagoDiferido();
});
});
}
else
{
try
{
tenloahora.desactivarPagoDiferido();
}
catch(err)
{
console.log('TenloAhora no se inicio :S');
}
}
})();
</script>
{/literal}
</div>
{/if}
Muchas gracias!