Jump to content

Edit smarty variable from module hook


Bokobok

Recommended Posts

EDIT :

 

Maybe wa can't change the smarty vars once the tpl is loaded?

and the 'delay' text change occurs juste because its an instance ?

-----------------------------------------------------------------------------------

 

 

Hi,

 

I want to disable a carrier for some users (depending on their address).

 

I tried to develop a module but i'm failing in removing the carrier

 

In my module.php I have :

 
 
    public function hookDisplayBeforeCarrier($params)
    {	    	
    	global $appended_text;
    	$appended_text = "aa";
    	
		$delivery_option_list = $this->context->smarty->getTemplateVars('delivery_option_list');
		foreach($delivery_option_list as $id_address => $carrier_list_raw) {
			foreach($carrier_list_raw as $key => $carrier_list) {
				foreach($carrier_list['carrier_list'] as $id_carrier => $carrier) {
					if($id_carrier != "3") {
						continue;
					}
					$delay = &$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance']->delay;
					$delay = array_map(function ($item) { global $appended_text; return $item.$appended_text;}, $delay);
					unset($delivery_option_list[$id_address][$key]);
				}
			}
		}
		
		$this->context->smarty->assign('delivery_option_list', $delivery_option_list, false);
    }

If i var_dump 'delivery_option_list' in module.php the entry is removed, but if I debug the tpl, it is still here! 

 

I'm new to this, Am I doing something bad?

 

Thanks in advance for your answer.

Edited by Bokobok (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Same issue...

I have a module to check whether a carrier can deliver in a postcode(I have custom tables and functions for this).But I am stuck in select "Shipping" step.

I want to disable a carrier before "Shipping" step,based on..

 

in mymodule.php

//mymodule.php

public function hookDisplayBeforeCarrier($params) {
  $delivery_option_list = $params['delivery_option_list'];
  $carriers = $params['carriers'];
  //updated $delivery_option_list and $carriers here.Removed unavailable carriers in that delivery address.
  // overwrite the list of shipping options
  $this->context->smarty->assign('carriers', $carrires);
  $this->context->smarty->assign('delivery_option_list', $delivery_option_list);
}

But its not reflecting in the front end..Still its showing all the carriers..

I checked order-carrier.tpl.

order-carrier.tpl line no 51

<div class="delivery_options_address">
				{if isset($delivery_option_list)}

{$delivery_option_list|@print_r} 
					{foreach $delivery_option_list as $id_address => $option_list}
						<p class="carrier_title">
							{if isset($address_collection[$id_address])}
								{l s='Choose a shipping option for this address:'} {$address_collection[$id_address]->alias}
							{else}
								{l s='Choose a shipping option'}
							{/if}
						</p>

Please help me to remove a carrier on hookDisplayBeforeCarrier hook

Link to comment
Share on other sites

  • 6 months later...

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...