Jump to content

Preventing some payment methods when certain carrier is selected


mikimoto

Recommended Posts

Hi!

 

I'm programming a module that add's an special kind of carrier.

 

I need to prevent selecting "defered" payment methods such as "cash on delivery" "transference", etc, when this carrier is selected.

 

I have implemented the solution via javascript, but i'm beeing unable to load the tpl file in the payment hook.

 

Does anybody have any idea?

 

Here is where the module registers the hooks:

$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;

Here where the tpl is loaded:

	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'); 

And this is the tpl that is loaded:

{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} 

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...